]> err.no Git - systemd/commitdiff
libudev: get rid of udev_utils.c
authorKay Sievers <kay.sievers@vrfy.org>
Wed, 10 Sep 2008 15:08:24 +0000 (17:08 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Wed, 10 Sep 2008 15:08:24 +0000 (17:08 +0200)
14 files changed:
extras/ata_id/Makefile.am
extras/cdrom_id/Makefile.am
extras/edd_id/Makefile.am
extras/floppy/Makefile.am
extras/fstab_import/Makefile.am
extras/scsi_id/Makefile.am
extras/usb_id/Makefile.am
extras/volume_id/Makefile.am
udev/lib/Makefile.am
udev/lib/libudev-device.c
udev/lib/libudev-enumerate.c
udev/lib/libudev-private.h
udev/lib/libudev-utils.c
udev/lib/libudev.c

index f74964875b166e1ca62c19898399515b12fd0998..61c02fb9f56c92c075f728752bb1c310b5f48184 100644 (file)
@@ -12,6 +12,7 @@ ata_id_SOURCES = \
        ata_id.c \
        ../../udev/lib/libudev.h \
        ../../udev/lib/libudev.c \
+       ../../udev/lib/libudev-utils.c \
        ../../udev/udev_sysdeps.c \
        ../../udev/udev_utils.c \
        ../../udev/udev_utils_string.c
index 9a39ee503a2ab446f18e6a7701d51a5ca000fce2..f0916ba557c9a6c53c8ead2ad263980d398d17ef 100644 (file)
@@ -15,6 +15,7 @@ cdrom_id_SOURCES = \
        cdrom_id.c \
        ../../udev/lib/libudev.h \
        ../../udev/lib/libudev.c \
+       ../../udev/lib/libudev-utils.c \
        ../../udev/udev_sysdeps.c \
        ../../udev/udev_utils.c \
        ../../udev/udev_utils_string.c
index 575de8514d710adc63dbdd82e10d28fe03c59cfa..d5dedda7d9e9efddb152d7a93fa53f71e7487009 100644 (file)
@@ -15,6 +15,7 @@ edd_id_SOURCES = \
        edd_id.c \
        ../../udev/lib/libudev.h \
        ../../udev/lib/libudev.c \
+       ../../udev/lib/libudev-utils.c \
        ../../udev/udev_sysdeps.c \
        ../../udev/udev_utils.c \
        ../../udev/udev_utils_string.c
index 44e9b2fbc070fdcd137c226a0437750b51aa9370..de3876ee5105a8e32c22dfef3da913328659e9f7 100644 (file)
@@ -11,6 +11,7 @@ create_floppy_devices_SOURCES = \
        create_floppy_devices.c \
        ../../udev/lib/libudev.h \
        ../../udev/lib/libudev.c \
+       ../../udev/lib/libudev-utils.c \
        ../../udev/udev_sysdeps.c \
        ../../udev/udev_utils.c \
        ../../udev/udev_utils_string.c
index 92be9a439b84993c192459f100678bdba9185705..07aadafd264d99789178534a34316f1c68964ec2 100644 (file)
@@ -15,6 +15,7 @@ fstab_import_SOURCES = \
        fstab_import.c \
        ../../udev/lib/libudev.h \
        ../../udev/lib/libudev.c \
+       ../../udev/lib/libudev-utils.c \
        ../../udev/udev_sysdeps.c \
        ../../udev/udev_utils.c \
        ../../udev/udev_utils_string.c
index ffa9bf31433137cbed110a77a0d10b54d68e8602..61813fb65ced4779b17dc443e4425f6e204957c4 100644 (file)
@@ -15,6 +15,7 @@ scsi_id_SOURCES = \
        bsg.h \
        ../../udev/lib/libudev.h \
        ../../udev/lib/libudev.c \
+       ../../udev/lib/libudev-utils.c \
        ../../udev/udev_sysdeps.c \
        ../../udev/udev_utils.c \
        ../../udev/udev_utils_string.c
index 9eb6f16b57c5abdddbdbccb40694beb933c85a4a..d69cfe43a1114c460b1b0e67a5da60a85b7332ee 100644 (file)
@@ -11,6 +11,7 @@ usb_id_SOURCES = \
        usb_id.c \
        ../../udev/lib/libudev.h \
        ../../udev/lib/libudev.c \
+       ../../udev/lib/libudev-utils.c \
        ../../udev/udev_sysdeps.c \
        ../../udev/udev_sysfs.c \
        ../../udev/udev_utils.c \
index 85607634152eaf377bf3d3280dda3e572c381476..b4e76180aefa04c5cb98942732cf579472c27460 100644 (file)
@@ -14,6 +14,7 @@ vol_id_SOURCES = \
        vol_id.c \
        ../../udev/lib/libudev.h \
        ../../udev/lib/libudev.c \
+       ../../udev/lib/libudev-utils.c \
        ../../udev/udev_sysdeps.c \
        ../../udev/udev_utils.c \
        ../../udev/udev_utils_string.c
index a768daa8179987b05a5eafb7dfea3dca7a54bf7a..b33addfbf781e4bd65dc041807436c249ee755ba 100644 (file)
@@ -30,8 +30,6 @@ libudev_la_SOURCES =\
        libudev-monitor.c \
        ../list.h \
        ../udev.h \
-       ../udev_utils.c \
-       ../udev_utils_string.c \
        ../udev_sysdeps.c
 
 libudev_la_LDFLAGS = \
index 416cae450d99053997a79d46a1f44e45f0f936d9..78b644b01d8252a638a64a8690e4d191cbd1d9c5 100644 (file)
@@ -61,7 +61,7 @@ static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *f
        strlcpy(filename, udev_get_dev_path(udev), len);
        start = strlcat(filename, "/.udev/db/", len);
        strlcat(filename, devpath, len);
-       return path_encode(&filename[start], len - start);
+       return util_path_encode(&filename[start], len - start);
 }
 
 static int device_read_db(struct udev_device *udev_device)
@@ -264,8 +264,8 @@ void udev_device_unref(struct udev_device *udev_device)
        free(udev_device->syspath);
        free(udev_device->devname);
        free(udev_device->subsystem);
-       name_list_cleanup(udev_device->udev, &udev_device->link_list);
-       name_list_cleanup(udev_device->udev, &udev_device->env_list);
+       util_name_list_cleanup(udev_device->udev, &udev_device->link_list);
+       util_name_list_cleanup(udev_device->udev, &udev_device->env_list);
        free(udev_device->action);
        free(udev_device->driver);
        free(udev_device->devpath_old);
@@ -477,14 +477,14 @@ int device_set_devname(struct udev_device *udev_device, const char *devname)
 
 int device_add_devlink(struct udev_device *udev_device, const char *devlink)
 {
-       if (name_list_add(udev_device->udev, &udev_device->link_list, devlink, 0) == NULL)
+       if (util_name_list_add(udev_device->udev, &udev_device->link_list, devlink, 0) == NULL)
                return -ENOMEM;
        return 0;
 }
 
 int device_add_property(struct udev_device *udev_device, const char *property)
 {
-       if (name_list_add(udev_device->udev, &udev_device->env_list, property, 0) == NULL)
+       if (util_name_list_add(udev_device->udev, &udev_device->env_list, property, 0) == NULL)
                return -ENOMEM;
        return 0;
 }
index f36eafaff6a01055461435a3d256e9ff03047308..72b97cebd7b5784010bbe271579625d4fab64336 100644 (file)
@@ -59,7 +59,7 @@ static int devices_scan_subsystem(struct udev *udev,
                strlcat(devpath, "/", sizeof(devpath));
                strlcat(devpath, dent->d_name, sizeof(devpath));
                util_resolve_sys_link(udev, devpath, sizeof(devpath));
-               name_list_add(udev, device_list, devpath, 1);
+               util_name_list_add(udev, device_list, devpath, 1);
        }
        closedir(dir);
        return 0;
index 1579df6d6e13d02b06a7970b82920f228545bb14..a715067ebb7b03a28847ba717abba294a3f6331c 100644 (file)
@@ -107,4 +107,11 @@ extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg);
 extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size);
 extern ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size);
 extern int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size);
+extern struct util_name_entry *util_name_list_add(struct udev *udev, struct list_head *name_list,
+                                                 const char *name, int sort);
+extern void util_name_list_cleanup(struct udev *udev, struct list_head *name_list);
+extern int util_log_priority(const char *priority);
+extern size_t util_path_encode(char *s, size_t len);
+extern size_t util_path_decode(char *s);
+extern void util_remove_trailing_chars(char *path, char c);
 #endif
index e5f1ed7c38d66af5a95b624a217e282553260f15..dfd5f3c3fb0af26d1f6c5cc046e1eb3ecf1365a5 100644 (file)
@@ -94,3 +94,121 @@ int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size)
        strlcat(devpath, &link_target[back * 3], size);
        return 0;
 }
+
+struct util_name_entry {
+       struct list_head node;
+       char *name;
+       int *i;
+};
+
+struct util_name_entry *util_name_list_add(struct udev *udev, struct list_head *name_list,
+                                          const char *name, int sort)
+{
+       struct util_name_entry *name_loop;
+       struct util_name_entry *name_new;
+
+       /* avoid duplicate entries */
+       list_for_each_entry(name_loop, name_list, node) {
+               if (strcmp(name_loop->name, name) == 0) {
+                       dbg(udev, "'%s' is already in the list\n", name);
+                       return name_loop;
+               }
+       }
+
+       if (sort) {
+               list_for_each_entry(name_loop, name_list, node) {
+                       if (strcmp(name_loop->name, name) > 0)
+                               break;
+               }
+       }
+
+       name_new->name = strdup(name);
+       if (name_new->name == NULL)
+               return NULL;
+       dbg(udev, "adding '%s'\n", name_new->name);
+       list_add_tail(&name_new->node, &name_loop->node);
+       return name_new;
+}
+
+void util_name_list_cleanup(struct udev *udev, struct list_head *name_list)
+{
+       struct util_name_entry *name_loop;
+       struct util_name_entry *name_tmp;
+
+       list_for_each_entry_safe(name_loop, name_tmp, name_list, node) {
+               list_del(&name_loop->node);
+               free(name_loop->name);
+               free(name_loop);
+       }
+}
+
+int util_log_priority(const char *priority)
+{
+       char *endptr;
+       int prio;
+
+       prio = strtol(priority, &endptr, 10);
+       if (endptr[0] == '\0')
+               return prio;
+       if (strncasecmp(priority, "err", 3) == 0)
+               return LOG_ERR;
+       if (strcasecmp(priority, "info") == 0)
+               return LOG_INFO;
+       if (strcasecmp(priority, "debug") == 0)
+               return LOG_DEBUG;
+       return 0;
+}
+
+size_t util_path_encode(char *s, size_t len)
+{
+       char t[(len * 3)+1];
+       size_t i, j;
+
+       t[0] = '\0';
+       for (i = 0, j = 0; s[i] != '\0'; i++) {
+               if (s[i] == '/') {
+                       memcpy(&t[j], "\\x2f", 4);
+                       j += 4;
+               } else if (s[i] == '\\') {
+                       memcpy(&t[j], "\\x5c", 4);
+                       j += 4;
+               } else {
+                       t[j] = s[i];
+                       j++;
+               }
+       }
+       t[j] = '\0';
+       strncpy(s, t, len);
+       return j;
+}
+
+size_t util_path_decode(char *s)
+{
+       size_t i, j;
+
+       for (i = 0, j = 0; s[i] != '\0'; j++) {
+               if (memcmp(&s[i], "\\x2f", 4) == 0) {
+                       s[j] = '/';
+                       i += 4;
+               }else if (memcmp(&s[i], "\\x5c", 4) == 0) {
+                       s[j] = '\\';
+                       i += 4;
+               } else {
+                       s[j] = s[i];
+                       i++;
+               }
+       }
+       s[j] = '\0';
+       return j;
+}
+
+void util_remove_trailing_chars(char *path, char c)
+{
+       size_t len;
+
+       if (path == NULL)
+               return;
+       len = strlen(path);
+       while (len > 0 && path[len-1] == c)
+               path[--len] = '\0';
+}
index 3bcafcd9a6955be02e0c4a4e9d9e0735a7c300df..d1dd9e4838251bca244f82c3a6eea722a5417a3e 100644 (file)
@@ -184,18 +184,18 @@ struct udev *udev_new(void)
        if (env != NULL) {
                free(udev->sys_path);
                udev->sys_path = strdup(env);
-               remove_trailing_chars(udev->sys_path, '/');
+               util_remove_trailing_chars(udev->sys_path, '/');
        }
 
        env = getenv("UDEV_RUN");
-       if (env != NULL && !string_is_true(env))
+       if (env != NULL && strcmp(env, "0") == 0)
                udev->run = 0;
 
        env = getenv("UDEV_CONFIG_FILE");
        if (env != NULL) {
                free(config_file);
                config_file = strdup(env);
-               remove_trailing_chars(config_file, '/');
+               util_remove_trailing_chars(config_file, '/');
        }
        if (config_file == NULL)
                goto err;
@@ -263,19 +263,19 @@ struct udev *udev_new(void)
                        }
 
                        if (strcasecmp(key, "udev_log") == 0) {
-                               udev->log_priority = log_priority(val);
+                               udev->log_priority = util_log_priority(val);
                                continue;
                        }
                        if (strcasecmp(key, "udev_root") == 0) {
                                free(udev->dev_path);
                                udev->dev_path = strdup(val);
-                               remove_trailing_chars(udev->dev_path, '/');
+                               util_remove_trailing_chars(udev->dev_path, '/');
                                continue;
                        }
                        if (strcasecmp(key, "udev_rules") == 0) {
                                free(udev->rules_path);
                                udev->rules_path = strdup(val);
-                               remove_trailing_chars(udev->rules_path, '/');
+                               util_remove_trailing_chars(udev->rules_path, '/');
                                continue;
                        }
                }
@@ -286,12 +286,12 @@ struct udev *udev_new(void)
        if (env != NULL) {
                free(udev->dev_path);
                udev->dev_path = strdup(env);
-               remove_trailing_chars(udev->dev_path, '/');
+               util_remove_trailing_chars(udev->dev_path, '/');
        }
 
        env = getenv("UDEV_LOG");
        if (env != NULL)
-               udev->log_priority = log_priority(env);
+               udev->log_priority = util_log_priority(env);
 
        if (udev->dev_path == NULL || udev->sys_path == NULL)
                goto err;