chiark / gitweb /
Fix Dell Studio 1558 volume keys not releasing
[elogind.git] / udev / udev-event.c
index 3f69c0bb7a86c35ed8b3d1eb737e2d4a37d355fd..986c119fbbccaceef117d0ec62064d5cf3fe54be 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2009 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2003-2009 Kay Sievers <kay.sievers@vrfy.org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
+#include <time.h>
+#include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <net/if.h>
 #include <linux/sockios.h>
 
 #include "udev.h"
@@ -126,7 +127,7 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char *
                                }
 
                                for (i = 0; i < ARRAY_SIZE(map); i++) {
-                                       if (strncasecmp(&from[1], map[i].name, strlen(map[i].name)) == 0) {
+                                       if (strncmp(&from[1], map[i].name, strlen(map[i].name)) == 0) {
                                                type = map[i].type;
                                                from += strlen(map[i].name)+1;
                                                dbg(event->udev, "will substitute format name '%s'\n", map[i].name);
@@ -180,6 +181,8 @@ subst:
                        attrbuf[i] = '\0';
                        from += i+1;
                        attr = attrbuf;
+               } else {
+                       attr = NULL;
                }
 
                switch (type) {
@@ -276,8 +279,8 @@ subst:
                        break;
                }
                case SUBST_ATTR: {
-                       const char *val;
-                       char value[UTIL_NAME_SIZE];
+                       const char *value = NULL;
+                       char vbuf[UTIL_NAME_SIZE];
                        size_t len;
                        int count;
 
@@ -286,36 +289,32 @@ subst:
                                break;
                        }
 
-                       value[0] = '\0';
-                       /* read the value specified by "[dmi/id]product_name" */
-                       util_resolve_subsys_kernel(event->udev, attr, value, sizeof(value), 1);
+                       /* try to read the value specified by "[dmi/id]product_name" */
+                       if (util_resolve_subsys_kernel(event->udev, attr, vbuf, sizeof(vbuf), 1) == 0)
+                               value = vbuf;
 
-                       /* try to read attribute of the current device */
-                       if (value[0] == '\0') {
-                               val = udev_device_get_sysattr_value(event->dev, attr);
-                               if (val != NULL)
-                                       util_strscpy(value, sizeof(value), val);
-                       }
+                       /* try to read the attribute the device */
+                       if (value == NULL)
+                               value = udev_device_get_sysattr_value(event->dev, attr);
 
                        /* try to read the attribute of the parent device, other matches have selected */
-                       if (value[0] == '\0' && event->dev_parent != NULL && event->dev_parent != event->dev) {
-                               val = udev_device_get_sysattr_value(event->dev_parent, attr);
-                               if (val != NULL)
-                                       util_strscpy(value, sizeof(value), val);
-                       }
+                       if (value == NULL && event->dev_parent != NULL && event->dev_parent != event->dev)
+                               value = udev_device_get_sysattr_value(event->dev_parent, attr);
 
-                       if (value[0]=='\0')
+                       if (value == NULL)
                                break;
 
                        /* strip trailing whitespace, and replace unwanted characters */
-                       len = strlen(value);
-                       while (len > 0 && isspace(value[--len]))
-                               value[len] = '\0';
-                       count = udev_util_replace_chars(value, UDEV_ALLOWED_CHARS_INPUT);
+                       if (value != vbuf)
+                               util_strscpy(vbuf, sizeof(vbuf), value);
+                       len = strlen(vbuf);
+                       while (len > 0 && isspace(vbuf[--len]))
+                               vbuf[len] = '\0';
+                       count = udev_util_replace_chars(vbuf, UDEV_ALLOWED_CHARS_INPUT);
                        if (count > 0)
                                info(event->udev, "%i character(s) replaced\n" , count);
-                       l = util_strpcpy(&s, l, value);
-                       dbg(event->udev, "substitute sysfs value '%s'\n", value);
+                       l = util_strpcpy(&s, l, vbuf);
+                       dbg(event->udev, "substitute sysfs value '%s'\n", vbuf);
                        break;
                }
                case SUBST_PARENT: {
@@ -493,8 +492,7 @@ static int rename_netif(struct udev_event *event)
                }
 
                /* free our own name, another process may wait for us */
-               util_strscpy(ifr.ifr_newname, IFNAMSIZ, udev_device_get_sysname(dev));
-               util_strscpy(ifr.ifr_newname, IFNAMSIZ, "_rename");
+               util_strscpyl(ifr.ifr_newname, IFNAMSIZ, udev_device_get_sysname(dev), "_rename", NULL);
                err = ioctl(sk, SIOCSIFNAME, &ifr);
                if (err != 0) {
                        err(event->udev, "error changing netif name %s to %s: %m\n",
@@ -507,6 +505,8 @@ static int rename_netif(struct udev_event *event)
                util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name);
                loop = 90 * 20;
                while (loop--) {
+                       const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 };
+
                        err = ioctl(sk, SIOCSIFNAME, &ifr);
                        if (err == 0) {
                                rename_netif_kernel_log(ifr);
@@ -520,7 +520,7 @@ static int rename_netif(struct udev_event *event)
                        }
                        dbg(event->udev, "wait for netif '%s' to become free, loop=%i\n",
                            event->name, (90 * 20) - loop);
-                       usleep(1000 * 1000 / 20);
+                       nanosleep(&duration, NULL);
                }
        }
 exit:
@@ -533,10 +533,12 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
        struct udev_device *dev = event->dev;
        int err = 0;
 
-       if (udev_device_get_devpath_old(dev) != NULL) {
-               if (udev_device_rename_db(dev, udev_device_get_devpath(dev)) == 0)
-                       info(event->udev, "moved database from '%s' to '%s'\n",
-                            udev_device_get_devpath_old(dev), udev_device_get_devpath(dev));
+       if (udev_device_get_sysname_old(dev) != NULL &&
+           strcmp(udev_device_get_sysname_old(dev), udev_device_get_sysname(dev)) != 0) {
+               udev_device_rename_db(dev);
+               info(event->udev, "moved database from '%s:%s' to '%s:%s'\n",
+                    udev_device_get_subsystem(dev), udev_device_get_sysname_old(dev),
+                    udev_device_get_subsystem(dev), udev_device_get_sysname(dev));
        }
 
        /* add device node */
@@ -566,14 +568,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
                        event->tmp_node = NULL;
                }
 
-               if (event->ignore_device) {
-                       info(event->udev, "device event will be ignored\n");
-                       delete_kdevnode = 1;
-                       goto exit_add;
-               }
-
                if (event->name != NULL && event->name[0] == '\0') {
-                       info(event->udev, "device node creation supressed\n");
+                       info(event->udev, "device node creation suppressed\n");
                        delete_kdevnode = 1;
                        goto exit_add;
                }
@@ -636,10 +632,6 @@ exit_add:
                udev_device_delete_db(dev);
 
                udev_rules_apply_to_event(rules, event);
-               if (event->ignore_device) {
-                       info(event->udev, "device event will be ignored\n");
-                       goto exit;
-               }
                if (event->name == NULL)
                        goto exit;
 
@@ -685,17 +677,13 @@ exit_add:
                        char devnode[UTIL_PATH_SIZE];
 
                        info(event->udev, "'%s' not found in database, using kernel name '%s'\n",
-                            udev_device_get_syspath(dev), udev_device_get_sysname(dev));
+                            udev_device_get_syspath(dev), udev_device_get_knodename(dev));
                        util_strscpyl(devnode, sizeof(devnode),
-                                     udev_get_dev_path(event->udev), "/", udev_device_get_sysname(dev), NULL);
+                                     udev_get_dev_path(event->udev), "/", udev_device_get_knodename(dev), NULL);
                        udev_device_set_devnode(dev, devnode);
                }
 
                udev_rules_apply_to_event(rules, event);
-               if (event->ignore_device) {
-                       info(event->udev, "device event will be ignored\n");
-                       goto exit;
-               }
 
                if (udev_device_get_ignore_remove(dev)) {
                        info(event->udev, "ignore_remove for '%s'\n", udev_device_get_devnode(dev));
@@ -708,8 +696,6 @@ exit_add:
 
        /* default devices */
        udev_rules_apply_to_event(rules, event);
-       if (event->ignore_device)
-               info(event->udev, "device event will be ignored\n");
 
        if (strcmp(udev_device_get_action(dev), "remove") != 0)
                udev_device_update_db(dev);
@@ -719,7 +705,7 @@ exit:
        return err;
 }
 
-int udev_event_execute_run(struct udev_event *event)
+int udev_event_execute_run(struct udev_event *event, const sigset_t *sigmask)
 {
        struct udev_list_entry *list_entry;
        int err = 0;
@@ -742,8 +728,8 @@ int udev_event_execute_run(struct udev_event *event)
 
                        udev_event_apply_format(event, cmd, program, sizeof(program));
                        envp = udev_device_get_properties_envp(event->dev);
-                       if (util_run_program(event->udev, program, envp, NULL, 0, NULL) != 0) {
-                               if (!udev_list_entry_get_flag(list_entry))
+                       if (util_run_program(event->udev, program, envp, NULL, 0, NULL, sigmask) != 0) {
+                               if (udev_list_entry_get_flags(list_entry))
                                        err = -1;
                        }
                }