summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udev-builtin-firmware.c18
-rw-r--r--src/udev/udev-builtin-kmod.c2
-rw-r--r--src/udev/udev-builtin-net_id.c2
-rw-r--r--src/udev/udev-ctrl.c17
-rw-r--r--src/udev/udev-event.c7
-rw-r--r--src/udev/udev-node.c30
-rw-r--r--src/udev/udev-rules.c17
-rw-r--r--src/udev/udev.h2
-rw-r--r--src/udev/udev.pc.in6
-rw-r--r--src/udev/udevadm-info.c8
-rw-r--r--src/udev/udevadm-trigger.c2
-rw-r--r--src/udev/udevd.c128
12 files changed, 36 insertions, 203 deletions
diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c
index 4a91d33575..a23b8c1a46 100644
--- a/src/udev/udev-builtin-firmware.c
+++ b/src/udev/udev-builtin-firmware.c
@@ -78,8 +78,6 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo
{
struct udev *udev = udev_device_get_udev(dev);
static const char *searchpath[] = { FIRMWARE_PATH };
- char fwencpath[UTIL_PATH_SIZE];
- char misspath[UTIL_PATH_SIZE];
char loadpath[UTIL_PATH_SIZE];
char datapath[UTIL_PATH_SIZE];
char fwpath[UTIL_PATH_SIZE];
@@ -111,23 +109,10 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo
break;
}
- util_path_encode(firmware, fwencpath, sizeof(fwencpath));
- 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) {
- int err;
-
- /* This link indicates the missing firmware file and the associated device */
log_debug("did not find firmware file '%s'\n", firmware);
- do {
- err = mkdir_parents(misspath, 0755);
- if (err != 0 && err != -ENOENT)
- break;
- err = symlink(udev_device_get_devpath(dev), misspath);
- if (err != 0)
- err = -errno;
- } while (err == -ENOENT);
rc = EXIT_FAILURE;
/*
* Do not cancel the request in the initrd, the real root might have
@@ -146,9 +131,6 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo
goto exit;
}
- if (unlink(misspath) == 0)
- util_delete_path(udev, misspath);
-
if (!set_loading(udev, loadpath, "1"))
goto exit;
diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c
index 300090a5b9..d2148a8ab2 100644
--- a/src/udev/udev-builtin-kmod.c
+++ b/src/udev/udev-builtin-kmod.c
@@ -37,7 +37,7 @@
static struct kmod_ctx *ctx;
-static int load_module(struct udev *udev, char *const alias)
+static int load_module(struct udev *udev, const char *alias)
{
#ifdef HAVE_LIBKMOD
struct kmod_list *list = NULL;
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 36eec5aec0..d6cb196d4c 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -24,6 +24,8 @@
* - physical/geographical location of the hardware
* - the interface's MAC address
*
+ * http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames
+ *
* Two character prefixes based on the type of interface:
* en -- ethernet
* wl -- wlan
diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c
index c0c3fe5ae7..4586b014e7 100644
--- a/src/udev/udev-ctrl.c
+++ b/src/udev/udev-ctrl.c
@@ -10,7 +10,6 @@
*/
#include <errno.h>
-#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
@@ -191,24 +190,8 @@ struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl)
#if HAVE_DECL_ACCEPT4
conn->sock = accept4(uctrl->sock, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK);
-
- /* Fallback path when accept4() is unavailable */
- if ( conn->sock < 0 && (errno == ENOSYS || errno == ENOTSUP) )
- {
- conn->sock = accept(uctrl->sock, NULL, NULL);
-
- if (conn->sock >= 0) {
- fcntl(conn->sock, F_SETFL, O_NONBLOCK);
- fcntl(conn->sock, F_SETFD, FD_CLOEXEC);
- }
- }
#else
conn->sock = accept(uctrl->sock, NULL, NULL);
-
- if (conn->sock >= 0) {
- fcntl(conn->sock, F_SETFL, O_NONBLOCK);
- fcntl(conn->sock, F_SETFD, FD_CLOEXEC);
- }
#endif
if (conn->sock < 0) {
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 01b503ef1c..d1880efe50 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 Kay Sievers <kay@vrfy.org>
+ * Copyright (C) 2003-2013 Kay Sievers <kay@vrfy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -845,6 +845,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
}
if (major(udev_device_get_devnum(dev)) > 0) {
+ bool apply;
+
/* remove/update possible left-over symlinks from old database entry */
if (event->dev_db != NULL)
udev_node_update_old_links(dev, event->dev_db);
@@ -868,7 +870,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
}
}
- udev_node_add(dev, event->mode, event->uid, event->gid);
+ apply = streq(udev_device_get_action(dev), "add") || event->owner_set || event->group_set || event->mode_set;
+ udev_node_add(dev, apply, event->mode, event->uid, event->gid);
}
/* preserve old, or get new initialization timestamp */
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index 23df10f0f9..d10c63aaa0 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 Kay Sievers <kay@vrfy.org>
+ * Copyright (C) 2003-2013 Kay Sievers <kay@vrfy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,15 +31,13 @@
#include "udev.h"
-#define TMP_FILE_EXT ".udev-tmp"
-
-static int node_symlink(struct udev *udev, const char *node, const char *slink)
+static int node_symlink(struct udev_device *dev, const char *node, const char *slink)
{
struct stat stats;
char target[UTIL_PATH_SIZE];
char *s;
size_t l;
- char slink_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)];
+ char slink_tmp[UTIL_PATH_SIZE + 32];
int i = 0;
int tail = 0;
int err = 0;
@@ -101,7 +99,7 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink)
}
log_debug("atomically replace '%s'\n", slink);
- util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL);
+ util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, ".tmp-", udev_device_get_id_filename(dev), NULL);
unlink(slink_tmp);
do {
err = mkdir_parents_label(slink_tmp, 0755);
@@ -204,7 +202,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add)
util_delete_path(udev, slink);
} else {
log_debug("creating link '%s' to '%s'\n", slink, target);
- node_symlink(udev, target, slink);
+ node_symlink(dev, target, slink);
}
if (add) {
@@ -254,7 +252,7 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev
}
}
-static int node_fixup(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid)
+static int node_permissions_apply(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, gid_t gid)
{
const char *devnode = udev_device_get_devnode(dev);
dev_t devnum = udev_device_get_devnum(dev);
@@ -279,13 +277,7 @@ static int node_fixup(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid
goto out;
}
- /*
- * Set permissions and selinux file context only on add events. We always
- * set it on bootup (coldplug) with "trigger --action=add" for all devices
- * and for any newly added devices (hotplug). We don't want to change it
- * later, in case something else has applied custom settings in the meantime.
- */
- if (strcmp(udev_device_get_action(dev), "add") == 0) {
+ if (apply) {
if ((stats.st_mode & 0777) != (mode & 0777) || stats.st_uid != uid || stats.st_gid != gid) {
log_debug("set permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
chmod(devnode, mode);
@@ -294,7 +286,6 @@ static int node_fixup(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid
} else {
log_debug("preserve permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
}
-
label_fix(devnode, true, false);
}
@@ -304,23 +295,22 @@ out:
return err;
}
-void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid)
+void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, gid_t gid)
{
- struct udev *udev = udev_device_get_udev(dev);
char filename[UTIL_PATH_SIZE];
struct udev_list_entry *list_entry;
log_debug("handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d\n",
udev_device_get_devnode(dev), udev_device_get_id_filename(dev), mode, uid, gid);
- if (node_fixup(dev, mode, uid, gid) < 0)
+ if (node_permissions_apply(dev, apply, mode, uid, gid) < 0)
return;
/* always add /dev/{block,char}/$major:$minor */
snprintf(filename, sizeof(filename), "/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);
+ node_symlink(dev, udev_device_get_devnode(dev), filename);
/* create/update symlinks, add symlinks to name index */
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev))
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 0fcad5d7e9..0561e01567 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1600,21 +1600,6 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
if (!rules->strbuf)
return udev_rules_unref(rules);
- /* Note - need a better way to manage these paths:
- * ie, should have a list of paths we always support, and
- * do not include the #define vars if they are duplicates
- *
- * original - UDEV_RULES_DIR should be /etc/udev/rules.d
- * ..but we have it set to UDEV_LIBEXEC_DIR "/rules.d" so that
- * ..the default rules are installed there instead of in /etc
- *
- * original2 - UDEV_LIBEXEC_DIR used to be forced to /usr/lib/udev
- * ..by default, we have it as /lib/udev (or whatever rootlibdir is)
- * ..therefore we did not include /usr/lib/udev/rules.d.
- *
- * Reworked code; there are duplicate paths here but at least
- * everyting is listed.
- */
rules->dirs = strv_new(UDEV_CONF_DIR "/rules.d",
UDEV_RULES_DIR,
"/run/udev/rules.d",
@@ -1639,7 +1624,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
return udev_rules_unref(rules);
udev_rules_check_timestamp(rules);
- r = conf_files_list_strv(&files, NULL, ".rules", (const char **)rules->dirs);
+ r = conf_files_list_strv(&files, ".rules", NULL, (const char **)rules->dirs);
if (r < 0) {
log_error("failed to enumerate rules files: %s\n", strerror(-r));
return udev_rules_unref(rules);
diff --git a/src/udev/udev.h b/src/udev/udev.h
index 5418261b55..6d3b42a30d 100644
--- a/src/udev/udev.h
+++ b/src/udev/udev.h
@@ -95,7 +95,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev);
struct udev_device *udev_watch_lookup(struct udev *udev, int wd);
/* udev-node.c */
-void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid);
+void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, gid_t gid);
void udev_node_remove(struct udev_device *dev);
void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old);
diff --git a/src/udev/udev.pc.in b/src/udev/udev.pc.in
index 092f1c6ed0..4f6381eb7a 100644
--- a/src/udev/udev.pc.in
+++ b/src/udev/udev.pc.in
@@ -1,7 +1,7 @@
+Name: udev
+Description: eudev
+Version: @UDEV_VERSION@
prefix=@prefix@
exec_prefix=@exec_prefix@
udevdir=@udevlibexecdir@
-Name: udev
-Description: Part of eudev
-Version: @UDEV_VERSION@
diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c
index 5fbc77803b..75510c5178 100644
--- a/src/udev/udevadm-info.c
+++ b/src/udev/udevadm-info.c
@@ -33,7 +33,7 @@
static bool skip_attribute(const char *name)
{
- static const char const *skip[] = {
+ static const char* const skip[] = {
"uevent",
"dev",
"modalias",
@@ -256,12 +256,6 @@ static void cleanup_db(struct udev *udev)
cleanup_dir(dir, 0, 1);
closedir(dir);
}
-
- dir = opendir("/run/udev/firmware-missing");
- if (dir != NULL) {
- cleanup_dir(dir, 0, 1);
- closedir(dir);
- }
}
static struct udev_device *find_device(struct udev *udev, const char *id, const char *prefix)
diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c
index d52ae461fe..d8960f997d 100644
--- a/src/udev/udevadm-trigger.c
+++ b/src/udev/udevadm-trigger.c
@@ -214,7 +214,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
exec_list(udev_enumerate, action);
goto exit;
default:
- goto exit;
+ assert_not_reached("device_type");
}
exit:
udev_enumerate_unref(udev_enumerate);
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index fc9cc37b13..0034fa344e 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -818,7 +818,11 @@ static void static_dev_create_from_modules(struct udev *udev)
char buf[4096];
FILE *f;
- uname(&kernel);
+ if (uname(&kernel) < 0) {
+ log_error("uname failed: %m");
+ return;
+ }
+
util_strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", kernel.release, "/modules.devname", NULL);
f = fopen(modules, "re");
if (f == NULL)
@@ -878,113 +882,6 @@ static void static_dev_create_from_modules(struct udev *udev)
fclose(f);
}
-static int mem_size_mb(void)
-{
- FILE *f;
- char buf[4096];
- long int memsize = -1;
-
- f = fopen("/proc/meminfo", "re");
- if (f == NULL)
- return -1;
-
- while (fgets(buf, sizeof(buf), f) != NULL) {
- long int value;
-
- if (sscanf(buf, "MemTotal: %ld kB", &value) == 1) {
- memsize = value / 1024;
- break;
- }
- }
-
- fclose(f);
- return memsize;
-}
-
-static int convert_db(struct udev *udev)
-{
- char filename[UTIL_PATH_SIZE];
- struct udev_enumerate *udev_enumerate;
- struct udev_list_entry *list_entry;
-
- /* current database */
- if (access("/run/udev/data", F_OK) >= 0)
- return 0;
-
- /* make sure we do not get here again */
- mkdir_p("/run/udev/data", 0755);
-
- /* old database */
- util_strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL);
- if (access(filename, F_OK) < 0)
- return 0;
-
- print_kmsg("converting old udev database\n");
-
- udev_enumerate = udev_enumerate_new(udev);
- if (udev_enumerate == NULL)
- return -1;
- udev_enumerate_scan_devices(udev_enumerate);
- udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate)) {
- struct udev_device *device;
-
- device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry));
- if (device == NULL)
- continue;
-
- /* try to find the old database for devices without a current one */
- if (udev_device_read_db(device, NULL) < 0) {
- bool have_db;
- const char *id;
- struct stat stats;
- char devpath[UTIL_PATH_SIZE];
- char from[UTIL_PATH_SIZE];
-
- have_db = false;
-
- /* find database in old location */
- id = udev_device_get_id_filename(device);
- util_strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL);
- if (lstat(from, &stats) == 0) {
- if (!have_db) {
- udev_device_read_db(device, from);
- have_db = true;
- }
- unlink(from);
- }
-
- /* find old database with $subsys:$sysname name */
- 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);
- have_db = true;
- }
- unlink(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), "/dev/.udev/db/", devpath, NULL);
- if (lstat(from, &stats) == 0) {
- if (!have_db) {
- udev_device_read_db(device, from);
- have_db = true;
- }
- unlink(from);
- }
-
- /* write out new database */
- if (have_db)
- udev_device_update_db(device);
- }
- udev_device_unref(device);
- }
- udev_enumerate_unref(udev_enumerate);
- return 0;
-}
-
/*
* read the kernel commandline, in case we need to get into debug mode
* udev.log-priority=<level> syslog priority
@@ -1304,17 +1201,14 @@ int main(int argc, char *argv[])
goto exit;
}
- /* if needed, convert old database from earlier udev version */
- convert_db(udev);
-
if (children_max <= 0) {
- int memsize = mem_size_mb();
+ cpu_set_t cpu_set;
- /* set value depending on the amount of RAM */
- if (memsize > 0)
- children_max = 16 + (memsize / 8);
- else
- children_max = 16;
+ children_max = 8;
+
+ if (sched_getaffinity(0, sizeof (cpu_set), &cpu_set) == 0) {
+ children_max += CPU_COUNT(&cpu_set) * 2;
+ }
}
log_debug("set children_max to %u\n", children_max);