From 6ada823a9a0979ea145fd70add1007c21caa45c0 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 16 Apr 2012 17:21:22 +0200 Subject: udev: remove configuration options for /dev, /sys, /run directories --- Makefile.am | 26 +++++-- TODO | 5 +- docs/libudev/libudev-sections.txt | 4 +- man/udev.xml | 8 --- src/libudev/libudev-device-private.c | 11 ++- src/libudev/libudev-device.c | 69 +++++++++---------- src/libudev/libudev-enumerate.c | 25 ++----- src/libudev/libudev-private.h | 6 +- src/libudev/libudev-queue-private.c | 16 ++--- src/libudev/libudev-queue.c | 8 +-- src/libudev/libudev-selinux-private.c | 2 +- src/libudev/libudev.c | 119 +++------------------------------ src/test/test-libudev.c | 10 +-- src/test/test-udev.c | 2 +- src/udev/accelerometer/accelerometer.c | 7 +- src/udev/collect/collect.c | 2 +- src/udev/udev-builtin-firmware.c | 2 +- src/udev/udev-ctrl.c | 3 +- src/udev/udev-event.c | 30 +++------ src/udev/udev-node.c | 11 ++- src/udev/udev-rules.c | 72 ++++++++++++++------ src/udev/udev-watch.c | 46 +++++-------- src/udev/udev.h | 1 + src/udev/udevadm-info.c | 62 ++++++----------- src/udev/udevadm-settle.c | 4 +- src/udev/udevadm-test-builtin.c | 4 +- src/udev/udevadm-test.c | 4 +- src/udev/udevadm-trigger.c | 4 +- src/udev/udevadm.c | 2 - src/udev/udevd.c | 55 +++------------ test/udev-test.pl | 79 ++++++++-------------- 31 files changed, 253 insertions(+), 446 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0d2cb70349..7df3915b75 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1501,12 +1501,30 @@ test_libudev_LDADD = \ libudev.la test_udev_SOURCES = \ - src/test/test-udev.c + src/test/test-udev.c \ + $(libudev_core_la_SOURCES) \ + $(libudev_private_la_SOURCES) + +# The test-udev program needs everything compiled with relative path +# names for /sys, /dev, /run prefixed, pointing to our test/ directory. +test_udev_CFLAGS = \ + -DTEST_PREFIX=\"test\" \ + $(libudev_core_la_CFLAGS) \ + $(libudev_private_la_CFLAGS) + +test_udev_CPPFLAGS =\ + $(libudev_core_la_CPPFLAGS) test_udev_LDADD = \ - libudev-core.la \ - libudev-private.la \ - libsystemd-shared.la + libsystemd-shared.la \ + $(BLKID_LIBS) \ + $(KMOD_LIBS) \ + $(SELINUX_LIBS) + +if HAVE_ACL +test_udev_LDADD += \ + libsystemd-acl.la +endif check_DATA += \ test/sys diff --git a/TODO b/TODO index 292ee21708..d2145f99d1 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,9 @@ Features: * suspend/hibernate/hybrid support, auto-suspend logic with idle hint -* udev: remove /sys and /dev configurability +* udev: unify selinux stuff with systemd + +* udev: move udev's recursive mkdir to shared/ * udev: find a way to tell udev to not cancel firmware requests when running in initramfs @@ -31,6 +33,7 @@ Features: - return object with *_unref() - kill: udev_monitor_from_socket() - kill: udev_queue_get_failed_list_entry() + - kill: udev_get_{dev,sys,run}_path() * allow configuration of console width/height in vconsole.conf diff --git a/docs/libudev/libudev-sections.txt b/docs/libudev/libudev-sections.txt index 83b2b79ee2..31f356f295 100644 --- a/docs/libudev/libudev-sections.txt +++ b/docs/libudev/libudev-sections.txt @@ -8,11 +8,11 @@ udev_new udev_set_log_fn udev_get_log_priority udev_set_log_priority +udev_get_userdata +udev_set_userdata udev_get_sys_path udev_get_dev_path udev_get_run_path -udev_get_userdata -udev_set_userdata
diff --git a/man/udev.xml b/man/udev.xml index 417fb11ebc..458d351658 100644 --- a/man/udev.xml +++ b/man/udev.xml @@ -64,14 +64,6 @@ It consists of a set of variables allowing the user to override default udev values. The following variables can be set: - - - - Specifies where to place the device nodes in the filesystem. - The default value is /dev. - - - diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index 91fd06c025..c58cde2ff6 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -31,7 +31,7 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add) id = udev_device_get_id_filename(dev); if (id == NULL) return; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags/", tag, "/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/tags/", tag, "/", id, NULL); if (add) { int fd; @@ -108,7 +108,7 @@ int udev_device_update_db(struct udev_device *udev_device) return -1; has_info = device_has_info(udev_device); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); /* do not store anything for otherwise empty devices */ if (!has_info && @@ -138,10 +138,8 @@ int udev_device_update_db(struct udev_device *udev_device) struct udev_list_entry *list_entry; if (major(udev_device_get_devnum(udev_device)) > 0) { - size_t devlen = strlen(udev_get_dev_path(udev))+1; - udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(udev_device)) - fprintf(f, "S:%s\n", &udev_list_entry_get_name(list_entry)[devlen]); + fprintf(f, "S:%s\n", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/")); if (udev_device_get_devlink_priority(udev_device) != 0) fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device)); if (udev_device_get_watch_handle(udev_device) >= 0) @@ -173,13 +171,12 @@ int udev_device_update_db(struct udev_device *udev_device) int udev_device_delete_db(struct udev_device *udev_device) { const char *id; - struct udev *udev = udev_device_get_udev(udev_device); char filename[UTIL_PATH_SIZE]; id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); unlink(filename); return 0; } diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 257d6355fe..212163bb92 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -356,7 +356,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, if (strncmp(property, "DEVPATH=", 8) == 0) { char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev_device->udev), &property[8], NULL); + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys", &property[8], NULL); udev_device_set_syspath(udev_device, path); } else if (strncmp(property, "SUBSYSTEM=", 10) == 0) { udev_device_set_subsystem(udev_device, &property[10]); @@ -473,7 +473,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_device->udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); dbfile = filename; } @@ -496,7 +496,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) val = &line[2]; switch(line[0]) { case 'S': - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", val, NULL); udev_device_add_devlink(udev_device, filename, 0); break; case 'L': @@ -624,7 +624,6 @@ struct udev_device *udev_device_new(struct udev *udev) **/ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) { - size_t len; const char *subdir; char path[UTIL_PATH_SIZE]; char *pos; @@ -637,14 +636,13 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con return NULL; /* path starts in sys */ - len = strlen(udev_get_sys_path(udev)); - if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) { + if (strncmp(syspath, TEST_PREFIX "/sys", strlen(TEST_PREFIX "/sys")) != 0) { dbg(udev, "not in sys :%s\n", syspath); return NULL; } /* path is not a root directory */ - subdir = &syspath[len+1]; + subdir = syspath + strlen(TEST_PREFIX "/sys"); pos = strrchr(subdir, '/'); if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) return NULL; @@ -653,7 +651,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con util_strscpy(path, sizeof(path), syspath); util_resolve_sys_link(udev, path, sizeof(path)); - if (strncmp(&path[len], "/devices/", 9) == 0) { + if (strncmp(path + strlen(TEST_PREFIX "/sys"), "/devices/", 9) == 0) { char file[UTIL_PATH_SIZE]; /* all "devices" require a "uevent" file */ @@ -705,8 +703,8 @@ _public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char return NULL; /* use /sys/dev/{block,char}/: link */ - snprintf(path, sizeof(path), "%s/dev/%s/%u:%u", - udev_get_sys_path(udev), type_str, major(devnum), minor(devnum)); + snprintf(path, sizeof(path), TEST_PREFIX "/sys/dev/%s/%u:%u", + type_str, major(devnum), minor(devnum)); return udev_device_new_from_syspath(udev, path); } @@ -782,32 +780,27 @@ struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id **/ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname) { - char path_full[UTIL_PATH_SIZE]; - char *path; - size_t l; + char path[UTIL_PATH_SIZE]; struct stat statbuf; - path = path_full; - l = util_strpcpyl(&path, sizeof(path_full), udev_get_sys_path(udev), NULL); - if (strcmp(subsystem, "subsystem") == 0) { - util_strscpyl(path, l, "/subsystem/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/class/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; goto out; } if (strcmp(subsystem, "module") == 0) { - util_strscpyl(path, l, "/module/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/module/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; goto out; } @@ -822,32 +815,32 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev driver[0] = '\0'; driver = &driver[1]; - util_strscpyl(path, l, "/subsystem/", subsys, "/drivers/", driver, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsys, "/drivers/", driver, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", subsys, "/drivers/", driver, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsys, "/drivers/", driver, NULL); + if (stat(path, &statbuf) == 0) goto found; } goto out; } - util_strscpyl(path, l, "/subsystem/", subsystem, "/devices/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsystem, "/devices/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", subsystem, "/devices/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsystem, "/devices/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/class/", subsystem, "/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", subsystem, "/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; out: return NULL; found: - return udev_device_new_from_syspath(udev, path_full); + return udev_device_new_from_syspath(udev, path); } /** @@ -893,7 +886,7 @@ static struct udev_device *device_new_from_parent(struct udev_device *udev_devic const char *subdir; util_strscpy(path, sizeof(path), udev_device->syspath); - subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1]; + subdir = path + strlen(TEST_PREFIX "/sys/"); for (;;) { char *pos; @@ -1438,7 +1431,7 @@ int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath udev_device->syspath = strdup(syspath); if (udev_device->syspath == NULL) return -ENOMEM; - udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))]; + udev_device->devpath = udev_device->syspath + strlen(TEST_PREFIX "/sys"); udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath); pos = strrchr(udev_device->syspath, '/'); @@ -1471,7 +1464,7 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode { free(udev_device->devnode); if (devnode[0] != '/') { - if (asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), devnode) < 0) + if (asprintf(&udev_device->devnode, TEST_PREFIX "/dev/%s", devnode) < 0) udev_device->devnode = NULL; } else { udev_device->devnode = strdup(devnode); diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 7b9a732ce6..ed4f62c66c 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -204,12 +204,10 @@ static bool devices_delay_end(struct udev *udev, const char *syspath) "/block/dm-", NULL }; - size_t len; int i; - len = strlen(udev_get_sys_path(udev)); for (i = 0; delay_device_list[i] != NULL; i++) { - if (strstr(&syspath[len], delay_device_list[i]) != NULL) + if (strstr(syspath + strlen("/sys"), delay_device_list[i]) != NULL) return true; } return false; @@ -624,7 +622,6 @@ static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sys static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir1, const char *subdir2) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); char path[UTIL_PATH_SIZE]; size_t l; char *s; @@ -632,7 +629,7 @@ static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, struct dirent *dent; s = path; - l = util_strpcpyl(&s, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL); + l = util_strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL); if (subdir1 != NULL) l = util_strpcpyl(&s, l, "/", subdir1, NULL); if (subdir2 != NULL) @@ -707,13 +704,11 @@ static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *s static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char path[UTIL_PATH_SIZE]; DIR *dir; struct dirent *dent; - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL); + util_strscpyl(path, sizeof(path), "/sys/", basedir, NULL); dir = opendir(path); if (dir == NULL) return -1; @@ -756,7 +751,6 @@ _public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, c static int scan_devices_tags(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); struct udev_list_entry *list_entry; /* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */ @@ -765,8 +759,7 @@ static int scan_devices_tags(struct udev_enumerate *udev_enumerate) struct dirent *dent; char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), udev_get_run_path(udev), "/tags/", - udev_list_entry_get_name(list_entry), NULL); + util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL); dir = opendir(path); if (dir == NULL) continue; @@ -861,12 +854,9 @@ static int scan_devices_children(struct udev_enumerate *enumerate) static int scan_devices_all(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char base[UTIL_PATH_SIZE]; struct stat statbuf; - util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL); - if (stat(base, &statbuf) == 0) { + if (stat("/sys/subsystem", &statbuf) == 0) { /* we have /subsystem/, forget all the old stuff */ scan_dir(udev_enumerate, "subsystem", "devices", NULL); } else { @@ -907,8 +897,6 @@ _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) **/ _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char base[UTIL_PATH_SIZE]; struct stat statbuf; const char *subsysdir; @@ -919,8 +907,7 @@ _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerat if (match_subsystem(udev_enumerate, "module")) scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL); - util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL); - if (stat(base, &statbuf) == 0) + if (stat("/sys/subsystem", &statbuf) == 0) subsysdir = "subsystem"; else subsysdir = "bus"; diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 91f92264dd..986c40c91e 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -19,9 +19,13 @@ #include "macro.h" #include "libudev.h" -#define READ_END 0 +#define READ_END 0 #define WRITE_END 1 +#ifndef TEST_PREFIX +#define TEST_PREFIX "" +#endif + /* avoid (sometimes expensive) calculations of parameters for debug output */ #define udev_log_cond(udev, prio, arg...) \ do { \ diff --git a/src/libudev/libudev-queue-private.c b/src/libudev/libudev-queue-private.c index ca6d229a2c..f653e6db4c 100644 --- a/src/libudev/libudev-queue-private.c +++ b/src/libudev/libudev-queue-private.c @@ -101,14 +101,10 @@ struct udev_queue_export *udev_queue_export_unref(struct udev_queue_export *udev void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export) { - char filename[UTIL_PATH_SIZE]; - if (udev_queue_export == NULL) return; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL); - unlink(filename); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL); - unlink(filename); + unlink("/run/udev/queue.tmp"); + unlink("/run/udev/queue.bin"); } static int skip_to(FILE *file, long offset) @@ -201,8 +197,6 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) { unsigned long long int seqnum; struct queue_devpaths *devpaths = NULL; - char filename[UTIL_PATH_SIZE]; - char filename_tmp[UTIL_PATH_SIZE]; FILE *new_queue_file = NULL; unsigned int i; @@ -218,8 +212,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) } /* create new queue file */ - util_strscpyl(filename_tmp, sizeof(filename_tmp), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL); - new_queue_file = fopen(filename_tmp, "w+"); + new_queue_file = fopen("/run/udev/queue.tmp", "w+"); if (new_queue_file == NULL) goto error; seqnum = udev_queue_export->seqnum_max; @@ -252,8 +245,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) goto error; /* rename the new file on top of the old one */ - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL); - if (rename(filename_tmp, filename) != 0) + if (rename("/run/udev/queue.tmp", "/run/udev/queue.bin") != 0) goto error; if (udev_queue_export->queue_file != NULL) diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index 0e0df8597d..ca23002307 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -121,14 +121,12 @@ _public_ struct udev *udev_queue_get_udev(struct udev_queue *udev_queue) unsigned long long int udev_get_kernel_seqnum(struct udev *udev) { - char filename[UTIL_PATH_SIZE]; unsigned long long int seqnum; int fd; char buf[32]; ssize_t len; - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), "/kernel/uevent_seqnum", NULL); - fd = open(filename, O_RDONLY|O_CLOEXEC); + fd = open("/sys/kernel/uevent_seqnum", O_RDONLY|O_CLOEXEC); if (fd < 0) return 0; len = read(fd, buf, sizeof(buf)); @@ -210,7 +208,7 @@ static FILE *open_queue_file(struct udev_queue *udev_queue, unsigned long long i char filename[UTIL_PATH_SIZE]; FILE *queue_file; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue->udev), "/queue.bin", NULL); + util_strscpyl(filename, sizeof(filename), "/run/udev/queue.bin", NULL); queue_file = fopen(filename, "re"); if (queue_file == NULL) return NULL; @@ -437,7 +435,7 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu snprintf(seqnum_str, sizeof(seqnum_str), "%llu", seqnum); s = syspath; - l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL); + l = util_strpcpy(&s, sizeof(syspath), "/sys"); len = udev_queue_read_devpath(queue_file, s, l); if (len < 0) break; diff --git a/src/libudev/libudev-selinux-private.c b/src/libudev/libudev-selinux-private.c index d68097f991..e9e65ad41d 100644 --- a/src/libudev/libudev-selinux-private.c +++ b/src/libudev/libudev-selinux-private.c @@ -29,7 +29,7 @@ void udev_selinux_init(struct udev *udev) dbg(udev, "selinux=%i\n", selinux_enabled); if (!selinux_enabled) return; - matchpathcon_init_prefix(NULL, udev_get_dev_path(udev)); + matchpathcon_init_prefix(NULL, TEST_PREFIX "/dev"); if (getfscreatecon(&selinux_prev_scontext) < 0) { err(udev, "getfscreatecon failed\n"); selinux_prev_scontext = NULL; diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index 74b53cbf1b..212c5fdd75 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -41,12 +41,6 @@ struct udev { int priority, const char *file, int line, const char *fn, const char *format, va_list args); void *userdata; - char *sys_path; - char *dev_path; - char *rules_path[4]; - unsigned long long rules_path_ts[4]; - int rules_path_count; - char *run_path; struct udev_list properties_list; int log_priority; }; @@ -100,14 +94,6 @@ _public_ void udev_set_userdata(struct udev *udev, void *userdata) udev->userdata = userdata; } -static char *set_value(char **s, const char *v) -{ - free(*s); - *s = strdup(v); - util_remove_trailing_chars(*s, '/'); - return *s; -} - /** * udev_new: * @@ -123,7 +109,6 @@ _public_ struct udev *udev_new(void) { struct udev *udev; const char *env; - char *config_file = NULL; FILE *f; udev = calloc(1, sizeof(struct udev)); @@ -134,21 +119,7 @@ _public_ struct udev *udev_new(void) udev->log_priority = LOG_ERR; udev_list_init(udev, &udev->properties_list, true); - /* custom config file */ - env = getenv("UDEV_CONFIG_FILE"); - if (env != NULL) { - if (set_value(&config_file, env) == NULL) - goto err; - udev_add_property(udev, "UDEV_CONFIG_FILE", config_file); - } - - /* default config file */ - if (config_file == NULL) - config_file = strdup(SYSCONFDIR "/udev/udev.conf"); - if (config_file == NULL) - goto err; - - f = fopen(config_file, "re"); + f = fopen(SYSCONFDIR "/udev/udev.conf", "re"); if (f != NULL) { char line[UTIL_LINE_SIZE]; int line_nr = 0; @@ -172,7 +143,7 @@ _public_ struct udev *udev_new(void) /* split key/value */ val = strchr(key, '='); if (val == NULL) { - err(udev, "missing = in '%s'[%i], skip line\n", config_file, line_nr); + err(udev, "missing = in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); continue; } val[0] = '\0'; @@ -204,7 +175,7 @@ _public_ struct udev *udev_new(void) /* unquote */ if (val[0] == '"' || val[0] == '\'') { if (val[len-1] != val[0]) { - err(udev, "inconsistent quoting in '%s'[%i], skip line\n", config_file, line_nr); + err(udev, "inconsistent quoting in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); continue; } val[len-1] = '\0'; @@ -215,23 +186,6 @@ _public_ struct udev *udev_new(void) udev_set_log_priority(udev, util_log_priority(val)); continue; } - if (strcmp(key, "udev_root") == 0) { - set_value(&udev->dev_path, val); - continue; - } - if (strcmp(key, "udev_run") == 0) { - set_value(&udev->run_path, val); - continue; - } - if (strcmp(key, "udev_sys") == 0) { - set_value(&udev->sys_path, val); - continue; - } - if (strcmp(key, "udev_rules") == 0) { - set_value(&udev->rules_path[0], val); - udev->rules_path_count = 1; - continue; - } } fclose(f); } @@ -241,44 +195,7 @@ _public_ struct udev *udev_new(void) if (env != NULL) udev_set_log_priority(udev, util_log_priority(env)); - /* set defaults */ - if (udev->dev_path == NULL) - if (set_value(&udev->dev_path, "/dev") == NULL) - goto err; - - if (udev->sys_path == NULL) - if (set_value(&udev->sys_path, "/sys") == NULL) - goto err; - - if (udev->run_path == NULL) - if (set_value(&udev->run_path, "/run/udev") == NULL) - goto err; - - if (udev->rules_path[0] == NULL) { - /* /usr/lib/udev -- system rules */ - udev->rules_path[0] = strdup(UDEVLIBEXECDIR "/rules.d"); - if (!udev->rules_path[0]) - goto err; - - /* /run/udev -- runtime rules */ - if (asprintf(&udev->rules_path[1], "%s/rules.d", udev->run_path) < 0) - goto err; - - /* /etc/udev -- local administration rules */ - udev->rules_path[2] = strdup(SYSCONFDIR "/udev/rules.d"); - if (!udev->rules_path[2]) - goto err; - - udev->rules_path_count = 3; - } - - free(config_file); return udev; -err: - free(config_file); - err(udev, "context creation failed\n"); - udev_unref(udev); - return NULL; } /** @@ -313,12 +230,6 @@ _public_ void udev_unref(struct udev *udev) if (udev->refcount > 0) return; udev_list_cleanup(&udev->properties_list); - free(udev->dev_path); - free(udev->sys_path); - free(udev->rules_path[0]); - free(udev->rules_path[1]); - free(udev->rules_path[2]); - free(udev->run_path); free(udev); } @@ -372,21 +283,11 @@ _public_ void udev_set_log_priority(struct udev *udev, int priority) udev_add_property(udev, "UDEV_LOG", num); } -int udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *stamp_usec[]) -{ - *path = udev->rules_path; - if (stamp_usec) - *stamp_usec = udev->rules_path_ts; - return udev->rules_path_count; -} - /** * udev_get_sys_path: * @udev: udev library context * - * Retrieve the sysfs mount point. The default is "/sys". For - * testing purposes, it can be overridden with udev_sys= - * in the udev configuration file. + * Returns always "/sys"; deprecated, will be removed in a future version. * * Returns: the sys mount point **/ @@ -394,16 +295,14 @@ _public_ const char *udev_get_sys_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->sys_path; + return "/sys"; } /** * udev_get_dev_path: * @udev: udev library context * - * Retrieve the device directory path. The default value is "/dev", - * the actual value may be overridden in the udev configuration - * file. + * Returns always "/dev"; deprecated, will be removed in a future version. * * Returns: the device directory path **/ @@ -411,14 +310,14 @@ _public_ const char *udev_get_dev_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->dev_path; + return "/dev"; } /** * udev_get_run_path: * @udev: udev library context * - * Retrieve the udev runtime directory path. The default is "/run/udev". + * Returns always "/run/udev"; deprecated, will be removed in a future version. * * Returns: the runtime directory path **/ @@ -426,7 +325,7 @@ _public_ const char *udev_get_run_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->run_path; + return "/run/udev"; } struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value) diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index 6161fb3e31..f5c7ae2c30 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -434,7 +434,6 @@ int main(int argc, char *argv[]) const char *syspath = "/devices/virtual/mem/null"; const char *subsystem = NULL; char path[1024]; - const char *str; udev = udev_new(); printf("context: %p\n", udev); @@ -474,14 +473,9 @@ int main(int argc, char *argv[]) } } - str = udev_get_sys_path(udev); - printf("sys_path: '%s'\n", str); - str = udev_get_dev_path(udev); - printf("dev_path: '%s'\n", str); - /* add sys path if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) { - snprintf(path, sizeof(path), "%s%s", udev_get_sys_path(udev), syspath); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) { + snprintf(path, sizeof(path), "/sys/%s", syspath); syspath = path; } diff --git a/src/test/test-udev.c b/src/test/test-udev.c index 150cb16a31..b843e5f648 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) rules = udev_rules_new(udev, 1); - util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL); + util_strscpyl(syspath, sizeof(syspath), TEST_PREFIX "/sys", devpath, NULL); dev = udev_device_new_from_syspath(udev, syspath); if (dev == NULL) { log_debug("unknown device '%s'\n", devpath); diff --git a/src/udev/accelerometer/accelerometer.c b/src/udev/accelerometer/accelerometer.c index 4c5e47d0b7..08be363370 100644 --- a/src/udev/accelerometer/accelerometer.c +++ b/src/udev/accelerometer/accelerometer.c @@ -294,7 +294,7 @@ int main (int argc, char** argv) } /* get the device */ - snprintf(devpath, sizeof(devpath), "%s/%s", udev_get_sys_path(udev), argv[optind]); + snprintf(devpath, sizeof(devpath), "/sys/%s", argv[optind]); dev = udev_device_new_from_syspath(udev, devpath); if (dev == NULL) { fprintf(stderr, "unable to access '%s'\n", devpath); @@ -307,9 +307,8 @@ int main (int argc, char** argv) return 0; } - /* Get the children devices and find the devnode - * FIXME: use udev_enumerate_add_match_children() instead - * when it's available */ + /* Get the children devices and find the devnode */ + /* FIXME: use udev_enumerate_add_match_parent() instead */ devnode = NULL; enumerate = udev_enumerate_new(udev); udev_enumerate_add_match_property(enumerate, "ID_PATH", id_path); diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index 076fe479e2..882564a5f5 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -405,7 +405,7 @@ int main(int argc, char **argv) if (debug) fprintf(stderr, "Using checkpoint '%s'\n", checkpoint); - util_strscpyl(tmpdir, sizeof(tmpdir), udev_get_run_path(udev), "/collect", NULL); + util_strscpyl(tmpdir, sizeof(tmpdir), "/run/udev/collect", NULL); fd = prepare(tmpdir, checkpoint); if (fd < 0) { ret = 3; diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c index 5ba712c89d..bd2716fdc8 100644 --- a/src/udev/udev-builtin-firmware.c +++ b/src/udev/udev-builtin-firmware.c @@ -112,7 +112,7 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo } util_path_encode(firmware, fwencpath, sizeof(fwencpath)); - util_strscpyl(misspath, sizeof(misspath), udev_get_run_path(udev), "/firmware-missing/", fwencpath, NULL); + util_strscpyl(misspath, sizeof(misspath), "/run/udev/firmware-missing/", fwencpath, NULL); util_strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL); if (fwfile == NULL) { diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 71c330f6f9..fcb0cd48a6 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -93,8 +93,7 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) } uctrl->saddr.sun_family = AF_LOCAL; - util_strscpyl(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), - udev_get_run_path(udev), "/control", NULL); + util_strscpy(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), "/run/udev/control"); uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.sun_path); return uctrl; } diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index eab1bae27f..d330062ebf 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -318,46 +318,38 @@ subst: if (dev_parent == NULL) break; devnode = udev_device_get_devnode(dev_parent); - if (devnode != NULL) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - l = util_strpcpy(&s, l, &devnode[devlen]); - } + if (devnode != NULL) + l = util_strpcpy(&s, l, devnode + strlen(TEST_PREFIX "/dev/")); break; } case SUBST_DEVNODE: if (udev_device_get_devnode(dev) != NULL) l = util_strpcpy(&s, l, udev_device_get_devnode(dev)); break; - case SUBST_NAME: { - if (event->name != NULL) { + case SUBST_NAME: + if (event->name != NULL) l = util_strpcpy(&s, l, event->name); - } else if (udev_device_get_devnode(dev) != NULL) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - l = util_strpcpy(&s, l, &udev_device_get_devnode(dev)[devlen]); - } else { + else if (udev_device_get_devnode(dev) != NULL) + l = util_strpcpy(&s, l, udev_device_get_devnode(dev) + strlen(TEST_PREFIX "/dev/")); + else l = util_strpcpy(&s, l, udev_device_get_sysname(dev)); - } break; - } case SUBST_LINKS: { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; struct udev_list_entry *list_entry; list_entry = udev_device_get_devlinks_list_entry(dev); if (list_entry == NULL) break; - l = util_strpcpy(&s, l, &udev_list_entry_get_name(list_entry)[devlen]); + l = util_strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/")); udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) - l = util_strpcpyl(&s, l, " ", &udev_list_entry_get_name(list_entry)[devlen], NULL); + l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"), NULL); break; } case SUBST_ROOT: - l = util_strpcpy(&s, l, udev_get_dev_path(event->udev)); + l = util_strpcpy(&s, l, TEST_PREFIX "/dev"); break; case SUBST_SYS: - l = util_strpcpy(&s, l, udev_get_sys_path(event->udev)); + l = util_strpcpy(&s, l, TEST_PREFIX "/sys"); break; case SUBST_ENV: if (attr == NULL) { diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 8e1318872a..26a43e9623 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -203,8 +203,8 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) const char *target; char buf[UTIL_PATH_SIZE]; - util_path_encode(&slink[strlen(udev_get_dev_path(udev))+1], name_enc, sizeof(name_enc)); - util_strscpyl(dirname, sizeof(dirname), udev_get_run_path(udev), "/links/", name_enc, NULL); + util_path_encode(slink + strlen(TEST_PREFIX "/dev"), name_enc, sizeof(name_enc)); + util_strscpyl(dirname, sizeof(dirname), TEST_PREFIX "/run/udev/links/", name_enc, NULL); util_strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL); if (!add && unlink(filename) == 0) @@ -329,8 +329,7 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) return; /* always add /dev/{block,char}/$major:$minor */ - snprintf(filename, sizeof(filename), "%s/%s/%u:%u", - udev_get_dev_path(udev), + snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u", strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); node_symlink(udev, udev_device_get_devnode(dev), filename); @@ -347,7 +346,6 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) void udev_node_remove(struct udev_device *dev) { - struct udev *udev = udev_device_get_udev(dev); struct udev_list_entry *list_entry; char filename[UTIL_PATH_SIZE]; @@ -356,8 +354,7 @@ void udev_node_remove(struct udev_device *dev) link_update(dev, udev_list_entry_get_name(list_entry), 0); /* remove /dev/{block,char}/$major:$minor */ - snprintf(filename, sizeof(filename), "%s/%s/%u:%u", - udev_get_dev_path(udev), + snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u", strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); unlink(filename); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 55d7e30c02..1ec817872d 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -36,6 +36,13 @@ #define PREALLOC_STRBUF 32 * 1024 #define PREALLOC_TRIE 256 +/* configuration directories with last modification timestamp */ +static const char *rules_dirs[] = { + TEST_PREFIX UDEVLIBEXECDIR "/rules.d", + TEST_PREFIX "/run/udev/rules.d", + TEST_PREFIX SYSCONFDIR "/udev/rules.d", +}; + struct uid_gid { unsigned int name_off; union { @@ -58,6 +65,7 @@ struct trie_node { struct udev_rules { struct udev *udev; + unsigned long long dirs_ts_usec[ELEMENTSOF(rules_dirs)]; int resolve_names; /* every key in the rules file becomes a token */ @@ -664,7 +672,6 @@ static gid_t add_gid(struct udev_rules *rules, const char *group) static int import_property_from_string(struct udev_device *dev, char *line) { - struct udev *udev = udev_device_get_udev(dev); char *key; char *val; size_t len; @@ -724,7 +731,7 @@ static int import_property_from_string(struct udev_device *dev, char *line) log_debug("updating devpath from '%s' to '%s'\n", udev_device_get_devpath(dev), val); - util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), val, NULL); + util_strscpyl(syspath, sizeof(syspath), "/sys", val, NULL); udev_device_set_syspath(dev, syspath); } else { struct udev_list_entry *entry; @@ -807,7 +814,6 @@ static int import_parent_into_properties(struct udev_device *dev, const char *fi #define WAIT_LOOP_PER_SECOND 50 static int wait_for_file(struct udev_device *dev, const char *file, int timeout) { - struct udev *udev = udev_device_get_udev(dev); char filepath[UTIL_PATH_SIZE]; char devicepath[UTIL_PATH_SIZE]; struct stat stats; @@ -816,8 +822,7 @@ static int wait_for_file(struct udev_device *dev, const char *file, int timeout) /* a relative path is a device attribute */ devicepath[0] = '\0'; if (file[0] != '/') { - util_strscpyl(devicepath, sizeof(devicepath), - udev_get_sys_path(udev), udev_device_get_devpath(dev), NULL); + util_strscpyl(devicepath, sizeof(devicepath), udev_device_get_syspath(dev), NULL); util_strscpyl(filepath, sizeof(filepath), devicepath, "/", file, NULL); file = filepath; } @@ -1746,7 +1751,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) struct udev_list file_list; struct udev_list_entry *file_loop; struct token end_token; - char **s; + unsigned int i; rules = calloc(1, sizeof(struct udev_rules)); if (rules == NULL) @@ -1786,8 +1791,8 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) memset(rules->trie_nodes, 0x00, sizeof(struct trie_node)); rules->trie_nodes_cur = 1; - for (udev_get_rules_path(udev, &s, NULL); *s != NULL; s++) - add_matching_files(udev, &file_list, *s, ".rules"); + for (i = 0; i < ELEMENTSOF(rules_dirs); i++) + add_matching_files(udev, &file_list, rules_dirs[i], ".rules"); /* add all filenames to the string buffer */ udev_list_entry_foreach(file_loop, udev_list_get_entry(&file_list)) { @@ -1884,6 +1889,33 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules) return NULL; } +bool udev_rules_check_timestamp(struct udev_rules *rules) +{ + unsigned int i; + bool changed = false; + + for (i = 0; i < ELEMENTSOF(rules_dirs); i++) { + struct stat stats; + + if (stat(rules_dirs[i], &stats) < 0) + continue; + + if (rules->dirs_ts_usec[i] == ts_usec(&stats.st_mtim)) + continue; + + /* first check */ + if (rules->dirs_ts_usec[i] != 0) { + log_debug("reload - timestamp of '%s' changed\n", rules_dirs[i]); + changed = true; + } + + /* update timestamp */ + rules->dirs_ts_usec[i] = ts_usec(&stats.st_mtim); + } + + return changed; +} + static int match_key(struct udev_rules *rules, struct token *token, const char *val) { char *key_value = &rules->buf[token->key.value_off]; @@ -2054,14 +2086,13 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event goto nomatch; break; case TK_M_DEVLINK: { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; struct udev_list_entry *list_entry; bool match = false; udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(event->dev)) { const char *devlink; - devlink = &udev_list_entry_get_name(list_entry)[devlen]; + devlink = udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"); if (match_key(rules, cur, devlink) == 0) { match = true; break; @@ -2534,15 +2565,12 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (count > 0) log_debug("%i character(s) replaced\n", count); } - if (major(udev_device_get_devnum(event->dev))) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - if (strcmp(name_str, &udev_device_get_devnode(event->dev)[devlen]) != 0) { - log_error("NAME=\"%s\" ignored, kernel device nodes " - "can not be renamed; please fix it in %s:%u\n", name, - &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - break; - } + if (major(udev_device_get_devnum(event->dev)) && + (strcmp(name_str, udev_device_get_devnode(event->dev) + strlen(TEST_PREFIX "/dev/")) != 0)) { + log_error("NAME=\"%s\" ignored, kernel device nodes " + "can not be renamed; please fix it in %s:%u\n", name, + &rules->buf[rule->rule.filename_off], rule->rule.filename_line); + break; } free(event->name); event->name = strdup(name_str); @@ -2583,7 +2611,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event next[0] = '\0'; log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); while (isspace(next[1])) next++; @@ -2593,7 +2621,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (pos[0] != '\0') { log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); } break; @@ -2703,7 +2731,7 @@ void udev_rules_apply_static_dev_perms(struct udev_rules *rules) /* we assure, that the permissions tokens are sorted before the static token */ if (mode == 0 && uid == 0 && gid == 0) goto next; - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(rules->udev), "/", + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", &rules->buf[cur->key.value_off], NULL); if (stat(filename, &stats) != 0) goto next; diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 968728eba9..7d5b30bd68 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -49,41 +49,33 @@ int udev_watch_init(struct udev *udev) */ void udev_watch_restore(struct udev *udev) { - char filename[UTIL_PATH_SIZE], oldname[UTIL_PATH_SIZE]; - if (inotify_fd < 0) return; - util_strscpyl(oldname, sizeof(oldname), udev_get_run_path(udev), "/watch.old", NULL); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch", NULL); - if (rename(filename, oldname) == 0) { + if (rename("/run/udev/watch", "/run/udev/watch.old") == 0) { DIR *dir; struct dirent *ent; - dir = opendir(oldname); + dir = opendir("/run/udev/watch.old"); if (dir == NULL) { - log_error("unable to open old watches dir '%s', old watches will not be restored: %m", oldname); + log_error("unable to open old watches dir /run/udev/watch.old; old watches will not be restored: %m"); return; } for (ent = readdir(dir); ent != NULL; ent = readdir(dir)) { char device[UTIL_PATH_SIZE]; - char *s; - size_t l; ssize_t len; struct udev_device *dev; if (ent->d_name[0] == '.') continue; - s = device; - l = util_strpcpy(&s, sizeof(device), udev_get_sys_path(udev)); - len = readlinkat(dirfd(dir), ent->d_name, s, l); - if (len <= 0 || len == (ssize_t)l) + len = readlinkat(dirfd(dir), ent->d_name, device, sizeof(device)); + if (len <= 0 || len == (ssize_t)sizeof(device)) goto unlink; - s[len] = '\0'; + device[len] = '\0'; - dev = udev_device_new_from_id_filename(udev, s); + dev = udev_device_new_from_id_filename(udev, device); if (dev == NULL) goto unlink; @@ -95,10 +87,10 @@ unlink: } closedir(dir); - rmdir(oldname); + rmdir("/run/udev/watch.old"); } else if (errno != ENOENT) { - log_error("unable to move watches dir '%s', old watches will not be restored: %m", filename); + log_error("unable to move watches dir /run/udev/watch; old watches will not be restored: %m"); } } @@ -118,7 +110,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) return; } - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); util_create_path(udev, filename); unlink(filename); symlink(udev_device_get_id_filename(dev), filename); @@ -141,7 +133,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) log_debug("removing watch on '%s'\n", udev_device_get_devnode(dev)); inotify_rm_watch(inotify_fd, wd); - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); unlink(filename); udev_device_set_watch_handle(dev, -1); @@ -150,21 +142,17 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) struct udev_device *udev_watch_lookup(struct udev *udev, int wd) { char filename[UTIL_PATH_SIZE]; - char majmin[UTIL_PATH_SIZE]; - char *s; - size_t l; + char device[UTIL_NAME_SIZE]; ssize_t len; if (inotify_fd < 0 || wd < 0) return NULL; - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); - s = majmin; - l = util_strpcpy(&s, sizeof(majmin), udev_get_sys_path(udev)); - len = readlink(filename, s, l); - if (len <= 0 || (size_t)len == l) + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); + len = readlink(filename, device, sizeof(device)); + if (len <= 0 || (size_t)len == sizeof(device)) return NULL; - s[len] = '\0'; + device[len] = '\0'; - return udev_device_new_from_id_filename(udev, s); + return udev_device_new_from_id_filename(udev, device); } diff --git a/src/udev/udev.h b/src/udev/udev.h index 681660ecb7..ed5f768ea8 100644 --- a/src/udev/udev.h +++ b/src/udev/udev.h @@ -65,6 +65,7 @@ struct udev_watch { struct udev_rules; struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names); struct udev_rules *udev_rules_unref(struct udev_rules *rules); +bool udev_rules_check_timestamp(struct udev_rules *rules); int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, const sigset_t *sigmask); void udev_rules_apply_static_dev_perms(struct udev_rules *rules); diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 39221b7374..3b14139459 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -131,26 +131,22 @@ static int print_device_chain(struct udev_device *device) static void print_record(struct udev_device *device) { - size_t len; const char *str; int i; struct udev_list_entry *list_entry; printf("P: %s\n", udev_device_get_devpath(device)); - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); str = udev_device_get_devnode(device); if (str != NULL) - printf("N: %s\n", &str[len+1]); + printf("N: %s\n", str + strlen("/dev/")); i = udev_device_get_devlink_priority(device); if (i != 0) printf("L: %i\n", i); - udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) { - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); - printf("S: %s\n", &udev_list_entry_get_name(list_entry)[len+1]); - } + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) + printf("S: %s\n", udev_list_entry_get_name(list_entry) + strlen("/dev/")); udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) printf("E: %s=%s\n", @@ -233,42 +229,35 @@ static void cleanup_dir(DIR *dir, mode_t mask, int depth) static void cleanup_db(struct udev *udev) { - char filename[UTIL_PATH_SIZE]; DIR *dir; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/queue.bin", NULL); - unlink(filename); + unlink("/run/udev/queue.bin"); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/data"); if (dir != NULL) { cleanup_dir(dir, S_ISVTX, 1); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/links", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/links"); if (dir != NULL) { cleanup_dir(dir, 0, 2); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/tags"); if (dir != NULL) { cleanup_dir(dir, 0, 2); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/watch"); if (dir != NULL) { cleanup_dir(dir, 0, 1); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/firmware-missing", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/firmware-missing"); if (dir != NULL) { cleanup_dir(dir, 0, 1); closedir(dir); @@ -335,9 +324,9 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) rc = 2; goto exit; } - /* remove /dev if given */ - if (strncmp(optarg, udev_get_dev_path(udev), strlen(udev_get_dev_path(udev))) != 0) - util_strscpyl(name, sizeof(name), udev_get_dev_path(udev), "/", optarg, NULL); + /* add /dev if not given */ + if (strncmp(optarg, "/dev", strlen("/dev")) != 0) + util_strscpyl(name, sizeof(name), "/dev/", optarg, NULL); else util_strscpy(name, sizeof(name), optarg); util_remove_trailing_chars(name, '/'); @@ -372,8 +361,8 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) goto exit; } /* 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 (strncmp(optarg, "/sys", strlen("/sys")) != 0) + util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); else util_strscpy(path, sizeof(path), optarg); util_remove_trailing_chars(path, '/'); @@ -408,7 +397,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) root = true; break; case 'R': - printf("%s\n", udev_get_run_path(udev)); + printf("/run/udev\n"); goto exit; case 'd': action = ACTION_DEVICE_ID_FILE; @@ -476,26 +465,19 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) goto exit; } - if (root) { + if (root) printf("%s\n", udev_device_get_devnode(device)); - } else { - size_t len = strlen(udev_get_dev_path(udev)); - - printf("%s\n", &udev_device_get_devnode(device)[len+1]); - } + else + printf("%s\n", udev_device_get_devnode(device) + strlen("/dev/")); break; } case QUERY_SYMLINK: list_entry = udev_device_get_devlinks_list_entry(device); while (list_entry != NULL) { - if (root) { + if (root) printf("%s", udev_list_entry_get_name(list_entry)); - } else { - size_t len; - - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); - printf("%s", &udev_list_entry_get_name(list_entry)[len+1]); - } + else + printf("%s", udev_list_entry_get_name(list_entry) + strlen("/dev/")); list_entry = udev_list_entry_get_next(list_entry); if (list_entry != NULL) printf(" "); @@ -543,7 +525,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) rc = 1; break; case ACTION_ROOT: - printf("%s\n", udev_get_dev_path(udev)); + printf("/dev\n"); break; default: fprintf(stderr, "missing option\n"); diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 19c1e99ccb..e70b351eb9 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -152,8 +152,8 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) if (pfd[0].fd < 0) { log_error("inotify_init failed: %m\n"); } else { - if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_MOVED_TO) < 0) { - log_error("watching '%s' failed\n", udev_get_run_path(udev)); + if (inotify_add_watch(pfd[0].fd, "/run/udev" , IN_MOVED_TO) < 0) { + log_error("watching /run/udev failed\n"); close(pfd[0].fd); pfd[0].fd = -1; } diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 94bb24f5f8..e63b1f4eb7 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -95,8 +95,8 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) + util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else util_strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index f963c1b510..0c8a762540 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -112,8 +112,8 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) + util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else util_strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 99ef12cb85..a910121ecd 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -164,8 +164,8 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) 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 (strncmp(optarg, "/sys", strlen("/sys")) != 0) + util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); else util_strscpy(path, sizeof(path), optarg); util_remove_trailing_chars(path, '/'); diff --git a/src/udev/udevadm.c b/src/udev/udevadm.c index 0858c37be8..2b4a845d77 100644 --- a/src/udev/udevadm.c +++ b/src/udev/udevadm.c @@ -128,8 +128,6 @@ int main(int argc, char *argv[]) } command = argv[optind]; - log_debug("runtime dir '%s'\n", udev_get_run_path(udev)); - if (command != NULL) for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) { if (strcmp(udevadm_cmds[i]->name, command) == 0) { diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 24f0bf6d1e..d6de2aa222 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -856,7 +856,7 @@ static void static_dev_create_from_modules(struct udev *udev) else continue; - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/", devname, NULL); + util_strscpyl(filename, sizeof(filename), "/dev/", devname, NULL); util_create_path_selinux(udev, filename); udev_selinux_setfscreatecon(udev, filename, mode); log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min); @@ -885,7 +885,7 @@ static void static_dev_create_links(struct udev *udev) }; unsigned int i; - dir = opendir(udev_get_dev_path(udev)); + dir = opendir("/dev"); if (dir == NULL) return; @@ -934,16 +934,15 @@ static int convert_db(struct udev *udev) struct udev_list_entry *list_entry; /* current database */ - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL); - if (access(filename, F_OK) >= 0) + if (access("/run/udev/data", F_OK) >= 0) return 0; /* make sure we do not get here again */ - util_create_path(udev, filename); + util_create_path(udev, "/run/udev/data"); mkdir(filename, 0755); /* old database */ - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db", NULL); + util_strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL); if (access(filename, F_OK) < 0) return 0; @@ -976,7 +975,7 @@ static int convert_db(struct udev *udev) /* find database in old location */ id = udev_device_get_id_filename(device); - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", id, NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -986,9 +985,8 @@ static int convert_db(struct udev *udev) } /* find old database with $subsys:$sysname name */ - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), - "/.udev/db/", udev_device_get_subsystem(device), ":", - udev_device_get_sysname(device), NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", + udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -999,7 +997,7 @@ static int convert_db(struct udev *udev) /* find old database with the encoded devpath name */ util_path_encode(udev_device_get_devpath(device), devpath, sizeof(devpath)); - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", devpath, NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -1054,36 +1052,6 @@ static int systemd_fds(struct udev *udev, int *rctrl, int *rnetlink) return 0; } -static bool check_rules_timestamp(struct udev *udev) -{ - char **p; - unsigned long long *stamp_usec; - int i, n; - bool changed = false; - - n = udev_get_rules_path(udev, &p, &stamp_usec); - for (i = 0; i < n; i++) { - struct stat stats; - - if (stat(p[i], &stats) < 0) - continue; - - if (stamp_usec[i] == ts_usec(&stats.st_mtim)) - continue; - - /* first check */ - if (stamp_usec[i] != 0) { - log_debug("reload - timestamp of '%s' changed\n", p[i]); - changed = true; - } - - /* update timestamp */ - stamp_usec[i] = ts_usec(&stats.st_mtim); - } - - return changed; -} - int main(int argc, char *argv[]) { struct udev *udev; @@ -1216,8 +1184,7 @@ int main(int argc, char *argv[]) chdir("/"); umask(022); - /* /run/udev */ - mkdir(udev_get_run_path(udev), 0755); + mkdir("/run/udev", 0755); /* create standard links, copy static nodes, create nodes from modules */ static_dev_create_links(udev); @@ -1557,7 +1524,7 @@ int main(int argc, char *argv[]) /* check for changed config, every 3 seconds at most */ if ((now_usec() - last_usec) > 3 * 1000 * 1000) { - if (check_rules_timestamp(udev)) + if (udev_rules_check_timestamp(rules)) reload = true; if (udev_builtin_validate(udev)) reload = true; diff --git a/test/udev-test.pl b/test/udev-test.pl index 0a2571a1d5..d80b00c374 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -14,20 +14,19 @@ # After creation and removal the result is checked against the # expected value and the result is printed. # -# Copyright (C) 2004-2011 Kay Sievers +# Copyright (C) 2004-2012 Kay Sievers # Copyright (C) 2004 Leann Ogasawara use warnings; use strict; -my $PWD = $ENV{PWD}; -my $sysfs = "test/sys"; my $udev_bin = "./test-udev"; my $valgrind = 0; my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin"; -my $udev_root = "udev-root"; -my $udev_conf = "udev-test.conf"; -my $udev_rules = "udev-test.rules"; +my $udev_dev = "test/dev"; +my $udev_run = "test/run"; +my $udev_rules_dir = "$udev_run/udev/rules.d"; +my $udev_rules = "$udev_rules_dir/udev-test.rules"; my @tests = ( { @@ -251,15 +250,6 @@ EOF exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" , rules => < "import of shell-value file", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "subdir/err/node" , - rules => < "tty33", exp_perms => "0:0:0600", rules => < "udev_root substitution", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "start-udev-root-end", + exp_name => "start-test/dev-end", rules => <$udev_rules" || die "unable to create rules file: $udev_rules"; print CONF $$rules; close CONF; @@ -1416,13 +1404,15 @@ sub major_minor_test { } } -sub make_udev_root { - system("rm -rf $udev_root"); - mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; - # setting group and mode of udev_root ensures the tests work +sub udev_setup { + system("rm", "-rf", "$udev_dev"); + mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n"; + # setting group and mode of udev_dev ensures the tests work # even if the parent directory has setgid bit enabled. - chown (0, 0, $udev_root) || die "unable to chown $udev_root\n"; - chmod (0755, $udev_root) || die "unable to chmod $udev_root\n"; + chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n"; + chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n"; + + system("rm", "-rf", "$udev_run"); } sub run_test { @@ -1433,19 +1423,19 @@ sub run_test { udev("add", $rules->{devpath}, \$rules->{rules}); if (defined($rules->{not_exp_name})) { - if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") || - (-l "$PWD/$udev_root/$rules->{not_exp_name}")) { + if ((-e "$udev_dev/$rules->{not_exp_name}") || + (-l "$udev_dev/$rules->{not_exp_name}")) { print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; $error++; sleep(1); } } - if ((-e "$PWD/$udev_root/$rules->{exp_name}") || - (-l "$PWD/$udev_root/$rules->{exp_name}")) { + if ((-e "$udev_dev/$rules->{exp_name}") || + (-l "$udev_dev/$rules->{exp_name}")) { my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, - $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}"); + $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}"); if (defined($rules->{exp_perms})) { permissions_test($rules, $uid, $gid, $mode); @@ -1460,7 +1450,7 @@ sub run_test { print " as expected\n"; } else { print "\n"; - system("tree $udev_root"); + system("tree", "$udev_dev"); print "\n"; $error++; sleep(1); @@ -1473,14 +1463,14 @@ sub run_test { } udev("remove", $rules->{devpath}, \$rules->{rules}); - if ((-e "$PWD/$udev_root/$rules->{exp_name}") || - (-l "$PWD/$udev_root/$rules->{exp_name}")) { + if ((-e "$udev_dev/$rules->{exp_name}") || + (-l "$udev_dev/$rules->{exp_name}")) { print "remove: error"; if ($rules->{exp_rem_error}) { print " as expected\n"; } else { print "\n"; - system("tree $udev_root"); + system("tree", "$udev_dev"); print "\n"; $error++; sleep(1); @@ -1492,7 +1482,7 @@ sub run_test { print "\n"; if (defined($rules->{option}) && $rules->{option} eq "clean") { - make_udev_root(); + udev_setup(); } } @@ -1504,17 +1494,7 @@ if (!($<==0)) { exit; } -# prepare -make_udev_root(); - -# create config file -open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf"; -print CONF "udev_root=\"$udev_root\"\n"; -print CONF "udev_run=\"$udev_root/.udev\"\n"; -print CONF "udev_sys=\"$sysfs\"\n"; -print CONF "udev_rules=\"$PWD\"\n"; -print CONF "udev_log=\"err\"\n"; -close CONF; +udev_setup(); my $test_num = 1; my @list; @@ -1550,9 +1530,8 @@ if ($list[0]) { print "$error errors occured\n\n"; # cleanup -system("rm -rf $udev_root"); -unlink($udev_rules); -unlink($udev_conf); +system("rm", "-rf", "$udev_dev"); +system("rm", "-rf", "$udev_run"); if ($error > 0) { exit(1); -- cgit v1.2.3-54-g00ecf