chiark / gitweb /
udev: use startswith() and streq()
[elogind.git] / src / udev / udevadm-trigger.c
index 3cce23d..7735e4b 100644 (file)
@@ -38,7 +38,6 @@ static int dry_run;
 
 static void exec_list(struct udev_enumerate *udev_enumerate, const char *action)
 {
 
 static void exec_list(struct udev_enumerate *udev_enumerate, const char *action)
 {
-        struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
         struct udev_list_entry *entry;
 
         udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(udev_enumerate)) {
         struct udev_list_entry *entry;
 
         udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(udev_enumerate)) {
@@ -51,12 +50,10 @@ static void exec_list(struct udev_enumerate *udev_enumerate, const char *action)
                         continue;
                 util_strscpyl(filename, sizeof(filename), udev_list_entry_get_name(entry), "/uevent", NULL);
                 fd = open(filename, O_WRONLY);
                         continue;
                 util_strscpyl(filename, sizeof(filename), udev_list_entry_get_name(entry), "/uevent", NULL);
                 fd = open(filename, O_WRONLY);
-                if (fd < 0) {
-                        dbg(udev, "error on opening %s: %m\n", filename);
+                if (fd < 0)
                         continue;
                         continue;
-                }
                 if (write(fd, action, strlen(action)) < 0)
                 if (write(fd, action, strlen(action)) < 0)
-                        info(udev, "error writing '%s' to '%s': %m\n", action, filename);
+                        log_debug("error writing '%s' to '%s': %m\n", action, filename);
                 close(fd);
         }
 }
                 close(fd);
         }
 }
@@ -101,7 +98,6 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
         struct udev_enumerate *udev_enumerate;
         int rc = 0;
 
         struct udev_enumerate *udev_enumerate;
         int rc = 0;
 
-        dbg(udev, "version %s\n", VERSION);
         udev_enumerate = udev_enumerate_new(udev);
         if (udev_enumerate == NULL) {
                 rc = 1;
         udev_enumerate = udev_enumerate_new(udev);
         if (udev_enumerate == NULL) {
                 rc = 1;
@@ -131,7 +127,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
                         } else if (strcmp(optarg, "subsystems") == 0) {
                                 device_type = TYPE_SUBSYSTEMS;
                         } else {
                         } else if (strcmp(optarg, "subsystems") == 0) {
                                 device_type = TYPE_SUBSYSTEMS;
                         } else {
-                                err(udev, "unknown type --type=%s\n", optarg);
+                                log_error("unknown type --type=%s\n", optarg);
                                 rc = 2;
                                 goto exit;
                         }
                                 rc = 2;
                                 goto exit;
                         }
@@ -168,14 +164,14 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
                         struct udev_device *dev;
 
                         /* add sys dir if needed */
                         struct udev_device *dev;
 
                         /* add sys dir if needed */
-                        if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0)
-                                util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), optarg, NULL);
+                        if (!startswith(optarg, "/sys"))
+                                util_strscpyl(path, sizeof(path), "/sys", optarg, NULL);
                         else
                                 util_strscpy(path, sizeof(path), optarg);
                         util_remove_trailing_chars(path, '/');
                         dev = udev_device_new_from_syspath(udev, path);
                         if (dev == NULL) {
                         else
                                 util_strscpy(path, sizeof(path), optarg);
                         util_remove_trailing_chars(path, '/');
                         dev = udev_device_new_from_syspath(udev, path);
                         if (dev == NULL) {
-                                err(udev, "unable to open the device '%s'\n", optarg);
+                                log_error("unable to open the device '%s'\n", optarg);
                                 rc = 2;
                                 goto exit;
                         }
                                 rc = 2;
                                 goto exit;
                         }