diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2011-03-23 02:31:09 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2011-03-23 02:31:09 +0100 |
commit | 4ec9c3e79771aa95586390cecff4218cc8938160 (patch) | |
tree | e26e6bd8125ebcefbdf9674739df7573d17a040a /udev | |
parent | 3c6ee190277f9d4bf39269fdb167f9c430633c9b (diff) |
use /run/udev/ if possible and fall back to /dev/.udev/
Diffstat (limited to 'udev')
-rw-r--r-- | udev/udev-node.c | 2 | ||||
-rw-r--r-- | udev/udev-rules.c | 2 | ||||
-rw-r--r-- | udev/udev-watch.c | 10 | ||||
-rw-r--r-- | udev/udev.xml | 2 | ||||
-rw-r--r-- | udev/udevadm-info.c | 6 | ||||
-rw-r--r-- | udev/udevadm.c | 2 | ||||
-rw-r--r-- | udev/udevadm.xml | 6 | ||||
-rw-r--r-- | udev/udevd.c | 32 |
8 files changed, 48 insertions, 14 deletions
diff --git a/udev/udev-node.c b/udev/udev-node.c index aaa2e32e65..ab4e932288 100644 --- a/udev/udev-node.c +++ b/udev/udev-node.c @@ -292,7 +292,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) dbg(udev, "update symlink '%s' of '%s'\n", slink, udev_device_get_syspath(dev)); util_path_encode(&slink[strlen(udev_get_dev_path(udev))+1], name_enc, sizeof(name_enc)); - util_strscpyl(dirname, sizeof(dirname), udev_get_dev_path(udev), "/.run/udev/links/", name_enc, NULL); + util_strscpyl(dirname, sizeof(dirname), udev_get_run_path(udev), "/links/", name_enc, NULL); util_strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL); if (!add) { diff --git a/udev/udev-rules.c b/udev/udev-rules.c index 4a5b8debca..221865c9dc 100644 --- a/udev/udev-rules.c +++ b/udev/udev-rules.c @@ -1803,7 +1803,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) add_matching_files(udev, &file_list, SYSCONFDIR "/udev/rules.d", ".rules"); /* read dynamic/temporary rules */ - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/rules.d", NULL); + util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/rules.d", NULL); udev_list_init(&sort_list); add_matching_files(udev, &sort_list, filename, ".rules"); diff --git a/udev/udev-watch.c b/udev/udev-watch.c index 47dca4c6e6..0ec8bfd627 100644 --- a/udev/udev-watch.c +++ b/udev/udev-watch.c @@ -54,8 +54,8 @@ void udev_watch_restore(struct udev *udev) if (inotify_fd < 0) return; - util_strscpyl(oldname, sizeof(oldname), udev_get_dev_path(udev), "/.run/udev/watch.old", NULL); - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/watch", NULL); + 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) { DIR *dir; struct dirent *ent; @@ -118,7 +118,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) return; } - snprintf(filename, sizeof(filename), "%s/.run/udev/watch/%d", udev_get_dev_path(udev), wd); + snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); util_create_path(udev, filename); unlink(filename); symlink(udev_device_get_id_filename(dev), filename); @@ -141,7 +141,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) info(udev, "removing watch on '%s'\n", udev_device_get_devnode(dev)); inotify_rm_watch(inotify_fd, wd); - snprintf(filename, sizeof(filename), "%s/.run/udev/watch/%d", udev_get_dev_path(udev), wd); + snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); unlink(filename); udev_device_set_watch_handle(dev, -1); @@ -158,7 +158,7 @@ struct udev_device *udev_watch_lookup(struct udev *udev, int wd) if (inotify_fd < 0 || wd < 0) return NULL; - snprintf(filename, sizeof(filename), "%s/.run/udev/watch/%d", udev_get_dev_path(udev), wd); + 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); diff --git a/udev/udev.xml b/udev/udev.xml index 452abc5c0d..deb3429698 100644 --- a/udev/udev.xml +++ b/udev/udev.xml @@ -73,7 +73,7 @@ <para>The udev rules are read from the files located in the default rules directory <filename>/lib/udev/rules.d/</filename>, the custom rules directory <filename>/etc/udev/rules.d/</filename> - and the temporary rules directory <filename>/var/run/udev/rules.d/</filename>. + and the temporary rules directory <filename>/run/udev/rules.d/</filename>. All rule files are sorted and processed in lexical order, regardless in which of these directories they live. Files in <filename>/etc/udev/rules.d/</filename> have precedence over files with diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c index 33d113c5b1..9357f67208 100644 --- a/udev/udevadm-info.c +++ b/udev/udevadm-info.c @@ -218,6 +218,7 @@ int udevadm_info(struct udev *udev, int argc, char *argv[]) { "attribute-walk", no_argument, NULL, 'a' }, { "export-db", no_argument, NULL, 'e' }, { "root", no_argument, NULL, 'r' }, + { "run", no_argument, NULL, 'R' }, { "device-id-of-file", required_argument, NULL, 'd' }, { "export", no_argument, NULL, 'x' }, { "export-prefix", required_argument, NULL, 'P' }, @@ -247,7 +248,7 @@ int udevadm_info(struct udev *udev, int argc, char *argv[]) int option; struct stat statbuf; - option = getopt_long(argc, argv, "aed:n:p:q:rxP:Vh", options, NULL); + option = getopt_long(argc, argv, "aed:n:p:q:rxP:RVh", options, NULL); if (option == -1) break; @@ -331,6 +332,9 @@ int udevadm_info(struct udev *udev, int argc, char *argv[]) action = ACTION_ROOT; root = true; break; + case 'R': + printf("%s\n", udev_get_run_path(udev)); + goto exit; case 'd': action = ACTION_DEVICE_ID_FILE; util_strscpy(name, sizeof(name), optarg); diff --git a/udev/udevadm.c b/udev/udevadm.c index 19b89ad05c..336d723705 100644 --- a/udev/udevadm.c +++ b/udev/udevadm.c @@ -171,6 +171,8 @@ int main(int argc, char *argv[]) } command = argv[optind]; + info(udev, "runtime dir '%s'\n", udev_get_run_path(udev)); + if (command != NULL) for (i = 0; cmds[i].cmd != NULL; i++) { if (strcmp(cmds[i].name, command) == 0) { diff --git a/udev/udevadm.xml b/udev/udevadm.xml index cefd7763af..be8f886fc8 100644 --- a/udev/udevadm.xml +++ b/udev/udevadm.xml @@ -111,6 +111,12 @@ </listitem> </varlistentry> <varlistentry> + <term><option>--run</option></term> + <listitem> + <para>The udev runtime directory: <filename>/run/udev</filename>.</para> + </listitem> + </varlistentry> + <varlistentry> <term><option>--attribute-walk</option></term> <listitem> <para>Print all sysfs properties of the specified device that can be used diff --git a/udev/udevd.c b/udev/udevd.c index 03cd2cbcee..ef82f72d05 100644 --- a/udev/udevd.c +++ b/udev/udevd.c @@ -979,13 +979,15 @@ static int convert_db(struct udev *udev) struct udev_list_entry *list_entry; /* current database */ - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/db3", NULL); + util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL); if (access(filename, F_OK) >= 0) return 0; /* make sure we do not get here again */ - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/db3/", NULL); util_create_path(udev, filename); + udev_selinux_setfscreatecon(udev, udev_get_run_path(udev), S_IFDIR|0755); + mkdir(filename, 0755); + udev_selinux_resetfscreatecon(udev); /* old database */ util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db", NULL); @@ -1044,8 +1046,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), udev_get_dev_path(udev), "/.udev/db/", devpath, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -1093,6 +1094,27 @@ int main(int argc, char *argv[]) info(udev, "version %s\n", VERSION); udev_selinux_init(udev); + /* make sure, that our runtime dir exists and is writable */ + if (utimensat(AT_FDCWD, udev_get_run_config_path(udev), NULL, 0) < 0) { + /* try to create our own subdirectory, do not create parent directories */ + udev_selinux_setfscreatecon(udev, udev_get_run_config_path(udev), S_IFDIR|0755); + mkdir(udev_get_run_config_path(udev), 0755); + udev_selinux_resetfscreatecon(udev); + + if (utimensat(AT_FDCWD, udev_get_run_config_path(udev), NULL, 0) >= 0) { + /* directory seems writable now */ + udev_set_run_path(udev, udev_get_run_config_path(udev)); + } else { + /* fall back to /dev/.udev */ + char filename[UTIL_PATH_SIZE]; + + util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev", NULL); + if (udev_set_run_path(udev, filename) == NULL) + goto exit; + } + } + info(udev, "runtime dir '%s'\n", udev_get_run_path(udev)); + for (;;) { int option; @@ -1252,7 +1274,7 @@ int main(int argc, char *argv[]) IN_DELETE | IN_MOVE | IN_CLOSE_WRITE); /* watch dynamic rules directory */ - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/rules.d", NULL); + util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/rules.d", NULL); if (stat(filename, &statbuf) != 0) { util_create_path(udev, filename); udev_selinux_setfscreatecon(udev, filename, S_IFDIR|0755); |