Menu

#279 lircd not picking up devices after first client connect

0.10
closed
nobody
None
fixed
2017-04-05
2017-04-03
No

I noticed that lircd (0.9.4d and trunk) isn't properly picking up devices that appear after the first client (lircd-uinput, irw, ...) connected. This can happen if systemd starts lircd/lircd-uinput before the device is available on the system (eg USB DVB receivers with integrated IR receiver).

With the default driver the behaviour is a bit odd, after all clients have disconnected and another client connects lircd will retry driver init in 1 second intervals. With the pinsys driver init is never retried.

Reproducing/simulating this is rather easy, just start lircd with a non-existant device. eg:

./sbin/lircd -n -D10 --driver=default --device=/does/not/exist -o /tmp/lircd.socket ../my.lircd.conf

Debugging revealed that the culprit seems to be driver.fd being initialized to 0. Most of the lirc code checks for drv.fd != -1, also the reconnect code in lircd.cpp responsible for setting the poll timeout to 1 second or -1.

With the default driver there's another (unwanted) side effect, default_deinit then closes stdin. After that it sets drv.fd to -1, thus reconnect works once the driver (which was never fully inited) got deinited.

As a quick workaround I initialized drv.fd to -1 in hw_coose_driver, this resulted in reconnect working properly with the default and pinsys drivers (haven't tested with other drivers):

--- a/lib/drv_admin.c
+++ b/lib/drv_admin.c
@@ -300,6 +300,7 @@ int hw_choose_driver(const char* name)

        if (name == NULL) {
                memcpy(&drv, &drv_null, sizeof(struct driver));
+               drv.fd = -1;
                return 0;
        }
        if (strcasecmp(name, "dev/input") == 0)
@@ -308,6 +309,7 @@ int hw_choose_driver(const char* name)
        found = for_each_driver(match_hw_name, (void*)name, NULL);
        if (found != (struct driver*)NULL) {
                memcpy(&drv, found, sizeof(struct driver));
+               drv.fd = -1;
                return 0;
        }
        return -1;

I'm not sure though if this is the correct fix, maybe initial .fd value should be controlled by the drivers or maybe that should be handled by applications like lircd.

Related

Tickets: #266
Tickets: #291

Discussion

  • Alec Leamas

    Alec Leamas - 2017-04-05
    • status: open --> closed
    • Resolution: na --> fixed
    • Milestone: Future --> 0.10
     
  • Alec Leamas

    Alec Leamas - 2017-04-05

    I cannot see anything else then that thsi is a plain bug. Also, the fix looks perfectly sane.

    Thanks for reporting, debugging + patch! Fixed in [0ba10e]

    EDIT: There have been multiple issues concerning the inital connect - see also [#274].

     

    Related

    Tickets: #274
    Commit: [0ba10e]


    Last edit: Alec Leamas 2017-04-05

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.