From fc6da921ad3bcb251aa317376e81701700e925c9 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 16 Mar 2007 03:09:02 +0100 Subject: store devpath with the usual leading slash --- udev_db.c | 25 +++++++++---------------- udevd.c | 8 ++++---- udevtrigger.c | 3 +-- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/udev_db.c b/udev_db.c index c07588db24..13d96894af 100644 --- a/udev_db.c +++ b/udev_db.c @@ -39,19 +39,11 @@ static size_t devpath_to_db_path(const char *devpath, char *filename, size_t len /* add location of db files */ strlcpy(filename, udev_root, len); - start = strlcat(filename, "/"DB_DIR, len); + start = strlcat(filename, "/"DB_DIR"/", len); strlcat(filename, devpath, len); - return path_encode(&filename[start+1], len - (start+1)); + return path_encode(&filename[start], len - start); } -static size_t db_file_to_devpath(const char *filename, char *devpath, size_t len) -{ - strlcpy(devpath, "/", len); - strlcat(devpath, filename, len); - return path_decode(devpath); -} - - /* reverse mapping from the device file name to the devpath */ static int name_index(const char *devpath, const char *name, int add) { @@ -64,10 +56,11 @@ static int name_index(const char *devpath, const char *name, int add) strlcpy(filename, udev_root, sizeof(filename)); start = strlcat(filename, "/"DB_NAME_INDEX_DIR"/", sizeof(filename)); strlcat(filename, name, sizeof(filename)); - path_encode(&filename[start+1], sizeof(filename) - (start+1)); + path_encode(&filename[start], sizeof(filename) - start); /* entry with the devpath */ strlcpy(device, devpath, sizeof(device)); - path_encode(&device[1], sizeof(device)-1); + path_encode(device, sizeof(device)); + strlcat(filename, "/", sizeof(filename)); strlcat(filename, device, sizeof(filename)); if (add) { @@ -261,7 +254,7 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len) strlcpy(dirname, udev_root, sizeof(dirname)); start = strlcat(dirname, "/"DB_NAME_INDEX_DIR"/", sizeof(dirname)); strlcat(dirname, name, sizeof(dirname)); - path_encode(&dirname[start+1], sizeof(dirname) - (start+1)); + path_encode(&dirname[start], sizeof(dirname) - start); dir = opendir(dirname); if (dir == NULL) { @@ -282,8 +275,7 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len) if (ent->d_name[0] == '.') continue; - strlcpy(device, "/", len); - strlcat(device, ent->d_name, sizeof(device)); + strlcpy(device, ent->d_name, sizeof(device)); path_decode(device); dbg("looking at '%s'", device); @@ -326,7 +318,8 @@ int udev_db_get_all_entries(struct list_head *name_list) if (ent->d_name[0] == '.') continue; - db_file_to_devpath(ent->d_name, device, sizeof(device)); + strlcpy(device, ent->d_name, sizeof(device)); + path_decode(device); name_list_add(name_list, device, 1); dbg("added '%s'", device); } diff --git a/udevd.c b/udevd.c index efb24ff651..2c92590dcd 100644 --- a/udevd.c +++ b/udevd.c @@ -174,16 +174,16 @@ static void export_event_state(struct udevd_uevent_msg *msg, enum event_state st /* add location of queue files */ strlcpy(filename, udev_root, sizeof(filename)); strlcat(filename, "/", sizeof(filename)); - start = strlcat(filename, EVENT_QUEUE_DIR, sizeof(filename)); + start = strlcat(filename, EVENT_QUEUE_DIR"/", sizeof(filename)); strlcat(filename, msg->devpath, sizeof(filename)); - path_encode(&filename[start+1], sizeof(filename) - (start+1)); + path_encode(&filename[start], sizeof(filename) - start); /* add location of failed files */ strlcpy(filename_failed, udev_root, sizeof(filename_failed)); strlcat(filename_failed, "/", sizeof(filename_failed)); - start = strlcat(filename_failed, EVENT_FAILED_DIR, sizeof(filename_failed)); + start = strlcat(filename_failed, EVENT_FAILED_DIR"/", sizeof(filename_failed)); strlcat(filename_failed, msg->devpath, sizeof(filename_failed)); - path_encode(&filename_failed[start+1], sizeof(filename) - (start+1)); + path_encode(&filename_failed[start], sizeof(filename) - start); switch (state) { case EVENT_QUEUED: diff --git a/udevtrigger.c b/udevtrigger.c index 2bdd0c8d07..7577c5f15f 100644 --- a/udevtrigger.c +++ b/udevtrigger.c @@ -412,8 +412,7 @@ static void scan_failed(void) if (dent->d_name[0] == '.') continue; - strlcpy(device, sysfs_path, sizeof(device)); - start = strlcat(device, "/", sizeof(device)); + start = strlcpy(device, sysfs_path, sizeof(device)); strlcat(device, dent->d_name, sizeof(device)); path_decode(&device[start]); device_list_insert(device); -- cgit v1.2.3-54-g00ecf