summaryrefslogtreecommitdiff
path: root/libudev
diff options
context:
space:
mode:
Diffstat (limited to 'libudev')
-rw-r--r--libudev/libudev-device-private.c6
-rw-r--r--libudev/libudev-device.c2
-rw-r--r--libudev/libudev-enumerate.c2
-rw-r--r--libudev/libudev-private.h3
-rw-r--r--libudev/libudev-queue-private.c10
-rw-r--r--libudev/libudev-queue.c4
-rw-r--r--libudev/libudev.c120
7 files changed, 101 insertions, 46 deletions
diff --git a/libudev/libudev-device-private.c b/libudev/libudev-device-private.c
index 7683f09857..6d72d328bd 100644
--- a/libudev/libudev-device-private.c
+++ b/libudev/libudev-device-private.c
@@ -31,7 +31,7 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add)
id = udev_device_get_id_filename(dev);
if (id == NULL)
return;
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/tags/", tag, "/", id, NULL);
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags/", tag, "/", id, NULL);
if (add) {
int fd;
@@ -115,7 +115,7 @@ int udev_device_update_db(struct udev_device *udev_device)
return -1;
has_info = device_has_info(udev_device);
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/db3/", id, NULL);
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL);
/* do not store anything for otherwise empty devices */
if (!has_info &&
@@ -176,7 +176,7 @@ int udev_device_delete_db(struct udev_device *udev_device)
id = udev_device_get_id_filename(udev_device);
if (id == NULL)
return -1;
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/db3/", id, NULL);
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL);
unlink(filename);
return 0;
}
diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c
index dd0224ae4b..ccd4a70677 100644
--- a/libudev/libudev-device.c
+++ b/libudev/libudev-device.c
@@ -254,7 +254,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile)
id = udev_device_get_id_filename(udev_device);
if (id == NULL)
return -1;
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/.run/udev/db3/", id, NULL);
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_device->udev), "/data/", id, NULL);
dbfile = filename;
}
diff --git a/libudev/libudev-enumerate.c b/libudev/libudev-enumerate.c
index d3dd5c963f..6870bb6115 100644
--- a/libudev/libudev-enumerate.c
+++ b/libudev/libudev-enumerate.c
@@ -751,7 +751,7 @@ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
struct dirent *dent;
char path[UTIL_PATH_SIZE];
- util_strscpyl(path, sizeof(path), udev_get_dev_path(udev), "/.run/udev/tags/",
+ util_strscpyl(path, sizeof(path), udev_get_run_path(udev), "/tags/",
udev_list_entry_get_name(list_entry), NULL);
dir = opendir(path);
if (dir == NULL)
diff --git a/libudev/libudev-private.h b/libudev/libudev-private.h
index 0fe6f4a6bf..bd317933ba 100644
--- a/libudev/libudev-private.h
+++ b/libudev/libudev-private.h
@@ -61,6 +61,9 @@ void udev_log(struct udev *udev,
const char *format, ...)
__attribute__((format(printf, 6, 7)));
const char *udev_get_rules_path(struct udev *udev);
+const char *udev_get_run_config_path(struct udev *udev);
+const char *udev_get_run_path(struct udev *udev);
+const char *udev_set_run_path(struct udev *udev, const char *path);
struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value);
struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev);
diff --git a/libudev/libudev-queue-private.c b/libudev/libudev-queue-private.c
index 9b02daf0a4..a714572361 100644
--- a/libudev/libudev-queue-private.c
+++ b/libudev/libudev-queue-private.c
@@ -103,10 +103,10 @@ void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export)
{
char filename[UTIL_PATH_SIZE];
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_queue_export->udev), "/.run/udev/queue.tmp", NULL);
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL);
unlink(filename);
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_queue_export->udev), "/.run/udev/queue.bin", NULL);
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL);
unlink(filename);
}
@@ -221,7 +221,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export)
}
/* create new queue file */
- util_strscpyl(filename_tmp, sizeof(filename_tmp), udev_get_dev_path(udev_queue_export->udev), "/.run/udev/queue.tmp", NULL);
+ util_strscpyl(filename_tmp, sizeof(filename_tmp), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL);
new_queue_file = fopen(filename_tmp, "w+");
if (new_queue_file == NULL)
goto error;
@@ -255,7 +255,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export)
goto error;
/* rename the new file on top of the old one */
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_queue_export->udev), "/.run/udev/queue.bin", NULL);
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL);
if (rename(filename_tmp, filename) != 0)
goto error;
@@ -401,7 +401,7 @@ static void update_failed(struct udev_queue_export *udev_queue_export,
return;
/* location of failed file */
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.run/udev/failed/",
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/failed/",
udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname(udev_device), NULL);
switch (state) {
diff --git a/libudev/libudev-queue.c b/libudev/libudev-queue.c
index 6f743d2061..75c5b2425e 100644
--- a/libudev/libudev-queue.c
+++ b/libudev/libudev-queue.c
@@ -214,7 +214,7 @@ static FILE *open_queue_file(struct udev_queue *udev_queue, unsigned long long i
char filename[UTIL_PATH_SIZE];
FILE *queue_file;
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_queue->udev), "/.run/udev/queue.bin", NULL);
+ util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue->udev), "/queue.bin", NULL);
queue_file = fopen(filename, "re");
if (queue_file == NULL)
return NULL;
@@ -484,7 +484,7 @@ struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev
if (udev_queue == NULL)
return NULL;
udev_list_cleanup_entries(udev_queue->udev, &udev_queue->failed_list);
- util_strscpyl(path, sizeof(path), udev_get_dev_path(udev_queue->udev), "/.run/udev/failed", NULL);
+ util_strscpyl(path, sizeof(path), udev_get_run_path(udev_queue->udev), "/failed", NULL);
dir = opendir(path);
if (dir == NULL)
return NULL;
diff --git a/libudev/libudev.c b/libudev/libudev.c
index cd418709f0..d96934fba8 100644
--- a/libudev/libudev.c
+++ b/libudev/libudev.c
@@ -43,6 +43,8 @@ struct udev {
char *sys_path;
char *dev_path;
char *rules_path;
+ char *run_config_path;
+ char *run_path;
struct udev_list_node properties_list;
int log_priority;
};
@@ -96,6 +98,14 @@ void udev_set_userdata(struct udev *udev, void *userdata)
udev->userdata = userdata;
}
+static char *set_value(char **s, const char *v)
+{
+ free(*s);
+ *s = strdup(v);
+ util_remove_trailing_chars(*s, '/');
+ return *s;
+}
+
/**
* udev_new:
*
@@ -111,7 +121,7 @@ struct udev *udev_new(void)
{
struct udev *udev;
const char *env;
- char *config_file;
+ char *config_file = NULL;
FILE *f;
udev = calloc(1, sizeof(struct udev));
@@ -121,31 +131,21 @@ struct udev *udev_new(void)
udev->log_fn = log_stderr;
udev->log_priority = LOG_ERR;
udev_list_init(&udev->properties_list);
- udev->dev_path = strdup("/dev");
- udev->sys_path = strdup("/sys");
- config_file = strdup(SYSCONFDIR "/udev/udev.conf");
- if (udev->dev_path == NULL ||
- udev->sys_path == NULL ||
- config_file == NULL)
- goto err;
-
- /* settings by environment and config file */
- env = getenv("SYSFS_PATH");
- if (env != NULL) {
- free(udev->sys_path);
- udev->sys_path = strdup(env);
- util_remove_trailing_chars(udev->sys_path, '/');
- udev_add_property(udev, "SYSFS_PATH", udev->sys_path);
- }
+ /* custom config file */
env = getenv("UDEV_CONFIG_FILE");
if (env != NULL) {
- free(config_file);
- config_file = strdup(env);
- util_remove_trailing_chars(config_file, '/');
+ udev_add_property(udev, "UDEV_CONFIG_FILE", udev->dev_path);
+ if (set_value(&config_file, env) == NULL)
+ goto err;
}
+
+ /* default config file */
+ if (config_file == NULL)
+ config_file = strdup(SYSCONFDIR "/udev/udev.conf");
if (config_file == NULL)
goto err;
+
f = fopen(config_file, "re");
if (f != NULL) {
char line[UTIL_LINE_SIZE];
@@ -214,40 +214,57 @@ struct udev *udev_new(void)
continue;
}
if (strcmp(key, "udev_root") == 0) {
- free(udev->dev_path);
- udev->dev_path = strdup(val);
- util_remove_trailing_chars(udev->dev_path, '/');
+ set_value(&udev->dev_path, val);
+ continue;
+ }
+ if (strcmp(key, "udev_run") == 0) {
+ set_value(&udev->run_config_path, val);
continue;
}
if (strcmp(key, "udev_rules") == 0) {
- free(udev->rules_path);
- udev->rules_path = strdup(val);
- util_remove_trailing_chars(udev->rules_path, '/');
+ set_value(&udev->rules_path, val);
continue;
}
}
fclose(f);
}
+ /* environment overwrites config */
+ env = getenv("UDEV_LOG");
+ if (env != NULL)
+ udev_set_log_priority(udev, util_log_priority(env));
+
env = getenv("UDEV_ROOT");
if (env != NULL) {
- free(udev->dev_path);
- udev->dev_path = strdup(env);
- util_remove_trailing_chars(udev->dev_path, '/');
+ set_value(&udev->dev_path, env);
udev_add_property(udev, "UDEV_ROOT", udev->dev_path);
}
- env = getenv("UDEV_LOG");
- if (env != NULL)
- udev_set_log_priority(udev, util_log_priority(env));
+ env = getenv("SYSFS_PATH");
+ if (env != NULL) {
+ set_value(&udev->sys_path, env);
+ udev_add_property(udev, "SYSFS_PATH", udev->sys_path);
+ }
+
+ /* set defaults */
+ if (udev->dev_path == NULL)
+ if (set_value(&udev->dev_path, "/dev") == NULL)
+ goto err;
+
+ if (udev->sys_path == NULL)
+ if (set_value(&udev->sys_path, "/sys") == NULL)
+ goto err;
+
+ if (udev->run_config_path == NULL)
+ if (set_value(&udev->run_config_path, "/run/udev") == NULL)
+ goto err;
- if (udev->dev_path == NULL || udev->sys_path == NULL)
- goto err;
dbg(udev, "context %p created\n", udev);
dbg(udev, "log_priority=%d\n", udev->log_priority);
dbg(udev, "config_file='%s'\n", config_file);
dbg(udev, "dev_path='%s'\n", udev->dev_path);
dbg(udev, "sys_path='%s'\n", udev->sys_path);
+ dbg(udev, "run_path='%s'\n", udev->run_config_path);
if (udev->rules_path != NULL)
dbg(udev, "rules_path='%s'\n", udev->rules_path);
free(config_file);
@@ -294,6 +311,8 @@ void udev_unref(struct udev *udev)
free(udev->dev_path);
free(udev->sys_path);
free(udev->rules_path);
+ free(udev->run_path);
+ free(udev->run_config_path);
dbg(udev, "context %p released\n", udev);
free(udev);
}
@@ -387,6 +406,39 @@ const char *udev_get_dev_path(struct udev *udev)
return udev->dev_path;
}
+const char *udev_get_run_config_path(struct udev *udev)
+{
+ return udev->run_config_path;
+}
+
+const char *udev_get_run_path(struct udev *udev)
+{
+ if (udev->run_path != NULL)
+ return udev->run_path;
+
+ /* check if configured path exists */
+ if (access(udev->run_config_path, F_OK) < 0) {
+ char filename[UTIL_PATH_SIZE];
+
+ /* fall back to /dev/.udev if that exists */
+ util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev", NULL);
+ if (access(filename, F_OK) >= 0)
+ if (set_value(&udev->run_path, filename) != NULL)
+ return udev->run_path;
+ }
+
+ /* use default path */
+ set_value(&udev->run_path, udev->run_config_path);
+ if (udev->run_path == NULL)
+ return udev->run_config_path;
+ return udev->run_path;
+}
+
+const char *udev_set_run_path(struct udev *udev, const char *path)
+{
+ return set_value(&udev->run_path, path);
+}
+
struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value)
{
if (value == NULL) {