summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2009-05-20 18:58:52 +0200
committerKay Sievers <kay.sievers@vrfy.org>2009-05-20 18:58:52 +0200
commite6c1a2bde7609cc703a5fad34c3bc1d15d19bbdc (patch)
treef3a7af4b7a2539833db52afff062afc81e504e8a
parenteba87f55f6383cd61a11fce2ae37ac8100d6ded2 (diff)
use openat(), unlinkat(), fstatat()
-rw-r--r--TODO1
-rw-r--r--udev/lib/libudev-queue.c7
-rw-r--r--udev/udev-rules.c6
-rw-r--r--udev/udev-watch.c20
-rw-r--r--udev/udevadm-info.c5
-rw-r--r--udev/udevd.c3
6 files changed, 16 insertions, 26 deletions
diff --git a/TODO b/TODO
index 541faea556..161df02f05 100644
--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@
o drop modprobe floppy alias (SUSE), it will be in the module (2.6.30)
o remove MMC rules, they got a modalias now (2.6.30)
o add scsi:t-0x09* to "ch" and remove modprobe rule (2.6.30)
- o convert readdir loops to unlinkat(), fstatat()
o implement path_id in C with libudev (?)
o convert firmware.sh to C (?)
diff --git a/udev/lib/libudev-queue.c b/udev/lib/libudev-queue.c
index a2860ec8c2..8dce6c314d 100644
--- a/udev/lib/libudev-queue.c
+++ b/udev/lib/libudev-queue.c
@@ -201,7 +201,6 @@ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev
if (dir == NULL)
return NULL;
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char filename[UTIL_PATH_SIZE];
char syspath[UTIL_PATH_SIZE];
char *s;
size_t l;
@@ -209,10 +208,9 @@ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev
if (dent->d_name[0] == '.')
continue;
- util_strscpyl(filename, sizeof(filename), path, "/", dent->d_name, NULL);
s = syspath;
l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL);
- len = readlink(filename, s, l);
+ len = readlinkat(dirfd(dir), dent->d_name, s, l);
if (len < 0 || (size_t)len >= l)
continue;
s[len] = '\0';
@@ -246,10 +244,9 @@ struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev
if (dent->d_name[0] == '.')
continue;
- util_strscpyl(filename, sizeof(filename), path, "/", dent->d_name, NULL);
s = syspath;
l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL);
- len = readlink(filename, s, l);
+ len = readlinkat(dirfd(dir), dent->d_name, s, l);
if (len < 0 || (size_t)len >= l)
continue;
s[len] = '\0';
diff --git a/udev/udev-rules.c b/udev/udev-rules.c
index da1d322037..6d03ab63c0 100644
--- a/udev/udev-rules.c
+++ b/udev/udev-rules.c
@@ -1641,10 +1641,8 @@ static int add_matching_files(struct udev *udev, struct udev_list_node *file_lis
if (strcmp(ext, suffix) != 0)
continue;
}
- dbg(udev, "put file '%s/%s' into list\n", dirname, dent->d_name);
-
- snprintf(filename, sizeof(filename), "%s/%s", dirname, dent->d_name);
- filename[sizeof(filename)-1] = '\0';
+ util_strscpyl(filename, sizeof(filename), dirname, "/", dent->d_name, NULL);
+ dbg(udev, "put file '%s' into list\n", filename);
udev_list_entry_add(udev, file_list, filename, NULL, 1, 1);
}
diff --git a/udev/udev-watch.c b/udev/udev-watch.c
index 8bc8775735..53492e5f35 100644
--- a/udev/udev-watch.c
+++ b/udev/udev-watch.c
@@ -72,8 +72,7 @@ void udev_watch_restore(struct udev *udev)
}
for (ent = readdir(dir); ent != NULL; ent = readdir(dir)) {
- char path[UTIL_PATH_SIZE];
- char buf[UTIL_PATH_SIZE];
+ char device[UTIL_PATH_SIZE];
char *s;
size_t l;
ssize_t len;
@@ -82,19 +81,18 @@ void udev_watch_restore(struct udev *udev)
if (ent->d_name[0] < '0' || ent->d_name[0] > '9')
continue;
- util_strscpyl(path, sizeof(path), oldname, "/", ent->d_name, NULL);
- s = buf;
- l = util_strpcpy(&s, sizeof(buf), udev_get_sys_path(udev));
- len = readlink(path, s, l);
+ 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) {
- unlink(path);
+ unlinkat(dirfd(dir), ent->d_name, 0);
continue;
}
s[len] = '\0';
- dbg(udev, "old watch to '%s' found\n", buf);
- dev = udev_device_new_from_syspath(udev, buf);
+ dbg(udev, "old watch to '%s' found\n", device);
+ dev = udev_device_new_from_syspath(udev, device);
if (dev == NULL) {
- unlink(path);
+ unlinkat(dirfd(dir), ent->d_name, 0);
continue;
}
@@ -102,7 +100,7 @@ void udev_watch_restore(struct udev *udev)
udev_watch_begin(udev, dev);
udev_device_unref(dev);
- unlink(path);
+ unlinkat(dirfd(dir), ent->d_name, 0);
}
closedir(dir);
diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c
index db11a289b2..b743a1d642 100644
--- a/udev/udevadm-info.c
+++ b/udev/udevadm-info.c
@@ -25,6 +25,7 @@
#include <dirent.h>
#include <errno.h>
#include <getopt.h>
+#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -40,7 +41,6 @@ static void print_all_attributes(struct udev_device *device, const char *key)
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
struct stat statbuf;
- char filename[UTIL_PATH_SIZE];
const char *value;
size_t len;
@@ -52,8 +52,7 @@ static void print_all_attributes(struct udev_device *device, const char *key)
if (strcmp(dent->d_name, "dev") == 0)
continue;
- util_strscpyl(filename, sizeof(filename), udev_device_get_syspath(device), "/", dent->d_name, NULL);
- if (lstat(filename, &statbuf) != 0)
+ if (fstatat(dirfd(dir), dent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0)
continue;
if (S_ISLNK(statbuf.st_mode))
continue;
diff --git a/udev/udevd.c b/udev/udevd.c
index 1fe76f8829..b64f08b5c5 100644
--- a/udev/udevd.c
+++ b/udev/udevd.c
@@ -649,8 +649,7 @@ static void cleanup_queue_dir(struct udev *udev)
break;
if (dent->d_name[0] == '.')
continue;
- util_strscpyl(filename, sizeof(filename), dirname, "/", dent->d_name, NULL);
- unlink(filename);
+ unlinkat(dirfd(dir), dent->d_name, 0);
}
closedir(dir);
rmdir(dirname);