summaryrefslogtreecommitdiff
path: root/libudev
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2012-01-01 04:21:15 +0100
committerKay Sievers <kay.sievers@vrfy.org>2012-01-01 04:21:15 +0100
commit220893b3cbdbf8932f95c44811b169a8f0d33939 (patch)
tree540deaec74df773c5d7973dc3b3bb3d734dc834b /libudev
parenteed0832780382298f5df26143a8271f9a4328a9f (diff)
remove mknod() logic and rely on 'devtmpfs'
Diffstat (limited to 'libudev')
-rw-r--r--libudev/libudev-device-private.c24
-rw-r--r--libudev/libudev-device.c54
-rw-r--r--libudev/libudev-private.h2
-rw-r--r--libudev/libudev-util-private.c17
-rw-r--r--libudev/libudev.c20
5 files changed, 27 insertions, 90 deletions
diff --git a/libudev/libudev-device-private.c b/libudev/libudev-device-private.c
index b78b6c9553..0864919301 100644
--- a/libudev/libudev-device-private.c
+++ b/libudev/libudev-device-private.c
@@ -78,7 +78,6 @@ int udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old,
static bool device_has_info(struct udev_device *udev_device)
{
- struct udev *udev = udev_device_get_udev(udev_device);
struct udev_list_entry *list_entry;
if (udev_device_get_devlinks_list_entry(udev_device) != NULL)
@@ -90,12 +89,6 @@ static bool device_has_info(struct udev_device *udev_device)
return true;
if (udev_device_get_tags_list_entry(udev_device) != NULL)
return true;
- if (udev_device_get_devnode(udev_device) != NULL && udev_device_get_knodename(udev_device) != NULL) {
- size_t devlen = strlen(udev_get_dev_path(udev))+1;
-
- if (strcmp(&udev_device_get_devnode(udev_device)[devlen], udev_device_get_knodename(udev_device)) != 0)
- return true;
- }
if (udev_device_get_watch_handle(udev_device) >= 0)
return true;
return false;
@@ -142,20 +135,22 @@ int udev_device_update_db(struct udev_device *udev_device)
fchmod(fileno(f), 01644);
if (has_info) {
- size_t devlen = strlen(udev_get_dev_path(udev))+1;
struct udev_list_entry *list_entry;
- if (udev_device_get_devnode(udev_device) != NULL) {
- fprintf(f, "N:%s\n", &udev_device_get_devnode(udev_device)[devlen]);
+ 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]);
+ 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)
+ fprintf(f, "W:%i\n", udev_device_get_watch_handle(udev_device));
}
- 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)
- fprintf(f, "W:%i\n", udev_device_get_watch_handle(udev_device));
+
if (udev_device_get_usec_initialized(udev_device) > 0)
fprintf(f, "I:%llu\n", udev_device_get_usec_initialized(udev_device));
+
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
if (!udev_list_entry_get_num(list_entry))
continue;
@@ -163,6 +158,7 @@ int udev_device_update_db(struct udev_device *udev_device)
udev_list_entry_get_name(list_entry),
udev_list_entry_get_value(list_entry));
}
+
udev_list_entry_foreach(list_entry, udev_device_get_tags_list_entry(udev_device))
fprintf(f, "G:%s\n", udev_list_entry_get_name(list_entry));
}
diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c
index 28df7a2a11..e5950bb4b1 100644
--- a/libudev/libudev-device.c
+++ b/libudev/libudev-device.c
@@ -57,7 +57,6 @@ struct udev_device {
char *driver;
char *action;
char *devpath_old;
- char *knodename;
char *id_filename;
char **envp;
char *monitor_buf;
@@ -161,23 +160,6 @@ static int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
return 0;
}
-const char *udev_device_get_knodename(struct udev_device *udev_device)
-{
- return udev_device->knodename;
-}
-
-static int udev_device_set_knodename(struct udev_device *udev_device, const char *knodename)
-{
- free(udev_device->knodename);
- udev_device->knodename = strdup(knodename);
- if (udev_device->knodename == NULL)
- return -ENOMEM;
- /* do not overwrite the udev property with the kernel property */
- if (udev_device->devnode == NULL)
- udev_device_add_property(udev_device, "DEVNAME", udev_device->knodename);
- return 0;
-}
-
const char *udev_device_get_devpath_old(struct udev_device *udev_device)
{
return udev_device->devpath_old;
@@ -381,10 +363,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device,
} else if (strncmp(property, "DEVTYPE=", 8) == 0) {
udev_device_set_devtype(udev_device, &property[8]);
} else if (strncmp(property, "DEVNAME=", 8) == 0) {
- if (property[8] == '/')
- udev_device_set_devnode(udev_device, &property[8]);
- else
- udev_device_set_knodename(udev_device, &property[8]);
+ udev_device_set_devnode(udev_device, &property[8]);
} else if (strncmp(property, "DEVLINKS=", 9) == 0) {
char devlinks[UTIL_PATH_SIZE];
char *slink;
@@ -516,10 +495,6 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile)
line[len-1] = '\0';
val = &line[2];
switch(line[0]) {
- case 'N':
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
- udev_device_set_devnode(udev_device, filename);
- break;
case 'S':
util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
udev_device_add_devlink(udev_device, filename, 0);
@@ -582,7 +557,7 @@ int udev_device_read_uevent_file(struct udev_device *udev_device)
else if (strncmp(line, "IFINDEX=", 8) == 0)
udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10));
else if (strncmp(line, "DEVNAME=", 8) == 0)
- udev_device_set_knodename(udev_device, &line[8]);
+ udev_device_set_devnode(udev_device, &line[8]);
else if (strncmp(line, "DEVMODE=", 8) == 0)
udev_device->devnode_mode = strtoul(&line[8], NULL, 8);
@@ -1073,7 +1048,6 @@ UDEV_EXPORT 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->knodename);
free(udev_device->id_filename);
free(udev_device->envp);
free(udev_device->monitor_buf);
@@ -1152,21 +1126,10 @@ UDEV_EXPORT const char *udev_device_get_devnode(struct udev_device *udev_device)
{
if (udev_device == NULL)
return NULL;
- if (!udev_device->info_loaded) {
- udev_device_read_uevent_file(udev_device);
- udev_device_read_db(udev_device, NULL);
- }
-
- /* we might get called before we handled an event and have a db, use the kernel-provided name */
- if (udev_device->devnode == NULL && udev_device_get_knodename(udev_device) != NULL) {
- char filename[UTIL_NAME_SIZE];
-
- util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/",
- udev_device_get_knodename(udev_device), NULL);
- udev_device_set_devnode(udev_device, filename);
+ if (udev_device->devnode != NULL)
return udev_device->devnode;
- }
-
+ if (!udev_device->info_loaded)
+ udev_device_read_uevent_file(udev_device);
return udev_device->devnode;
}
@@ -1522,7 +1485,12 @@ int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath
int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode)
{
free(udev_device->devnode);
- udev_device->devnode = strdup(devnode);
+ if (devnode[0] != '/') {
+ if (asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), devnode) < 0)
+ udev_device->devnode = NULL;
+ } else {
+ udev_device->devnode = strdup(devnode);
+ }
if (udev_device->devnode == NULL)
return -ENOMEM;
udev_device_add_property(udev_device, "DEVNAME", udev_device->devnode);
diff --git a/libudev/libudev-private.h b/libudev/libudev-private.h
index b86f6a8378..83976698a9 100644
--- a/libudev/libudev-private.h
+++ b/libudev/libudev-private.h
@@ -83,7 +83,6 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile);
int udev_device_read_uevent_file(struct udev_device *udev_device);
int udev_device_set_action(struct udev_device *udev_device, const char *action);
const char *udev_device_get_devpath_old(struct udev_device *udev_device);
-const char *udev_device_get_knodename(struct udev_device *udev_device);
const char *udev_device_get_id_filename(struct udev_device *udev_device);
void udev_device_set_is_initialized(struct udev_device *udev_device);
int udev_device_add_tag(struct udev_device *udev_device, const char *tag);
@@ -187,7 +186,6 @@ uint64_t util_string_bloom64(const char *str);
int util_create_path(struct udev *udev, const char *path);
int util_create_path_selinux(struct udev *udev, const char *path);
int util_delete_path(struct udev *udev, const char *path);
-int util_unlink_secure(struct udev *udev, const char *filename);
uid_t util_lookup_user(struct udev *udev, const char *user);
gid_t util_lookup_group(struct udev *udev, const char *group);
int util_resolve_subsys_kernel(struct udev *udev, const char *string,
diff --git a/libudev/libudev-util-private.c b/libudev/libudev-util-private.c
index 2d7f8dc758..015e6d5862 100644
--- a/libudev/libudev-util-private.c
+++ b/libudev/libudev-util-private.c
@@ -113,23 +113,6 @@ int util_delete_path(struct udev *udev, const char *path)
return err;
}
-/* Reset permissions on the device node, before unlinking it to make sure,
- * that permissions of possible hard links will be removed too.
- */
-int util_unlink_secure(struct udev *udev, const char *filename)
-{
- int err;
-
- chown(filename, 0, 0);
- chmod(filename, 0000);
- err = unlink(filename);
- if (errno == ENOENT)
- err = 0;
- if (err)
- err(udev, "unlink(%s) failed: %m\n", filename);
- return err;
-}
-
uid_t util_lookup_user(struct udev *udev, const char *user)
{
char *endptr;
diff --git a/libudev/libudev.c b/libudev/libudev.c
index 93f2d8f1b5..ca2ac5d030 100644
--- a/libudev/libudev.c
+++ b/libudev/libudev.c
@@ -223,6 +223,10 @@ UDEV_EXPORT struct udev *udev_new(void)
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;
@@ -237,18 +241,6 @@ UDEV_EXPORT struct udev *udev_new(void)
if (env != NULL)
udev_set_log_priority(udev, util_log_priority(env));
- env = getenv("UDEV_ROOT");
- if (env != NULL) {
- set_value(&udev->dev_path, env);
- udev_add_property(udev, "UDEV_ROOT", udev->dev_path);
- }
-
- 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)
@@ -401,8 +393,8 @@ int udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *st
* @udev: udev library context
*
* Retrieve the sysfs mount point. The default is "/sys". For
- * testing purposes, it can be overridden with the environment
- * variable SYSFS_PATH.
+ * testing purposes, it can be overridden with udev_sys=
+ * in the udev configuration file.
*
* Returns: the sys mount point
**/