diff options
author | Kay Sievers <kay@vrfy.org> | 2012-04-16 17:21:22 +0200 |
---|---|---|
committer | Kay Sievers <kay@vrfy.org> | 2012-04-16 19:20:57 +0200 |
commit | 6ada823a9a0979ea145fd70add1007c21caa45c0 (patch) | |
tree | 3eff7319e77b9cdffda502cb373a1eae6c6488bb /src/udev | |
parent | 8fef0ff25c9fd7e5bb99d66f43c6357e4996a3cc (diff) |
udev: remove configuration options for /dev, /sys, /run directories
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/accelerometer/accelerometer.c | 7 | ||||
-rw-r--r-- | src/udev/collect/collect.c | 2 | ||||
-rw-r--r-- | src/udev/udev-builtin-firmware.c | 2 | ||||
-rw-r--r-- | src/udev/udev-ctrl.c | 3 | ||||
-rw-r--r-- | src/udev/udev-event.c | 30 | ||||
-rw-r--r-- | src/udev/udev-node.c | 11 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 72 | ||||
-rw-r--r-- | src/udev/udev-watch.c | 46 | ||||
-rw-r--r-- | src/udev/udev.h | 1 | ||||
-rw-r--r-- | src/udev/udevadm-info.c | 62 | ||||
-rw-r--r-- | src/udev/udevadm-settle.c | 4 | ||||
-rw-r--r-- | src/udev/udevadm-test-builtin.c | 4 | ||||
-rw-r--r-- | src/udev/udevadm-test.c | 4 | ||||
-rw-r--r-- | src/udev/udevadm-trigger.c | 4 | ||||
-rw-r--r-- | src/udev/udevadm.c | 2 | ||||
-rw-r--r-- | src/udev/udevd.c | 55 |
16 files changed, 130 insertions, 179 deletions
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; |