diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2009-08-19 20:49:49 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2009-08-19 20:49:49 +0200 |
commit | 2ffc9cc1917b1bb6fe86881a94a47dce9aa15168 (patch) | |
tree | 842ba77f43018179ce42e5433ce1c6cd63559c60 /libudev | |
parent | 24d1fea8bd609f9eb7901efd7cba7f2dee05f557 (diff) |
change database file names
With very deeply nested devices, We can not use a single file
name to carry an entire DEVPATH. Use <subsystem>:<sysname> as
the database filename, which should also simplify the handling
of devices moving around, as these values will not change but
still be unique.
For the name stack we use the <maj>:<min> now as the filename.
> On Tue, Aug 18, 2009 at 09:59:56AM -0400, Ric Wheeler wrote:
> The first is that udev grumbles during boot about "file name too long"
> like the following:
>
> Aug 17 06:49:58 megadeth udevd-event[20447]: unable to create db file
> '/dev/.udev/db/\x2fdevices\x2fpci0000:00\x2f0000:00:04.0\x2f0000:17:00.0\x2f0000:18:0a.0\x2f0000:1f:00.0\x2fhost11\x2fport-11:0\x2fexpander-11:0\x2fport-11:0:0\x2fexpander-11:1\x2fport-11:1:0\x2fexpander-11:2\x2fport-11:2:17\x2fexpander-11:3\x2fport-11:3:1\x2fend_device-11:3:1\x2fbsg\x2fend_device-11:3:1':
> File name too long
Diffstat (limited to 'libudev')
-rw-r--r-- | libudev/libudev-device-private.c | 27 | ||||
-rw-r--r-- | libudev/libudev-device.c | 40 | ||||
-rw-r--r-- | libudev/libudev-private.h | 5 | ||||
-rw-r--r-- | libudev/libudev-queue-private.c | 16 |
4 files changed, 49 insertions, 39 deletions
diff --git a/libudev/libudev-device-private.c b/libudev/libudev-device-private.c index 68dc0a5b98..80a4da4c96 100644 --- a/libudev/libudev-device-private.c +++ b/libudev/libudev-device-private.c @@ -21,16 +21,6 @@ #include "libudev.h" #include "libudev-private.h" -static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len) -{ - char *s; - size_t l; - - s = filename; - l = util_strpcpyl(&s, len, udev_get_dev_path(udev), "/.udev/db/", NULL); - return util_path_encode(devpath, s, l); -} - int udev_device_update_db(struct udev_device *udev_device) { struct udev *udev = udev_device_get_udev(udev_device); @@ -43,8 +33,8 @@ int udev_device_update_db(struct udev_device *udev_device) struct udev_list_entry *list_entry; int ret; - devpath_to_db_path(udev, udev_device_get_devpath(udev_device), filename, sizeof(filename)); - util_create_path(udev, filename); + util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db/", + udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname(udev_device), NULL); unlink(filename); udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) @@ -78,11 +68,13 @@ int udev_device_update_db(struct udev_device *udev_device) } info(udev, "create db link (%s)\n", target); udev_selinux_setfscreatecon(udev, filename, S_IFLNK); + util_create_path(udev, filename); ret = symlink(target, filename); udev_selinux_resetfscreatecon(udev); if (ret == 0) goto out; file: + util_create_path(udev, filename); f = fopen(filename, "w"); if (f == NULL) { err(udev, "unable to create db file '%s': %m\n", filename); @@ -122,18 +114,21 @@ int udev_device_delete_db(struct udev_device *udev_device) struct udev *udev = udev_device_get_udev(udev_device); char filename[UTIL_PATH_SIZE]; - devpath_to_db_path(udev, udev_device_get_devpath(udev_device), filename, sizeof(filename)); + util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db/", + udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname(udev_device), NULL); unlink(filename); return 0; } -int udev_device_rename_db(struct udev_device *udev_device, const char *devpath_old) +int udev_device_rename_db(struct udev_device *udev_device) { struct udev *udev = udev_device_get_udev(udev_device); char filename_old[UTIL_PATH_SIZE]; char filename[UTIL_PATH_SIZE]; - devpath_to_db_path(udev, devpath_old, filename_old, sizeof(filename_old)); - devpath_to_db_path(udev, udev_device_get_devpath(udev_device), filename, sizeof(filename)); + util_strscpyl(filename_old, sizeof(filename_old), udev_get_dev_path(udev), "/.udev/db/", + udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname_old(udev_device), NULL); + util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db/", + udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname(udev_device), NULL); return rename(filename_old, filename); } diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c index eac6bd6041..22d8349275 100644 --- a/libudev/libudev-device.c +++ b/libudev/libudev-device.c @@ -51,6 +51,7 @@ struct udev_device { char *driver; char *action; char *devpath_old; + char *sysname_old; char *knodename; char **envp; char *monitor_buf; @@ -76,16 +77,6 @@ struct udev_device { unsigned int ignore_remove:1; }; -static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len) -{ - char *s; - size_t l; - - s = filename; - l = util_strpcpyl(&s, len, udev_get_dev_path(udev), "/.udev/db/", NULL); - return util_path_encode(devpath, s, l); -} - int udev_device_read_db(struct udev_device *udev_device) { struct stat stats; @@ -93,7 +84,8 @@ int udev_device_read_db(struct udev_device *udev_device) char line[UTIL_LINE_SIZE]; FILE *f; - devpath_to_db_path(udev_device->udev, udev_device->devpath, filename, sizeof(filename)); + util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/.udev/db/", + udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname(udev_device), NULL); if (lstat(filename, &stats) != 0) { dbg(udev_device->udev, "no db file to read %s: %m\n", filename); @@ -677,6 +669,7 @@ void udev_device_unref(struct udev_device *udev_device) free(udev_device->action); free(udev_device->driver); free(udev_device->devpath_old); + free(udev_device->sysname_old); free(udev_device->knodename); udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_list); free(udev_device->envp); @@ -1282,14 +1275,39 @@ const char *udev_device_get_devpath_old(struct udev_device *udev_device) int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old) { + const char *pos; + size_t len; + free(udev_device->devpath_old); udev_device->devpath_old = strdup(devpath_old); if (udev_device->devpath_old == NULL) return -ENOMEM; udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old); + + pos = strrchr(udev_device->devpath_old, '/'); + if (pos == NULL) + return -EINVAL; + udev_device->sysname_old = strdup(&pos[1]); + if (udev_device->sysname_old == NULL) + return -ENOMEM; + + /* some devices have '!' in their name, change that to '/' */ + len = 0; + while (udev_device->sysname_old[len] != '\0') { + if (udev_device->sysname_old[len] == '!') + udev_device->sysname_old[len] = '/'; + len++; + } return 0; } +const char *udev_device_get_sysname_old(struct udev_device *udev_device) +{ + if (udev_device == NULL) + return NULL; + return udev_device->sysname_old; +} + const char *udev_device_get_knodename(struct udev_device *udev_device) { return udev_device->knodename; diff --git a/libudev/libudev-private.h b/libudev/libudev-private.h index 16f9f2e1c1..b735298c67 100644 --- a/libudev/libudev-private.h +++ b/libudev/libudev-private.h @@ -79,6 +79,7 @@ int udev_device_read_uevent_file(struct udev_device *udev_device); int udev_device_set_action(struct udev_device *udev_device, const char *action); int udev_device_set_driver(struct udev_device *udev_device, const char *driver); const char *udev_device_get_devpath_old(struct udev_device *udev_device); +const char *udev_device_get_sysname_old(struct udev_device *udev_device); int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old); const char *udev_device_get_knodename(struct udev_device *udev_device); int udev_device_set_knodename(struct udev_device *udev_device, const char *knodename); @@ -101,7 +102,7 @@ void udev_device_set_info_loaded(struct udev_device *device); /* libudev-device-private.c */ int udev_device_update_db(struct udev_device *udev_device); int udev_device_delete_db(struct udev_device *udev_device); -int udev_device_rename_db(struct udev_device *udev_device, const char *devpath); +int udev_device_rename_db(struct udev_device *udev_device); /* libudev-monitor.c - netlink/unix socket communication */ int udev_monitor_disconnect(struct udev_monitor *udev_monitor); @@ -186,8 +187,8 @@ int udev_queue_export_device_failed(struct udev_queue_export *udev_queue_export, /* libudev-util.c */ #define UTIL_PATH_SIZE 1024 -#define UTIL_LINE_SIZE 2048 #define UTIL_NAME_SIZE 512 +#define UTIL_LINE_SIZE 2048 #define UDEV_ALLOWED_CHARS_INPUT "/ $%?," ssize_t util_get_sys_subsystem(struct udev *udev, const char *syspath, char *subsystem, size_t size); ssize_t util_get_sys_driver(struct udev *udev, const char *syspath, char *driver, size_t size); diff --git a/libudev/libudev-queue-private.c b/libudev/libudev-queue-private.c index 4dea4ad0e7..e0a8738e0e 100644 --- a/libudev/libudev-queue-private.c +++ b/libudev/libudev-queue-private.c @@ -396,16 +396,13 @@ static void update_failed(struct udev_queue_export *udev_queue_export, { struct udev *udev = udev_device_get_udev(udev_device); char filename[UTIL_PATH_SIZE]; - char *s; - size_t l; if (state != DEVICE_FAILED && udev_queue_export->failed_count == 0) return; /* location of failed file */ - s = filename; - l = util_strpcpyl(&s, sizeof(filename), udev_get_dev_path(udev_queue_export->udev), "/.udev/failed/", NULL); - util_path_encode(udev_device_get_devpath(udev_device), s, l); + util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/failed/", + udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname(udev_device), NULL); switch (state) { case DEVICE_FAILED: @@ -428,14 +425,13 @@ static void update_failed(struct udev_queue_export *udev_queue_export, break; case DEVICE_FINISHED: - if (udev_device_get_devpath_old(udev_device) != NULL) { + if (udev_device_get_sysname_old(udev_device) != NULL && + strcmp(udev_device_get_sysname_old(udev_device), udev_device_get_sysname(udev_device)) != 0) { /* "move" event - rename failed file to current name, do not delete failed */ char filename_old[UTIL_PATH_SIZE]; - s = filename_old; - l = util_strpcpyl(&s, sizeof(filename_old), udev_get_dev_path(udev_queue_export->udev), "/.udev/failed/", NULL); - util_path_encode(udev_device_get_devpath_old(udev_device), s, l); - + util_strscpyl(filename_old, sizeof(filename_old), udev_get_dev_path(udev), "/.udev/failed/", + udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname_old(udev_device), NULL); if (rename(filename_old, filename) == 0) info(udev, "renamed devpath, moved failed state of '%s' to %s'\n", udev_device_get_devpath_old(udev_device), udev_device_get_devpath(udev_device)); |