chiark / gitweb /
move syslog wrapper to libudev
[elogind.git] / udev / udev-event.c
index d52125193ce0f4a956f6bc5244c526a1d4bf774e..2f32805f30d9b57885a12e847d778248adf72fa4 100644 (file)
@@ -180,6 +180,8 @@ subst:
                        attrbuf[i] = '\0';
                        from += i+1;
                        attr = attrbuf;
+               } else {
+                       attr = NULL;
                }
 
                switch (type) {
@@ -276,8 +278,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 +288,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: {
@@ -734,18 +732,13 @@ int udev_event_execute_run(struct udev_event *event)
                        monitor = udev_monitor_new_from_socket(event->udev, &cmd[strlen("socket:")]);
                        if (monitor == NULL)
                                continue;
-                       udev_monitor_send_device(monitor, event->dev);
+                       udev_monitor_send_device(monitor, NULL, event->dev);
                        udev_monitor_unref(monitor);
                } else {
                        char program[UTIL_PATH_SIZE];
                        char **envp;
 
                        udev_event_apply_format(event, cmd, program, sizeof(program));
-                       if (event->trace)
-                               fprintf(stderr, "run  %s (%llu) '%s'\n",
-                                      udev_device_get_syspath(event->dev),
-                                      udev_device_get_seqnum(event->dev),
-                                      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))