chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
udev: move dev.d/ handling to external helper
[elogind.git]
/
udevstart.c
diff --git
a/udevstart.c
b/udevstart.c
index 97d38490aea0cbf6f77bccfe9a5e7f377a5461db..34f3835d65f3e0026805489736240b1afb3c6769 100644
(file)
--- a/
udevstart.c
+++ b/
udevstart.c
@@
-36,22
+36,32
@@
#include <sys/types.h>
#include "libsysfs/sysfs/libsysfs.h"
#include <sys/types.h>
#include "libsysfs/sysfs/libsysfs.h"
+#include "udev_libc_wrapper.h"
+#include "udev.h"
+#include "udev_version.h"
#include "logging.h"
#include "logging.h"
-#include "
namedev
.h"
+#include "
udev_rules
.h"
#include "udev_utils.h"
#include "list.h"
#include "udev_utils.h"
#include "list.h"
-#include "udev.h"
#ifdef USE_LOG
#ifdef USE_LOG
-void log_message(int
level
, const char *format, ...)
+void log_message(int
priority
, const char *format, ...)
{
{
+ va_list args;
+
+ if (priority > udev_log_priority)
+ return;
+
+ va_start(args, format);
+ vsyslog(priority, format, args);
+ va_end(args);
}
#endif
struct device {
}
#endif
struct device {
- struct list_head
list
;
- char path[
DEV
PATH_SIZE];
- char subsys[
SUBSYSTEM
_SIZE];
+ struct list_head
node
;
+ char path[PATH_SIZE];
+ char subsys[
NAME
_SIZE];
};
/* sort files in lexical order */
};
/* sort files in lexical order */
@@
-62,7
+72,7
@@
static int device_list_insert(const char *path, char *subsystem, struct list_hea
dbg("insert: '%s'\n", path);
dbg("insert: '%s'\n", path);
- list_for_each_entry(loop_device, device_list,
list
) {
+ list_for_each_entry(loop_device, device_list,
node
) {
if (strcmp(loop_device->path, path) > 0) {
break;
}
if (strcmp(loop_device->path, path) > 0) {
break;
}
@@
-74,9
+84,9
@@
static int device_list_insert(const char *path, char *subsystem, struct list_hea
return -ENOMEM;
}
return -ENOMEM;
}
- str
fieldcpy(new_device->path, path
);
- str
fieldcpy(new_device->subsys, subsystem
);
- list_add_tail(&new_device->
list, &loop_device->list
);
+ str
lcpy(new_device->path, path, sizeof(new_device->path)
);
+ str
lcpy(new_device->subsys, subsystem, sizeof(new_device->subsys)
);
+ list_add_tail(&new_device->
node, &loop_device->node
);
dbg("add '%s' from subsys '%s'", new_device->path, new_device->subsys);
return 0;
}
dbg("add '%s' from subsys '%s'", new_device->path, new_device->subsys);
return 0;
}
@@
-113,13
+123,18
@@
static int add_device(const char *path, const char *subsystem)
return -ENODEV;
}
return -ENODEV;
}
- udev_init_device(&udev, devpath, subsystem);
+ udev_init_device(&udev, devpath, subsystem
, "add"
);
udev_add_device(&udev, class_dev);
udev_add_device(&udev, class_dev);
- /* run dev.d/ scripts if we created a node or changed a netif name */
- if (udev_dev_d && udev.devname[0] != '\0') {
+ if (udev.devname[0] != '\0')
setenv("DEVNAME", udev.devname, 1);
setenv("DEVNAME", udev.devname, 1);
- udev_multiplex_directory(&udev, DEVD_DIR, DEVD_SUFFIX);
+
+ if (udev_run && !list_empty(&udev.run_list)) {
+ struct name_entry *name_loop;
+
+ dbg("executing run list");
+ list_for_each_entry(name_loop, &udev.run_list, node)
+ execute_command(name_loop->name, udev.subsystem);
}
sysfs_close_class_device(class_dev);
}
sysfs_close_class_device(class_dev);
@@
-135,11
+150,11
@@
static void exec_list(struct list_head *device_list)
int i;
/* handle the "first" type devices first */
int i;
/* handle the "first" type devices first */
- list_for_each_entry_safe(loop_device, tmp_device, device_list,
list
) {
+ list_for_each_entry_safe(loop_device, tmp_device, device_list,
node
) {
for (i = 0; first_list[i] != NULL; i++) {
if (strncmp(loop_device->path, first_list[i], strlen(first_list[i])) == 0) {
add_device(loop_device->path, loop_device->subsys);
for (i = 0; first_list[i] != NULL; i++) {
if (strncmp(loop_device->path, first_list[i], strlen(first_list[i])) == 0) {
add_device(loop_device->path, loop_device->subsys);
- list_del(&loop_device->
list
);
+ list_del(&loop_device->
node
);
free(loop_device);
break;
}
free(loop_device);
break;
}
@@
-147,7
+162,7
@@
static void exec_list(struct list_head *device_list)
}
/* handle the devices we are allowed to, excluding the "last" type devices */
}
/* handle the devices we are allowed to, excluding the "last" type devices */
- list_for_each_entry_safe(loop_device, tmp_device, device_list,
list
) {
+ list_for_each_entry_safe(loop_device, tmp_device, device_list,
node
) {
int found = 0;
for (i = 0; last_list[i] != NULL; i++) {
if (strncmp(loop_device->path, last_list[i], strlen(last_list[i])) == 0) {
int found = 0;
for (i = 0; last_list[i] != NULL; i++) {
if (strncmp(loop_device->path, last_list[i], strlen(last_list[i])) == 0) {
@@
-159,25
+174,25
@@
static void exec_list(struct list_head *device_list)
continue;
add_device(loop_device->path, loop_device->subsys);
continue;
add_device(loop_device->path, loop_device->subsys);
- list_del(&loop_device->
list
);
+ list_del(&loop_device->
node
);
free(loop_device);
}
/* handle the rest of the devices left over, if any */
free(loop_device);
}
/* handle the rest of the devices left over, if any */
- list_for_each_entry_safe(loop_device, tmp_device, device_list,
list
) {
+ list_for_each_entry_safe(loop_device, tmp_device, device_list,
node
) {
add_device(loop_device->path, loop_device->subsys);
add_device(loop_device->path, loop_device->subsys);
- list_del(&loop_device->
list
);
+ list_del(&loop_device->
node
);
free(loop_device);
}
}
static int has_devt(const char *directory)
{
free(loop_device);
}
}
static int has_devt(const char *directory)
{
- char filename[
NAME
_SIZE];
+ char filename[
PATH
_SIZE];
struct stat statbuf;
struct stat statbuf;
- snprintf(filename,
NAME_SIZE
, "%s/dev", directory);
- filename[
NAME_SIZE
-1] = '\0';
+ snprintf(filename,
sizeof(filename)
, "%s/dev", directory);
+ filename[
sizeof(filename)
-1] = '\0';
if (stat(filename, &statbuf) == 0)
return 1;
if (stat(filename, &statbuf) == 0)
return 1;
@@
-187,26
+202,26
@@
static int has_devt(const char *directory)
static void udev_scan_block(void)
{
static void udev_scan_block(void)
{
- char base[
NAME
_SIZE];
+ char base[
PATH
_SIZE];
DIR *dir;
struct dirent *dent;
LIST_HEAD(device_list);
DIR *dir;
struct dirent *dent;
LIST_HEAD(device_list);
- snprintf(base,
DEVPATH_SIZE
, "%s/block", sysfs_path);
- base[
DEVPATH_SIZE
-1] = '\0';
+ snprintf(base,
sizeof(base)
, "%s/block", sysfs_path);
+ base[
sizeof(base)
-1] = '\0';
dir = opendir(base);
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
dir = opendir(base);
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[
DEV
PATH_SIZE];
+ char dirname[PATH_SIZE];
DIR *dir2;
struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
DIR *dir2;
struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
- snprintf(dirname,
NAME_SIZE
, "%s/%s", base, dent->d_name);
- dirname[
NAME_SIZE
-1] = '\0';
+ snprintf(dirname,
sizeof(dirname)
, "%s/%s", base, dent->d_name);
+ dirname[
sizeof(dirname)
-1] = '\0';
if (has_devt(dirname))
device_list_insert(dirname, "block", &device_list);
else
if (has_devt(dirname))
device_list_insert(dirname, "block", &device_list);
else
@@
-216,13
+231,13
@@
static void udev_scan_block(void)
dir2 = opendir(dirname);
if (dir2 != NULL) {
for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
dir2 = opendir(dirname);
if (dir2 != NULL) {
for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[
DEV
PATH_SIZE];
+ char dirname2[PATH_SIZE];
if (dent2->d_name[0] == '.')
continue;
if (dent2->d_name[0] == '.')
continue;
- snprintf(dirname2,
DEVPATH_SIZE
, "%s/%s", dirname, dent2->d_name);
- dirname2[
DEVPATH_SIZE
-1] = '\0';
+ snprintf(dirname2,
sizeof(dirname2)
, "%s/%s", dirname, dent2->d_name);
+ dirname2[
sizeof(dirname2)
-1] = '\0';
if (has_devt(dirname2))
device_list_insert(dirname2, "block", &device_list);
if (has_devt(dirname2))
device_list_insert(dirname2, "block", &device_list);
@@
-237,37
+252,37
@@
static void udev_scan_block(void)
static void udev_scan_class(void)
{
static void udev_scan_class(void)
{
- char base[
DEV
PATH_SIZE];
+ char base[PATH_SIZE];
DIR *dir;
struct dirent *dent;
LIST_HEAD(device_list);
DIR *dir;
struct dirent *dent;
LIST_HEAD(device_list);
- snprintf(base,
DEVPATH_SIZE
, "%s/class", sysfs_path);
- base[
DEVPATH_SIZE
-1] = '\0';
+ snprintf(base,
sizeof(base)
, "%s/class", sysfs_path);
+ base[
sizeof(base)
-1] = '\0';
dir = opendir(base);
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
dir = opendir(base);
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[
DEV
PATH_SIZE];
+ char dirname[PATH_SIZE];
DIR *dir2;
struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
DIR *dir2;
struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
- snprintf(dirname,
DEVPATH_SIZE
, "%s/%s", base, dent->d_name);
- dirname[
DEVPATH_SIZE
-1] = '\0';
+ snprintf(dirname,
sizeof(dirname)
, "%s/%s", base, dent->d_name);
+ dirname[
sizeof(dirname)
-1] = '\0';
dir2 = opendir(dirname);
if (dir2 != NULL) {
for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
dir2 = opendir(dirname);
if (dir2 != NULL) {
for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[
DEV
PATH_SIZE];
+ char dirname2[PATH_SIZE];
if (dent2->d_name[0] == '.')
continue;
if (dent2->d_name[0] == '.')
continue;
- snprintf(dirname2,
DEVPATH_SIZE
, "%s/%s", dirname, dent2->d_name);
- dirname2[
DEVPATH_SIZE
-1] = '\0';
+ snprintf(dirname2,
sizeof(dirname2)
, "%s/%s", dirname, dent2->d_name);
+ dirname2[
sizeof(dirname2)
-1] = '\0';
/* pass the net class as it is */
if (strcmp(dent->d_name, "net") == 0)
/* pass the net class as it is */
if (strcmp(dent->d_name, "net") == 0)
@@
-298,7
+313,12
@@
int main(int argc, char *argv[], char *envp[])
{
struct sigaction act;
{
struct sigaction act;
+ logging_init("udev");
udev_init_config();
udev_init_config();
+ /* disable all logging if not explicitely requested */
+ if (getenv("UDEV_LOG") == NULL)
+ udev_log_priority = 0;
+ dbg("version %s", UDEV_VERSION);
/* set signal handlers */
memset(&act, 0x00, sizeof(act));
/* set signal handlers */
memset(&act, 0x00, sizeof(act));
@@
-316,10
+336,11
@@
int main(int argc, char *argv[], char *envp[])
setenv("ACTION", "add", 1);
setenv("UDEV_START", "1", 1);
setenv("ACTION", "add", 1);
setenv("UDEV_START", "1", 1);
-
namedev
_init();
+
udev_rules
_init();
udev_scan_block();
udev_scan_class();
udev_scan_block();
udev_scan_class();
+ logging_close();
return 0;
}
return 0;
}