X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_db.c;h=e2b7b4d9214e6a40b53f27eca451b41e71e56ea0;hp=bf369ac2e66c54b249afeeb35d6fa450c477de77;hb=e0dc4f00baaa4ad328aa13362fcf25e7ec2ae2f6;hpb=7104c558dad47ee85860ebb891bdc8820d95154d diff --git a/udev_db.c b/udev_db.c index bf369ac2e..e2b7b4d92 100644 --- a/udev_db.c +++ b/udev_db.c @@ -35,16 +35,16 @@ #include "udev.h" #include "udev_utils.h" #include "logging.h" -#include "udev_db.h" -#define PATH_TO_NAME_CHAR '@' static int devpath_to_db_path(const char *devpath, char *filename, size_t len) { size_t start, end, i; /* add location of db files */ - start = strlcpy(filename, udev_db_path, len); + strlcpy(filename, udev_root, len); + strlcat(filename, "/", len); + start = strlcat(filename, DB_DIR, len); end = strlcat(filename, devpath, len); if (end > len) end = len; @@ -95,7 +95,7 @@ int udev_db_add_device(struct udevice *udev) create_path(filename); f = fopen(filename, "w"); if (f == NULL) { - err("unable to create db file '%s'", filename); + err("unable to create db file '%s': %s", filename, strerror(errno)); return -1; } dbg("storing data for device '%s' in '%s'", udev->devpath, filename); @@ -129,7 +129,7 @@ int udev_db_get_device(struct udevice *udev, const char *devpath) devpath_to_db_path(devpath, filename, sizeof(filename)); if (file_map(filename, &buf, &bufsize) != 0) { - dbg("no db file to read '%s'", filename); + info("no db file to read %s: %s", filename, strerror(errno)); return -1; } @@ -205,12 +205,16 @@ int udev_db_delete_device(struct udevice *udev) int udev_db_lookup_name(const char *name, char *devpath, size_t len) { + char dbpath[PATH_MAX]; DIR *dir; int found = 0; - dir = opendir(udev_db_path); + strlcpy(dbpath, udev_root, sizeof(dbpath)); + strlcat(dbpath, "/", sizeof(dbpath)); + strlcat(dbpath, DB_DIR, sizeof(dbpath)); + dir = opendir(dbpath); if (dir == NULL) { - err("unable to open udev_db '%s'", udev_db_path); + err("unable to open udev_db '%s': %s", dbpath, strerror(errno)); return -1; } @@ -230,12 +234,12 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len) if (ent->d_name[0] == '.') continue; - snprintf(filename, sizeof(filename), "%s/%s", udev_db_path, ent->d_name); + snprintf(filename, sizeof(filename), "%s/%s", dbpath, ent->d_name); filename[sizeof(filename)-1] = '\0'; dbg("looking at '%s'", filename); if (file_map(filename, &buf, &bufsize) != 0) { - err("unable to read db file '%s'", filename); + err("unable to read db file '%s': %s", filename, strerror(errno)); continue; } @@ -274,11 +278,15 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len) int udev_db_get_all_entries(struct list_head *name_list) { + char dbpath[PATH_MAX]; DIR *dir; - dir = opendir(udev_db_path); + strlcpy(dbpath, udev_root, sizeof(dbpath)); + strlcat(dbpath, "/", sizeof(dbpath)); + strlcat(dbpath, DB_DIR, sizeof(dbpath)); + dir = opendir(dbpath); if (dir == NULL) { - err("unable to open udev_db '%s'", udev_db_path); + err("unable to open udev_db '%s': %s", dbpath, strerror(errno)); return -1; }