Menu

#41 Lircd should not use its default device (/dev/lirc0) in the driver has a default.

1.0
closed
nobody
lircd (8)
fixed,
2014-11-18
2014-08-31
No

Master branch

Presently, if the command line argument --device is empty, Lircd uses the default device /dev/lirc0, also if a sensible default is given in the driver. Possible fix

Related

Tickets: #90

Discussion

  • Bengt Martensson

    [ooops, pressed Save to fast...]
    Possible fix to lircd.c

    diff --git a/daemons/lircd.c b/daemons/lircd.c
    index 5e9f803..a55eca5 100644
    --- a/daemons/lircd.c
    +++ b/daemons/lircd.c
    @@ -2109,7 +2109,7 @@ static void lircd_add_defaults(void)
                    "lircd:nodaemon",       "False",
                    "lircd:permission",     DEFAULT_PERMISSIONS,
                    "lircd:driver",         "default",
    -               "lircd:device",         LIRC_DRIVER_DEVICE,
    +               "lircd:device",         NULL,
                    "lircd:listen",         NULL ,
                    "lircd:connect",        NULL,
                    "lircd:lircdfile",      LIRCD,
    @@ -2295,6 +2295,8 @@ int main(int argc, char **argv)
            if (device != NULL) {
                    drv.device = device;
            }
    +        if (!drv.device)
    +                drv.device = LIRC_DRIVER_DEVICE;
            if (strcmp(drv.name, "null") == 0 && peern == 0) {
                    fprintf(stderr, "%s: there's no hardware I can use and no peers are specified\n", progname);
                return (EXIT_FAILURE);
    
     
  • Alec Leamas

    Alec Leamas - 2014-09-01

    Basically agreed. But while we're on it: shouldn't the driver code have a chance to compute/autodetect a default device? I think so.

     
  • Bengt Martensson

    I definitely agree that the driver should be able/allowed to dynamically select the device name. For example, FTDI based devices get device names of the type /dev/ttyUSBn where n = 0,1,2,3,... (the lowest possible); Arduino (most types except Nano) and IrToy use /dev/ACMn with n as before.

    My proposition in the ticket is that if --device is not given, Lircd should not force its "/dev/lirc0" to a driver, unless its device is NULL. Thinking about it, also the "unless"-clause is unnecessary: A driver that wants /dev/lirc0 as default can state so itself in its code. This would mean skipping the second part of the path.

     
  • Alec Leamas

    Alec Leamas - 2014-09-01

    Hm... wher did my patch disappear? My idea is to implement it like this. Basically, this means that

    • --device wins if given
    • if not, a configured device wins, but nothing is configured by default.
    • else, the code in open handles it. default_open will fall back to
      /dev/lirc0
    • A slight change in open_func()'s semantics.

    The patch:

    diff --git a/daemons/lircd.c b/daemons/lircd.c
    index 4101257..dda4907 100644
    --- a/daemons/lircd.c
    +++ b/daemons/lircd.c
    @@ -2113,7 +2113,6 @@ static void lircd_add_defaults(void)
            "lircd:nodaemon",   "False",
            "lircd:permission",     DEFAULT_PERMISSIONS,
            "lircd:driver",     "default",
    -       "lircd:device",     LIRC_DRIVER_DEVICE,
            "lircd:listen",     NULL ,
            "lircd:connect",    NULL,
            "lircd:lircdfile",  LIRCD,
    diff --git a/lib/driver.c b/lib/driver.c
    index acd9504..ed56139 100644
    --- a/lib/driver.c
    +++ b/lib/driver.c
    @@ -21,7 +21,10 @@ const struct driver const* curr_driver = &drv;
     int default_open(const char* path)
     {
        static char buff[128];
    -   strncpy(buff, path, sizeof(buff));
    +   if (path == NULL)
    +       strcpy(buff, LIRC_DRIVER_DEVICE);
    +   else
    +       strncpy(buff, path, sizeof(buff));
        drv.device = buff;
        return 0;
     }
    diff --git a/lib/driver.h b/lib/driver.h
    index ce26e5d..401ede2 100644
    --- a/lib/driver.h
    +++ b/lib/driver.h
    @@ -65,6 +65,7 @@ struct driver {
              *  Function called to do basic driver setup.
              *  @param device String describing what device driver should
              *      communicate with. Often (but not always) a /dev/... path.
    +         *      If NULL, use driver's default device.
              *  @return 0 if everything is fine, else positive error code.
              */
        int (*const open_func) (const char* device);
    diff --git a/lirc_options.conf b/lirc_options.conf
    index 9dc672a..c709ac2 100644
    --- a/lirc_options.conf
    +++ b/lirc_options.conf
    @@ -5,7 +5,7 @@
     [lircd]
     nodaemon        = False
     driver          = default
    -device          = /dev/lirc0
    +#device          = /dev/lirc0
     output          = /var/run/lirc/lircd
     pidfile         = /var/run/lirc/lircd.pid
     plugindir       = /usr/lib/lirc/plugins
    
     
  • Alec Leamas

    Alec Leamas - 2014-09-03

    I have added your initial patch (more or less) in [252a83] to master. There are some drawbacks with this approach, but to solve it properly we need to update the API. Which we will do, changes are pending in the api branch, but not now.

    Closing, short term fix in master, long term in api branch

     

    Related

    Commit: [252a83]

  • Alec Leamas

    Alec Leamas - 2014-09-03
    • status: open --> closed
     
  • Alec Leamas

    Alec Leamas - 2014-11-18
    • Resolution: --> fixed,
     

Log in to post a comment.

MongoDB Logo MongoDB