summaryrefslogtreecommitdiff
path: root/src/udev/udev-watch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udev/udev-watch.c')
-rw-r--r--src/udev/udev-watch.c46
1 files changed, 17 insertions, 29 deletions
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);
}