diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2010-12-11 14:00:46 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2010-12-11 14:00:46 +0100 |
commit | 24d1076696ebe6696a8b8df414ab265aa6fc89c2 (patch) | |
tree | 6b988e0ea24457f1d3256fca64ced4da792f8b03 /udev | |
parent | 2713e6ab0abfc47a54ccbae26be22471aef46b24 (diff) |
udevd: simplify udev database and fix DEVNAME handling
Diffstat (limited to 'udev')
-rw-r--r-- | udev/udev-node.c | 2 | ||||
-rw-r--r-- | udev/udevadm-info.c | 34 |
2 files changed, 21 insertions, 15 deletions
diff --git a/udev/udev-node.c b/udev/udev-node.c index 70488c420b..a9ffa988b1 100644 --- a/udev/udev-node.c +++ b/udev/udev-node.c @@ -327,7 +327,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) err = util_create_path(udev, filename); if (err != 0 && err != -ENOENT) break; - fd = open(filename, O_WRONLY|O_CREAT|O_NOFOLLOW, 0444); + fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444); if (fd >= 0) close(fd); else diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c index 7206f4fcf6..4510f4aa90 100644 --- a/udev/udevadm-info.c +++ b/udev/udevadm-info.c @@ -210,38 +210,44 @@ static int convert_db(struct udev *udev) device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry)); if (device != NULL) { const char *id; - struct stat statbuf; + struct stat stats; char to[UTIL_PATH_SIZE]; char devpath[UTIL_PATH_SIZE]; char from[UTIL_PATH_SIZE]; id = udev_device_get_id_filename(device); - if (id == NULL) - goto next; + if (id == NULL) { + udev_device_unref(device); + continue; + } util_strscpyl(to, sizeof(to), udev_get_dev_path(udev), "/.udev/db/", id, NULL); - /* do not overwrite a new database file */ - if (lstat(to, &statbuf) == 0) - goto next; - /* find old database with $subsys:$sysname */ util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL); - if (lstat(from, &statbuf) == 0) { - rename(from, to); - goto next; + if (lstat(from, &stats) == 0) { + if (lstat(to, &stats) == 0) + unlink(from); + else + rename(from, to); } /* find old database with the encoded devpath */ 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); - if (lstat(from, &statbuf) == 0) { - rename(from, to); - goto next; + if (lstat(from, &stats) == 0) { + if (lstat(to, &stats) == 0) + unlink(from); + else + rename(from, to); } -next: + + /* read the old database, and write out a new one */ + udev_device_read_db(device); + udev_device_update_db(device); + udev_device_unref(device); } } |