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
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
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
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
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
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
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 \
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
libudev-monitor.c \
../list.h \
../udev.h \
- ../udev_utils.c \
- ../udev_utils_string.c \
../udev_sysdeps.c
libudev_la_LDFLAGS = \
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)
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);
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;
}
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;
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
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';
+}
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;
}
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;
}
}
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;