libudev.la
test_udev_SOURCES = \
- src/test/test-udev.c
+ src/test/test-udev.c \
+ $(libudev_core_la_SOURCES) \
+ $(libudev_private_la_SOURCES)
+
+# The test-udev program needs everything compiled with relative path
+# names for /sys, /dev, /run prefixed, pointing to our test/ directory.
+test_udev_CFLAGS = \
+ -DTEST_PREFIX=\"test\" \
+ $(libudev_core_la_CFLAGS) \
+ $(libudev_private_la_CFLAGS)
+
+test_udev_CPPFLAGS =\
+ $(libudev_core_la_CPPFLAGS)
test_udev_LDADD = \
- libudev-core.la \
- libudev-private.la \
- libsystemd-shared.la
+ libsystemd-shared.la \
+ $(BLKID_LIBS) \
+ $(KMOD_LIBS) \
+ $(SELINUX_LIBS)
+
+if HAVE_ACL
+test_udev_LDADD += \
+ libsystemd-acl.la
+endif
check_DATA += \
test/sys
* suspend/hibernate/hybrid support, auto-suspend logic with idle hint
-* udev: remove /sys and /dev configurability
+* udev: unify selinux stuff with systemd
+
+* udev: move udev's recursive mkdir to shared/
* udev: find a way to tell udev to not cancel firmware requests when running in initramfs
- return object with *_unref()
- kill: udev_monitor_from_socket()
- kill: udev_queue_get_failed_list_entry()
+ - kill: udev_get_{dev,sys,run}_path()
* allow configuration of console width/height in vconsole.conf
udev_set_log_fn
udev_get_log_priority
udev_set_log_priority
+udev_get_userdata
+udev_set_userdata
udev_get_sys_path
udev_get_dev_path
udev_get_run_path
-udev_get_userdata
-udev_set_userdata
</SECTION>
<SECTION>
It consists of a set of variables allowing the user to override default udev values.
The following variables can be set:</para>
<variablelist>
- <varlistentry>
- <term><option>udev_root</option></term>
- <listitem>
- <para>Specifies where to place the device nodes in the filesystem.
- The default value is <filename>/dev</filename>.</para>
- </listitem>
- </varlistentry>
-
<varlistentry>
<term><option>udev_log</option></term>
<listitem>
id = udev_device_get_id_filename(dev);
if (id == NULL)
return;
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags/", tag, "/", id, NULL);
+ util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/tags/", tag, "/", id, NULL);
if (add) {
int fd;
return -1;
has_info = device_has_info(udev_device);
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL);
+ util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL);
/* do not store anything for otherwise empty devices */
if (!has_info &&
struct udev_list_entry *list_entry;
if (major(udev_device_get_devnum(udev_device)) > 0) {
- size_t devlen = strlen(udev_get_dev_path(udev))+1;
-
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(udev_device))
- fprintf(f, "S:%s\n", &udev_list_entry_get_name(list_entry)[devlen]);
+ fprintf(f, "S:%s\n", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"));
if (udev_device_get_devlink_priority(udev_device) != 0)
fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device));
if (udev_device_get_watch_handle(udev_device) >= 0)
int udev_device_delete_db(struct udev_device *udev_device)
{
const char *id;
- struct udev *udev = udev_device_get_udev(udev_device);
char filename[UTIL_PATH_SIZE];
id = udev_device_get_id_filename(udev_device);
if (id == NULL)
return -1;
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL);
+ util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL);
unlink(filename);
return 0;
}
if (strncmp(property, "DEVPATH=", 8) == 0) {
char path[UTIL_PATH_SIZE];
- util_strscpyl(path, sizeof(path), udev_get_sys_path(udev_device->udev), &property[8], NULL);
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys", &property[8], NULL);
udev_device_set_syspath(udev_device, path);
} else if (strncmp(property, "SUBSYSTEM=", 10) == 0) {
udev_device_set_subsystem(udev_device, &property[10]);
id = udev_device_get_id_filename(udev_device);
if (id == NULL)
return -1;
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_device->udev), "/data/", id, NULL);
+ util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL);
dbfile = filename;
}
val = &line[2];
switch(line[0]) {
case 'S':
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
+ util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", val, NULL);
udev_device_add_devlink(udev_device, filename, 0);
break;
case 'L':
**/
_public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
{
- size_t len;
const char *subdir;
char path[UTIL_PATH_SIZE];
char *pos;
return NULL;
/* path starts in sys */
- len = strlen(udev_get_sys_path(udev));
- if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) {
+ if (strncmp(syspath, TEST_PREFIX "/sys", strlen(TEST_PREFIX "/sys")) != 0) {
dbg(udev, "not in sys :%s\n", syspath);
return NULL;
}
/* path is not a root directory */
- subdir = &syspath[len+1];
+ subdir = syspath + strlen(TEST_PREFIX "/sys");
pos = strrchr(subdir, '/');
if (pos == NULL || pos[1] == '\0' || pos < &subdir[2])
return NULL;
util_strscpy(path, sizeof(path), syspath);
util_resolve_sys_link(udev, path, sizeof(path));
- if (strncmp(&path[len], "/devices/", 9) == 0) {
+ if (strncmp(path + strlen(TEST_PREFIX "/sys"), "/devices/", 9) == 0) {
char file[UTIL_PATH_SIZE];
/* all "devices" require a "uevent" file */
return NULL;
/* use /sys/dev/{block,char}/<maj>:<min> link */
- snprintf(path, sizeof(path), "%s/dev/%s/%u:%u",
- udev_get_sys_path(udev), type_str, major(devnum), minor(devnum));
+ snprintf(path, sizeof(path), TEST_PREFIX "/sys/dev/%s/%u:%u",
+ type_str, major(devnum), minor(devnum));
return udev_device_new_from_syspath(udev, path);
}
**/
_public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname)
{
- char path_full[UTIL_PATH_SIZE];
- char *path;
- size_t l;
+ char path[UTIL_PATH_SIZE];
struct stat statbuf;
- path = path_full;
- l = util_strpcpyl(&path, sizeof(path_full), udev_get_sys_path(udev), NULL);
-
if (strcmp(subsystem, "subsystem") == 0) {
- util_strscpyl(path, l, "/subsystem/", sysname, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", sysname, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
- util_strscpyl(path, l, "/bus/", sysname, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", sysname, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
- util_strscpyl(path, l, "/class/", sysname, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", sysname, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
goto out;
}
if (strcmp(subsystem, "module") == 0) {
- util_strscpyl(path, l, "/module/", sysname, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/module/", sysname, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
goto out;
}
driver[0] = '\0';
driver = &driver[1];
- util_strscpyl(path, l, "/subsystem/", subsys, "/drivers/", driver, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsys, "/drivers/", driver, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
- util_strscpyl(path, l, "/bus/", subsys, "/drivers/", driver, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsys, "/drivers/", driver, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
}
goto out;
}
- util_strscpyl(path, l, "/subsystem/", subsystem, "/devices/", sysname, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsystem, "/devices/", sysname, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
- util_strscpyl(path, l, "/bus/", subsystem, "/devices/", sysname, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsystem, "/devices/", sysname, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
- util_strscpyl(path, l, "/class/", subsystem, "/", sysname, NULL);
- if (stat(path_full, &statbuf) == 0)
+ util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", subsystem, "/", sysname, NULL);
+ if (stat(path, &statbuf) == 0)
goto found;
out:
return NULL;
found:
- return udev_device_new_from_syspath(udev, path_full);
+ return udev_device_new_from_syspath(udev, path);
}
/**
const char *subdir;
util_strscpy(path, sizeof(path), udev_device->syspath);
- subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1];
+ subdir = path + strlen(TEST_PREFIX "/sys/");
for (;;) {
char *pos;
udev_device->syspath = strdup(syspath);
if (udev_device->syspath == NULL)
return -ENOMEM;
- udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
+ udev_device->devpath = udev_device->syspath + strlen(TEST_PREFIX "/sys");
udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath);
pos = strrchr(udev_device->syspath, '/');
{
free(udev_device->devnode);
if (devnode[0] != '/') {
- if (asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), devnode) < 0)
+ if (asprintf(&udev_device->devnode, TEST_PREFIX "/dev/%s", devnode) < 0)
udev_device->devnode = NULL;
} else {
udev_device->devnode = strdup(devnode);
"/block/dm-",
NULL
};
- size_t len;
int i;
- len = strlen(udev_get_sys_path(udev));
for (i = 0; delay_device_list[i] != NULL; i++) {
- if (strstr(&syspath[len], delay_device_list[i]) != NULL)
+ if (strstr(syspath + strlen("/sys"), delay_device_list[i]) != NULL)
return true;
}
return false;
static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
const char *basedir, const char *subdir1, const char *subdir2)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
char path[UTIL_PATH_SIZE];
size_t l;
char *s;
struct dirent *dent;
s = path;
- l = util_strpcpyl(&s, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL);
+ l = util_strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL);
if (subdir1 != NULL)
l = util_strpcpyl(&s, l, "/", subdir1, NULL);
if (subdir2 != NULL)
static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
-
char path[UTIL_PATH_SIZE];
DIR *dir;
struct dirent *dent;
- util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL);
+ util_strscpyl(path, sizeof(path), "/sys/", basedir, NULL);
dir = opendir(path);
if (dir == NULL)
return -1;
static int scan_devices_tags(struct udev_enumerate *udev_enumerate)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
struct udev_list_entry *list_entry;
/* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */
struct dirent *dent;
char path[UTIL_PATH_SIZE];
- util_strscpyl(path, sizeof(path), udev_get_run_path(udev), "/tags/",
- udev_list_entry_get_name(list_entry), NULL);
+ util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL);
dir = opendir(path);
if (dir == NULL)
continue;
static int scan_devices_all(struct udev_enumerate *udev_enumerate)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
- char base[UTIL_PATH_SIZE];
struct stat statbuf;
- util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL);
- if (stat(base, &statbuf) == 0) {
+ if (stat("/sys/subsystem", &statbuf) == 0) {
/* we have /subsystem/, forget all the old stuff */
scan_dir(udev_enumerate, "subsystem", "devices", NULL);
} else {
**/
_public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
- char base[UTIL_PATH_SIZE];
struct stat statbuf;
const char *subsysdir;
if (match_subsystem(udev_enumerate, "module"))
scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL);
- util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL);
- if (stat(base, &statbuf) == 0)
+ if (stat("/sys/subsystem", &statbuf) == 0)
subsysdir = "subsystem";
else
subsysdir = "bus";
#include "macro.h"
#include "libudev.h"
-#define READ_END 0
+#define READ_END 0
#define WRITE_END 1
+#ifndef TEST_PREFIX
+#define TEST_PREFIX ""
+#endif
+
/* avoid (sometimes expensive) calculations of parameters for debug output */
#define udev_log_cond(udev, prio, arg...) \
do { \
void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export)
{
- char filename[UTIL_PATH_SIZE];
-
if (udev_queue_export == NULL)
return;
- 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_run_path(udev_queue_export->udev), "/queue.bin", NULL);
- unlink(filename);
+ unlink("/run/udev/queue.tmp");
+ unlink("/run/udev/queue.bin");
}
static int skip_to(FILE *file, long offset)
{
unsigned long long int seqnum;
struct queue_devpaths *devpaths = NULL;
- char filename[UTIL_PATH_SIZE];
- char filename_tmp[UTIL_PATH_SIZE];
FILE *new_queue_file = NULL;
unsigned int i;
}
/* create new queue file */
- 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+");
+ new_queue_file = fopen("/run/udev/queue.tmp", "w+");
if (new_queue_file == NULL)
goto error;
seqnum = udev_queue_export->seqnum_max;
goto error;
/* rename the new file on top of the old one */
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL);
- if (rename(filename_tmp, filename) != 0)
+ if (rename("/run/udev/queue.tmp", "/run/udev/queue.bin") != 0)
goto error;
if (udev_queue_export->queue_file != NULL)
unsigned long long int udev_get_kernel_seqnum(struct udev *udev)
{
- char filename[UTIL_PATH_SIZE];
unsigned long long int seqnum;
int fd;
char buf[32];
ssize_t len;
- util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), "/kernel/uevent_seqnum", NULL);
- fd = open(filename, O_RDONLY|O_CLOEXEC);
+ fd = open("/sys/kernel/uevent_seqnum", O_RDONLY|O_CLOEXEC);
if (fd < 0)
return 0;
len = read(fd, buf, sizeof(buf));
char filename[UTIL_PATH_SIZE];
FILE *queue_file;
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue->udev), "/queue.bin", NULL);
+ util_strscpyl(filename, sizeof(filename), "/run/udev/queue.bin", NULL);
queue_file = fopen(filename, "re");
if (queue_file == NULL)
return NULL;
snprintf(seqnum_str, sizeof(seqnum_str), "%llu", seqnum);
s = syspath;
- l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL);
+ l = util_strpcpy(&s, sizeof(syspath), "/sys");
len = udev_queue_read_devpath(queue_file, s, l);
if (len < 0)
break;
dbg(udev, "selinux=%i\n", selinux_enabled);
if (!selinux_enabled)
return;
- matchpathcon_init_prefix(NULL, udev_get_dev_path(udev));
+ matchpathcon_init_prefix(NULL, TEST_PREFIX "/dev");
if (getfscreatecon(&selinux_prev_scontext) < 0) {
err(udev, "getfscreatecon failed\n");
selinux_prev_scontext = NULL;
int priority, const char *file, int line, const char *fn,
const char *format, va_list args);
void *userdata;
- char *sys_path;
- char *dev_path;
- char *rules_path[4];
- unsigned long long rules_path_ts[4];
- int rules_path_count;
- char *run_path;
struct udev_list properties_list;
int log_priority;
};
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:
*
{
struct udev *udev;
const char *env;
- char *config_file = NULL;
FILE *f;
udev = calloc(1, sizeof(struct udev));
udev->log_priority = LOG_ERR;
udev_list_init(udev, &udev->properties_list, true);
- /* custom config file */
- env = getenv("UDEV_CONFIG_FILE");
- if (env != NULL) {
- if (set_value(&config_file, env) == NULL)
- goto err;
- udev_add_property(udev, "UDEV_CONFIG_FILE", config_file);
- }
-
- /* 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");
+ f = fopen(SYSCONFDIR "/udev/udev.conf", "re");
if (f != NULL) {
char line[UTIL_LINE_SIZE];
int line_nr = 0;
/* split key/value */
val = strchr(key, '=');
if (val == NULL) {
- err(udev, "missing <key>=<value> in '%s'[%i], skip line\n", config_file, line_nr);
+ err(udev, "missing <key>=<value> in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr);
continue;
}
val[0] = '\0';
/* unquote */
if (val[0] == '"' || val[0] == '\'') {
if (val[len-1] != val[0]) {
- err(udev, "inconsistent quoting in '%s'[%i], skip line\n", config_file, line_nr);
+ err(udev, "inconsistent quoting in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr);
continue;
}
val[len-1] = '\0';
udev_set_log_priority(udev, util_log_priority(val));
continue;
}
- if (strcmp(key, "udev_root") == 0) {
- set_value(&udev->dev_path, val);
- continue;
- }
- if (strcmp(key, "udev_run") == 0) {
- set_value(&udev->run_path, val);
- continue;
- }
- if (strcmp(key, "udev_sys") == 0) {
- set_value(&udev->sys_path, val);
- continue;
- }
- if (strcmp(key, "udev_rules") == 0) {
- set_value(&udev->rules_path[0], val);
- udev->rules_path_count = 1;
- continue;
- }
}
fclose(f);
}
if (env != NULL)
udev_set_log_priority(udev, util_log_priority(env));
- /* 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_path == NULL)
- if (set_value(&udev->run_path, "/run/udev") == NULL)
- goto err;
-
- if (udev->rules_path[0] == NULL) {
- /* /usr/lib/udev -- system rules */
- udev->rules_path[0] = strdup(UDEVLIBEXECDIR "/rules.d");
- if (!udev->rules_path[0])
- goto err;
-
- /* /run/udev -- runtime rules */
- if (asprintf(&udev->rules_path[1], "%s/rules.d", udev->run_path) < 0)
- goto err;
-
- /* /etc/udev -- local administration rules */
- udev->rules_path[2] = strdup(SYSCONFDIR "/udev/rules.d");
- if (!udev->rules_path[2])
- goto err;
-
- udev->rules_path_count = 3;
- }
-
- free(config_file);
return udev;
-err:
- free(config_file);
- err(udev, "context creation failed\n");
- udev_unref(udev);
- return NULL;
}
/**
if (udev->refcount > 0)
return;
udev_list_cleanup(&udev->properties_list);
- free(udev->dev_path);
- free(udev->sys_path);
- free(udev->rules_path[0]);
- free(udev->rules_path[1]);
- free(udev->rules_path[2]);
- free(udev->run_path);
free(udev);
}
udev_add_property(udev, "UDEV_LOG", num);
}
-int udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *stamp_usec[])
-{
- *path = udev->rules_path;
- if (stamp_usec)
- *stamp_usec = udev->rules_path_ts;
- return udev->rules_path_count;
-}
-
/**
* udev_get_sys_path:
* @udev: udev library context
*
- * Retrieve the sysfs mount point. The default is "/sys". For
- * testing purposes, it can be overridden with udev_sys=
- * in the udev configuration file.
+ * Returns always "/sys"; deprecated, will be removed in a future version.
*
* Returns: the sys mount point
**/
{
if (udev == NULL)
return NULL;
- return udev->sys_path;
+ return "/sys";
}
/**
* udev_get_dev_path:
* @udev: udev library context
*
- * Retrieve the device directory path. The default value is "/dev",
- * the actual value may be overridden in the udev configuration
- * file.
+ * Returns always "/dev"; deprecated, will be removed in a future version.
*
* Returns: the device directory path
**/
{
if (udev == NULL)
return NULL;
- return udev->dev_path;
+ return "/dev";
}
/**
* udev_get_run_path:
* @udev: udev library context
*
- * Retrieve the udev runtime directory path. The default is "/run/udev".
+ * Returns always "/run/udev"; deprecated, will be removed in a future version.
*
* Returns: the runtime directory path
**/
{
if (udev == NULL)
return NULL;
- return udev->run_path;
+ return "/run/udev";
}
struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value)
const char *syspath = "/devices/virtual/mem/null";
const char *subsystem = NULL;
char path[1024];
- const char *str;
udev = udev_new();
printf("context: %p\n", udev);
}
}
- str = udev_get_sys_path(udev);
- printf("sys_path: '%s'\n", str);
- str = udev_get_dev_path(udev);
- printf("dev_path: '%s'\n", str);
-
/* add sys path if needed */
- if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
- snprintf(path, sizeof(path), "%s%s", udev_get_sys_path(udev), syspath);
+ if (strncmp(syspath, "/sys", strlen("/sys")) != 0) {
+ snprintf(path, sizeof(path), "/sys/%s", syspath);
syspath = path;
}
rules = udev_rules_new(udev, 1);
- util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL);
+ util_strscpyl(syspath, sizeof(syspath), TEST_PREFIX "/sys", devpath, NULL);
dev = udev_device_new_from_syspath(udev, syspath);
if (dev == NULL) {
log_debug("unknown device '%s'\n", devpath);
}
/* get the device */
- snprintf(devpath, sizeof(devpath), "%s/%s", udev_get_sys_path(udev), argv[optind]);
+ snprintf(devpath, sizeof(devpath), "/sys/%s", argv[optind]);
dev = udev_device_new_from_syspath(udev, devpath);
if (dev == NULL) {
fprintf(stderr, "unable to access '%s'\n", devpath);
return 0;
}
- /* Get the children devices and find the devnode
- * FIXME: use udev_enumerate_add_match_children() instead
- * when it's available */
+ /* Get the children devices and find the devnode */
+ /* FIXME: use udev_enumerate_add_match_parent() instead */
devnode = NULL;
enumerate = udev_enumerate_new(udev);
udev_enumerate_add_match_property(enumerate, "ID_PATH", id_path);
if (debug)
fprintf(stderr, "Using checkpoint '%s'\n", checkpoint);
- util_strscpyl(tmpdir, sizeof(tmpdir), udev_get_run_path(udev), "/collect", NULL);
+ util_strscpyl(tmpdir, sizeof(tmpdir), "/run/udev/collect", NULL);
fd = prepare(tmpdir, checkpoint);
if (fd < 0) {
ret = 3;
}
util_path_encode(firmware, fwencpath, sizeof(fwencpath));
- util_strscpyl(misspath, sizeof(misspath), udev_get_run_path(udev), "/firmware-missing/", fwencpath, NULL);
+ util_strscpyl(misspath, sizeof(misspath), "/run/udev/firmware-missing/", fwencpath, NULL);
util_strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL);
if (fwfile == NULL) {
}
uctrl->saddr.sun_family = AF_LOCAL;
- util_strscpyl(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path),
- udev_get_run_path(udev), "/control", NULL);
+ util_strscpy(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), "/run/udev/control");
uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.sun_path);
return uctrl;
}
if (dev_parent == NULL)
break;
devnode = udev_device_get_devnode(dev_parent);
- if (devnode != NULL) {
- size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
-
- l = util_strpcpy(&s, l, &devnode[devlen]);
- }
+ if (devnode != NULL)
+ l = util_strpcpy(&s, l, devnode + strlen(TEST_PREFIX "/dev/"));
break;
}
case SUBST_DEVNODE:
if (udev_device_get_devnode(dev) != NULL)
l = util_strpcpy(&s, l, udev_device_get_devnode(dev));
break;
- case SUBST_NAME: {
- if (event->name != NULL) {
+ case SUBST_NAME:
+ if (event->name != NULL)
l = util_strpcpy(&s, l, event->name);
- } else if (udev_device_get_devnode(dev) != NULL) {
- size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
-
- l = util_strpcpy(&s, l, &udev_device_get_devnode(dev)[devlen]);
- } else {
+ else if (udev_device_get_devnode(dev) != NULL)
+ l = util_strpcpy(&s, l, udev_device_get_devnode(dev) + strlen(TEST_PREFIX "/dev/"));
+ else
l = util_strpcpy(&s, l, udev_device_get_sysname(dev));
- }
break;
- }
case SUBST_LINKS: {
- size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
struct udev_list_entry *list_entry;
list_entry = udev_device_get_devlinks_list_entry(dev);
if (list_entry == NULL)
break;
- l = util_strpcpy(&s, l, &udev_list_entry_get_name(list_entry)[devlen]);
+ l = util_strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"));
udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry))
- l = util_strpcpyl(&s, l, " ", &udev_list_entry_get_name(list_entry)[devlen], NULL);
+ l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"), NULL);
break;
}
case SUBST_ROOT:
- l = util_strpcpy(&s, l, udev_get_dev_path(event->udev));
+ l = util_strpcpy(&s, l, TEST_PREFIX "/dev");
break;
case SUBST_SYS:
- l = util_strpcpy(&s, l, udev_get_sys_path(event->udev));
+ l = util_strpcpy(&s, l, TEST_PREFIX "/sys");
break;
case SUBST_ENV:
if (attr == NULL) {
const char *target;
char buf[UTIL_PATH_SIZE];
- util_path_encode(&slink[strlen(udev_get_dev_path(udev))+1], name_enc, sizeof(name_enc));
- util_strscpyl(dirname, sizeof(dirname), udev_get_run_path(udev), "/links/", name_enc, NULL);
+ util_path_encode(slink + strlen(TEST_PREFIX "/dev"), name_enc, sizeof(name_enc));
+ util_strscpyl(dirname, sizeof(dirname), TEST_PREFIX "/run/udev/links/", name_enc, NULL);
util_strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL);
if (!add && unlink(filename) == 0)
return;
/* always add /dev/{block,char}/$major:$minor */
- snprintf(filename, sizeof(filename), "%s/%s/%u:%u",
- udev_get_dev_path(udev),
+ snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u",
strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char",
major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
node_symlink(udev, udev_device_get_devnode(dev), filename);
void udev_node_remove(struct udev_device *dev)
{
- struct udev *udev = udev_device_get_udev(dev);
struct udev_list_entry *list_entry;
char filename[UTIL_PATH_SIZE];
link_update(dev, udev_list_entry_get_name(list_entry), 0);
/* remove /dev/{block,char}/$major:$minor */
- snprintf(filename, sizeof(filename), "%s/%s/%u:%u",
- udev_get_dev_path(udev),
+ snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u",
strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char",
major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
unlink(filename);
#define PREALLOC_STRBUF 32 * 1024
#define PREALLOC_TRIE 256
+/* configuration directories with last modification timestamp */
+static const char *rules_dirs[] = {
+ TEST_PREFIX UDEVLIBEXECDIR "/rules.d",
+ TEST_PREFIX "/run/udev/rules.d",
+ TEST_PREFIX SYSCONFDIR "/udev/rules.d",
+};
+
struct uid_gid {
unsigned int name_off;
union {
struct udev_rules {
struct udev *udev;
+ unsigned long long dirs_ts_usec[ELEMENTSOF(rules_dirs)];
int resolve_names;
/* every key in the rules file becomes a token */
static int import_property_from_string(struct udev_device *dev, char *line)
{
- struct udev *udev = udev_device_get_udev(dev);
char *key;
char *val;
size_t len;
log_debug("updating devpath from '%s' to '%s'\n",
udev_device_get_devpath(dev), val);
- util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), val, NULL);
+ util_strscpyl(syspath, sizeof(syspath), "/sys", val, NULL);
udev_device_set_syspath(dev, syspath);
} else {
struct udev_list_entry *entry;
#define WAIT_LOOP_PER_SECOND 50
static int wait_for_file(struct udev_device *dev, const char *file, int timeout)
{
- struct udev *udev = udev_device_get_udev(dev);
char filepath[UTIL_PATH_SIZE];
char devicepath[UTIL_PATH_SIZE];
struct stat stats;
/* a relative path is a device attribute */
devicepath[0] = '\0';
if (file[0] != '/') {
- util_strscpyl(devicepath, sizeof(devicepath),
- udev_get_sys_path(udev), udev_device_get_devpath(dev), NULL);
+ util_strscpyl(devicepath, sizeof(devicepath), udev_device_get_syspath(dev), NULL);
util_strscpyl(filepath, sizeof(filepath), devicepath, "/", file, NULL);
file = filepath;
}
struct udev_list file_list;
struct udev_list_entry *file_loop;
struct token end_token;
- char **s;
+ unsigned int i;
rules = calloc(1, sizeof(struct udev_rules));
if (rules == NULL)
memset(rules->trie_nodes, 0x00, sizeof(struct trie_node));
rules->trie_nodes_cur = 1;
- for (udev_get_rules_path(udev, &s, NULL); *s != NULL; s++)
- add_matching_files(udev, &file_list, *s, ".rules");
+ for (i = 0; i < ELEMENTSOF(rules_dirs); i++)
+ add_matching_files(udev, &file_list, rules_dirs[i], ".rules");
/* add all filenames to the string buffer */
udev_list_entry_foreach(file_loop, udev_list_get_entry(&file_list)) {
return NULL;
}
+bool udev_rules_check_timestamp(struct udev_rules *rules)
+{
+ unsigned int i;
+ bool changed = false;
+
+ for (i = 0; i < ELEMENTSOF(rules_dirs); i++) {
+ struct stat stats;
+
+ if (stat(rules_dirs[i], &stats) < 0)
+ continue;
+
+ if (rules->dirs_ts_usec[i] == ts_usec(&stats.st_mtim))
+ continue;
+
+ /* first check */
+ if (rules->dirs_ts_usec[i] != 0) {
+ log_debug("reload - timestamp of '%s' changed\n", rules_dirs[i]);
+ changed = true;
+ }
+
+ /* update timestamp */
+ rules->dirs_ts_usec[i] = ts_usec(&stats.st_mtim);
+ }
+
+ return changed;
+}
+
static int match_key(struct udev_rules *rules, struct token *token, const char *val)
{
char *key_value = &rules->buf[token->key.value_off];
goto nomatch;
break;
case TK_M_DEVLINK: {
- size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
struct udev_list_entry *list_entry;
bool match = false;
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(event->dev)) {
const char *devlink;
- devlink = &udev_list_entry_get_name(list_entry)[devlen];
+ devlink = udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/");
if (match_key(rules, cur, devlink) == 0) {
match = true;
break;
if (count > 0)
log_debug("%i character(s) replaced\n", count);
}
- if (major(udev_device_get_devnum(event->dev))) {
- size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
-
- if (strcmp(name_str, &udev_device_get_devnode(event->dev)[devlen]) != 0) {
- log_error("NAME=\"%s\" ignored, kernel device nodes "
- "can not be renamed; please fix it in %s:%u\n", name,
- &rules->buf[rule->rule.filename_off], rule->rule.filename_line);
- break;
- }
+ if (major(udev_device_get_devnum(event->dev)) &&
+ (strcmp(name_str, udev_device_get_devnode(event->dev) + strlen(TEST_PREFIX "/dev/")) != 0)) {
+ log_error("NAME=\"%s\" ignored, kernel device nodes "
+ "can not be renamed; please fix it in %s:%u\n", name,
+ &rules->buf[rule->rule.filename_off], rule->rule.filename_line);
+ break;
}
free(event->name);
event->name = strdup(name_str);
next[0] = '\0';
log_debug("LINK '%s' %s:%u\n", pos,
&rules->buf[rule->rule.filename_off], rule->rule.filename_line);
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL);
+ util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL);
udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique);
while (isspace(next[1]))
next++;
if (pos[0] != '\0') {
log_debug("LINK '%s' %s:%u\n", pos,
&rules->buf[rule->rule.filename_off], rule->rule.filename_line);
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL);
+ util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL);
udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique);
}
break;
/* we assure, that the permissions tokens are sorted before the static token */
if (mode == 0 && uid == 0 && gid == 0)
goto next;
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(rules->udev), "/",
+ util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/",
&rules->buf[cur->key.value_off], NULL);
if (stat(filename, &stats) != 0)
goto next;
*/
void udev_watch_restore(struct udev *udev)
{
- char filename[UTIL_PATH_SIZE], oldname[UTIL_PATH_SIZE];
-
if (inotify_fd < 0)
return;
- util_strscpyl(oldname, sizeof(oldname), udev_get_run_path(udev), "/watch.old", NULL);
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch", NULL);
- if (rename(filename, oldname) == 0) {
+ if (rename("/run/udev/watch", "/run/udev/watch.old") == 0) {
DIR *dir;
struct dirent *ent;
- dir = opendir(oldname);
+ dir = opendir("/run/udev/watch.old");
if (dir == NULL) {
- log_error("unable to open old watches dir '%s', old watches will not be restored: %m", oldname);
+ log_error("unable to open old watches dir /run/udev/watch.old; old watches will not be restored: %m");
return;
}
for (ent = readdir(dir); ent != NULL; ent = readdir(dir)) {
char device[UTIL_PATH_SIZE];
- char *s;
- size_t l;
ssize_t len;
struct udev_device *dev;
if (ent->d_name[0] == '.')
continue;
- s = device;
- l = util_strpcpy(&s, sizeof(device), udev_get_sys_path(udev));
- len = readlinkat(dirfd(dir), ent->d_name, s, l);
- if (len <= 0 || len == (ssize_t)l)
+ len = readlinkat(dirfd(dir), ent->d_name, device, sizeof(device));
+ if (len <= 0 || len == (ssize_t)sizeof(device))
goto unlink;
- s[len] = '\0';
+ device[len] = '\0';
- dev = udev_device_new_from_id_filename(udev, s);
+ dev = udev_device_new_from_id_filename(udev, device);
if (dev == NULL)
goto unlink;
}
closedir(dir);
- rmdir(oldname);
+ rmdir("/run/udev/watch.old");
} else if (errno != ENOENT) {
- log_error("unable to move watches dir '%s', old watches will not be restored: %m", filename);
+ log_error("unable to move watches dir /run/udev/watch; old watches will not be restored: %m");
}
}
return;
}
- snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd);
+ snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd);
util_create_path(udev, filename);
unlink(filename);
symlink(udev_device_get_id_filename(dev), filename);
log_debug("removing watch on '%s'\n", udev_device_get_devnode(dev));
inotify_rm_watch(inotify_fd, wd);
- snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd);
+ snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd);
unlink(filename);
udev_device_set_watch_handle(dev, -1);
struct udev_device *udev_watch_lookup(struct udev *udev, int wd)
{
char filename[UTIL_PATH_SIZE];
- char majmin[UTIL_PATH_SIZE];
- char *s;
- size_t l;
+ char device[UTIL_NAME_SIZE];
ssize_t len;
if (inotify_fd < 0 || wd < 0)
return NULL;
- snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd);
- s = majmin;
- l = util_strpcpy(&s, sizeof(majmin), udev_get_sys_path(udev));
- len = readlink(filename, s, l);
- if (len <= 0 || (size_t)len == l)
+ snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd);
+ len = readlink(filename, device, sizeof(device));
+ if (len <= 0 || (size_t)len == sizeof(device))
return NULL;
- s[len] = '\0';
+ device[len] = '\0';
- return udev_device_new_from_id_filename(udev, s);
+ return udev_device_new_from_id_filename(udev, device);
}
struct udev_rules;
struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names);
struct udev_rules *udev_rules_unref(struct udev_rules *rules);
+bool udev_rules_check_timestamp(struct udev_rules *rules);
int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, const sigset_t *sigmask);
void udev_rules_apply_static_dev_perms(struct udev_rules *rules);
static void print_record(struct udev_device *device)
{
- size_t len;
const char *str;
int i;
struct udev_list_entry *list_entry;
printf("P: %s\n", udev_device_get_devpath(device));
- len = strlen(udev_get_dev_path(udev_device_get_udev(device)));
str = udev_device_get_devnode(device);
if (str != NULL)
- printf("N: %s\n", &str[len+1]);
+ printf("N: %s\n", str + strlen("/dev/"));
i = udev_device_get_devlink_priority(device);
if (i != 0)
printf("L: %i\n", i);
- udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) {
- len = strlen(udev_get_dev_path(udev_device_get_udev(device)));
- printf("S: %s\n", &udev_list_entry_get_name(list_entry)[len+1]);
- }
+ udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device))
+ printf("S: %s\n", udev_list_entry_get_name(list_entry) + strlen("/dev/"));
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device))
printf("E: %s=%s\n",
static void cleanup_db(struct udev *udev)
{
- char filename[UTIL_PATH_SIZE];
DIR *dir;
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/queue.bin", NULL);
- unlink(filename);
+ unlink("/run/udev/queue.bin");
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL);
- dir = opendir(filename);
+ dir = opendir("/run/udev/data");
if (dir != NULL) {
cleanup_dir(dir, S_ISVTX, 1);
closedir(dir);
}
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/links", NULL);
- dir = opendir(filename);
+ dir = opendir("/run/udev/links");
if (dir != NULL) {
cleanup_dir(dir, 0, 2);
closedir(dir);
}
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags", NULL);
- dir = opendir(filename);
+ dir = opendir("/run/udev/tags");
if (dir != NULL) {
cleanup_dir(dir, 0, 2);
closedir(dir);
}
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch", NULL);
- dir = opendir(filename);
+ dir = opendir("/run/udev/watch");
if (dir != NULL) {
cleanup_dir(dir, 0, 1);
closedir(dir);
}
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/firmware-missing", NULL);
- dir = opendir(filename);
+ dir = opendir("/run/udev/firmware-missing");
if (dir != NULL) {
cleanup_dir(dir, 0, 1);
closedir(dir);
rc = 2;
goto exit;
}
- /* remove /dev if given */
- if (strncmp(optarg, udev_get_dev_path(udev), strlen(udev_get_dev_path(udev))) != 0)
- util_strscpyl(name, sizeof(name), udev_get_dev_path(udev), "/", optarg, NULL);
+ /* add /dev if not given */
+ if (strncmp(optarg, "/dev", strlen("/dev")) != 0)
+ util_strscpyl(name, sizeof(name), "/dev/", optarg, NULL);
else
util_strscpy(name, sizeof(name), optarg);
util_remove_trailing_chars(name, '/');
goto exit;
}
/* add sys dir if needed */
- if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0)
- util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), optarg, NULL);
+ if (strncmp(optarg, "/sys", strlen("/sys")) != 0)
+ util_strscpyl(path, sizeof(path), "/sys", optarg, NULL);
else
util_strscpy(path, sizeof(path), optarg);
util_remove_trailing_chars(path, '/');
root = true;
break;
case 'R':
- printf("%s\n", udev_get_run_path(udev));
+ printf("/run/udev\n");
goto exit;
case 'd':
action = ACTION_DEVICE_ID_FILE;
goto exit;
}
- if (root) {
+ if (root)
printf("%s\n", udev_device_get_devnode(device));
- } else {
- size_t len = strlen(udev_get_dev_path(udev));
-
- printf("%s\n", &udev_device_get_devnode(device)[len+1]);
- }
+ else
+ printf("%s\n", udev_device_get_devnode(device) + strlen("/dev/"));
break;
}
case QUERY_SYMLINK:
list_entry = udev_device_get_devlinks_list_entry(device);
while (list_entry != NULL) {
- if (root) {
+ if (root)
printf("%s", udev_list_entry_get_name(list_entry));
- } else {
- size_t len;
-
- len = strlen(udev_get_dev_path(udev_device_get_udev(device)));
- printf("%s", &udev_list_entry_get_name(list_entry)[len+1]);
- }
+ else
+ printf("%s", udev_list_entry_get_name(list_entry) + strlen("/dev/"));
list_entry = udev_list_entry_get_next(list_entry);
if (list_entry != NULL)
printf(" ");
rc = 1;
break;
case ACTION_ROOT:
- printf("%s\n", udev_get_dev_path(udev));
+ printf("/dev\n");
break;
default:
fprintf(stderr, "missing option\n");
if (pfd[0].fd < 0) {
log_error("inotify_init failed: %m\n");
} else {
- if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_MOVED_TO) < 0) {
- log_error("watching '%s' failed\n", udev_get_run_path(udev));
+ if (inotify_add_watch(pfd[0].fd, "/run/udev" , IN_MOVED_TO) < 0) {
+ log_error("watching /run/udev failed\n");
close(pfd[0].fd);
pfd[0].fd = -1;
}
}
/* add /sys if needed */
- if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0)
- util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL);
+ if (strncmp(syspath, "/sys", strlen("/sys")) != 0)
+ util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL);
else
util_strscpy(filename, sizeof(filename), syspath);
util_remove_trailing_chars(filename, '/');
}
/* add /sys if needed */
- if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0)
- util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL);
+ if (strncmp(syspath, "/sys", strlen("/sys")) != 0)
+ util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL);
else
util_strscpy(filename, sizeof(filename), syspath);
util_remove_trailing_chars(filename, '/');
struct udev_device *dev;
/* add sys dir if needed */
- if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0)
- util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), optarg, NULL);
+ if (strncmp(optarg, "/sys", strlen("/sys")) != 0)
+ util_strscpyl(path, sizeof(path), "/sys", optarg, NULL);
else
util_strscpy(path, sizeof(path), optarg);
util_remove_trailing_chars(path, '/');
}
command = argv[optind];
- log_debug("runtime dir '%s'\n", udev_get_run_path(udev));
-
if (command != NULL)
for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) {
if (strcmp(udevadm_cmds[i]->name, command) == 0) {
else
continue;
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/", devname, NULL);
+ util_strscpyl(filename, sizeof(filename), "/dev/", devname, NULL);
util_create_path_selinux(udev, filename);
udev_selinux_setfscreatecon(udev, filename, mode);
log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min);
};
unsigned int i;
- dir = opendir(udev_get_dev_path(udev));
+ dir = opendir("/dev");
if (dir == NULL)
return;
struct udev_list_entry *list_entry;
/* current database */
- util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL);
- if (access(filename, F_OK) >= 0)
+ if (access("/run/udev/data", F_OK) >= 0)
return 0;
/* make sure we do not get here again */
- util_create_path(udev, filename);
+ util_create_path(udev, "/run/udev/data");
mkdir(filename, 0755);
/* old database */
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db", NULL);
+ util_strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL);
if (access(filename, F_OK) < 0)
return 0;
/* find database in old location */
id = udev_device_get_id_filename(device);
- util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", id, NULL);
+ util_strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
udev_device_read_db(device, from);
}
/* find old database with $subsys:$sysname name */
- util_strscpyl(from, sizeof(from), udev_get_dev_path(udev),
- "/.udev/db/", udev_device_get_subsystem(device), ":",
- udev_device_get_sysname(device), NULL);
+ util_strscpyl(from, sizeof(from), "/dev/.udev/db/",
+ udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
udev_device_read_db(device, from);
/* find old database with the encoded devpath name */
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);
+ util_strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
udev_device_read_db(device, from);
return 0;
}
-static bool check_rules_timestamp(struct udev *udev)
-{
- char **p;
- unsigned long long *stamp_usec;
- int i, n;
- bool changed = false;
-
- n = udev_get_rules_path(udev, &p, &stamp_usec);
- for (i = 0; i < n; i++) {
- struct stat stats;
-
- if (stat(p[i], &stats) < 0)
- continue;
-
- if (stamp_usec[i] == ts_usec(&stats.st_mtim))
- continue;
-
- /* first check */
- if (stamp_usec[i] != 0) {
- log_debug("reload - timestamp of '%s' changed\n", p[i]);
- changed = true;
- }
-
- /* update timestamp */
- stamp_usec[i] = ts_usec(&stats.st_mtim);
- }
-
- return changed;
-}
-
int main(int argc, char *argv[])
{
struct udev *udev;
chdir("/");
umask(022);
- /* /run/udev */
- mkdir(udev_get_run_path(udev), 0755);
+ mkdir("/run/udev", 0755);
/* create standard links, copy static nodes, create nodes from modules */
static_dev_create_links(udev);
/* check for changed config, every 3 seconds at most */
if ((now_usec() - last_usec) > 3 * 1000 * 1000) {
- if (check_rules_timestamp(udev))
+ if (udev_rules_check_timestamp(rules))
reload = true;
if (udev_builtin_validate(udev))
reload = true;
# After creation and removal the result is checked against the
# expected value and the result is printed.
#
-# Copyright (C) 2004-2011 Kay Sievers <kay.sievers@vrfy.org>
+# Copyright (C) 2004-2012 Kay Sievers <kay.sievers@vrfy.org>
# Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org>
use warnings;
use strict;
-my $PWD = $ENV{PWD};
-my $sysfs = "test/sys";
my $udev_bin = "./test-udev";
my $valgrind = 0;
my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
-my $udev_root = "udev-root";
-my $udev_conf = "udev-test.conf";
-my $udev_rules = "udev-test.rules";
+my $udev_dev = "test/dev";
+my $udev_run = "test/run";
+my $udev_rules_dir = "$udev_run/udev/rules.d";
+my $udev_rules = "$udev_rules_dir/udev-test.rules";
my @tests = (
{
exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
rules => <<EOF
SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
-EOF
- },
- {
- desc => "import of shell-value file",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
- exp_name => "subdir/err/node" ,
- rules => <<EOF
-SUBSYSTEMS=="scsi", IMPORT{file}="udev-test.conf", SYMLINK+="subdir/%E{udev_log}/node"
-KERNEL=="ttyACM0", SYMLINK+="modem"
EOF
},
{
exp_name => "tty33",
exp_perms => "0:0:0600",
rules => <<EOF
-KERNEL=="tty33", SYMLINK+="tty33", OWNER="bad", GROUP="name"
+KERNEL=="tty33", OWNER="bad", GROUP="name"
EOF
},
{
{
desc => "udev_root substitution",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
- exp_name => "start-udev-root-end",
+ exp_name => "start-test/dev-end",
rules => <<EOF
SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
EOF
},
);
-# set env
-$ENV{UDEV_CONFIG_FILE} = $udev_conf;
-
sub udev {
my ($action, $devpath, $rules) = @_;
# create temporary rules
+ system("mkdir", "-p", "$udev_rules_dir");
open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
print CONF $$rules;
close CONF;
}
}
-sub make_udev_root {
- system("rm -rf $udev_root");
- mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
- # setting group and mode of udev_root ensures the tests work
+sub udev_setup {
+ system("rm", "-rf", "$udev_dev");
+ mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
+ # setting group and mode of udev_dev ensures the tests work
# even if the parent directory has setgid bit enabled.
- chown (0, 0, $udev_root) || die "unable to chown $udev_root\n";
- chmod (0755, $udev_root) || die "unable to chmod $udev_root\n";
+ chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
+ chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
+
+ system("rm", "-rf", "$udev_run");
}
sub run_test {
udev("add", $rules->{devpath}, \$rules->{rules});
if (defined($rules->{not_exp_name})) {
- if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") ||
- (-l "$PWD/$udev_root/$rules->{not_exp_name}")) {
+ if ((-e "$udev_dev/$rules->{not_exp_name}") ||
+ (-l "$udev_dev/$rules->{not_exp_name}")) {
print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
$error++;
sleep(1);
}
}
- if ((-e "$PWD/$udev_root/$rules->{exp_name}") ||
- (-l "$PWD/$udev_root/$rules->{exp_name}")) {
+ if ((-e "$udev_dev/$rules->{exp_name}") ||
+ (-l "$udev_dev/$rules->{exp_name}")) {
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
- $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}");
+ $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
if (defined($rules->{exp_perms})) {
permissions_test($rules, $uid, $gid, $mode);
print " as expected\n";
} else {
print "\n";
- system("tree $udev_root");
+ system("tree", "$udev_dev");
print "\n";
$error++;
sleep(1);
}
udev("remove", $rules->{devpath}, \$rules->{rules});
- if ((-e "$PWD/$udev_root/$rules->{exp_name}") ||
- (-l "$PWD/$udev_root/$rules->{exp_name}")) {
+ if ((-e "$udev_dev/$rules->{exp_name}") ||
+ (-l "$udev_dev/$rules->{exp_name}")) {
print "remove: error";
if ($rules->{exp_rem_error}) {
print " as expected\n";
} else {
print "\n";
- system("tree $udev_root");
+ system("tree", "$udev_dev");
print "\n";
$error++;
sleep(1);
print "\n";
if (defined($rules->{option}) && $rules->{option} eq "clean") {
- make_udev_root();
+ udev_setup();
}
}
exit;
}
-# prepare
-make_udev_root();
-
-# create config file
-open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
-print CONF "udev_root=\"$udev_root\"\n";
-print CONF "udev_run=\"$udev_root/.udev\"\n";
-print CONF "udev_sys=\"$sysfs\"\n";
-print CONF "udev_rules=\"$PWD\"\n";
-print CONF "udev_log=\"err\"\n";
-close CONF;
+udev_setup();
my $test_num = 1;
my @list;
print "$error errors occured\n\n";
# cleanup
-system("rm -rf $udev_root");
-unlink($udev_rules);
-unlink($udev_conf);
+system("rm", "-rf", "$udev_dev");
+system("rm", "-rf", "$udev_run");
if ($error > 0) {
exit(1);