chiark / gitweb /
[PATCH] move execute_program to utils + add action to init_device
[elogind.git] / udevstart.c
index 6b032a199969818dc9744a780ed4cb8762a63a64..4bd47958742da97e4ba1a45193fbdbd4972ab76e 100644 (file)
 #include "libsysfs/sysfs/libsysfs.h"
 #include "udev_libc_wrapper.h"
 #include "udev.h"
+#include "udev_version.h"
 #include "logging.h"
-#include "namedev.h"
+#include "udev_rules.h"
 #include "udev_utils.h"
 #include "list.h"
 
 #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 {
-       struct list_head list;
+       struct list_head node;
        char path[PATH_SIZE];
        char subsys[NAME_SIZE];
 };
@@ -63,7 +72,7 @@ static int device_list_insert(const char *path, char *subsystem, struct list_hea
 
        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;
                }
@@ -77,7 +86,7 @@ static int device_list_insert(const char *path, char *subsystem, struct list_hea
 
        strlcpy(new_device->path, path, sizeof(new_device->path));
        strlcpy(new_device->subsys, subsystem, sizeof(new_device->subsys));
-       list_add_tail(&new_device->list, &loop_device->list);
+       list_add_tail(&new_device->node, &loop_device->node);
        dbg("add '%s' from subsys '%s'", new_device->path, new_device->subsys);
        return 0;
 }
@@ -114,7 +123,7 @@ static int add_device(const char *path, const char *subsystem)
                return -ENODEV;
        }
 
-       udev_init_device(&udev, devpath, subsystem);
+       udev_init_device(&udev, devpath, subsystem, "add");
        udev_add_device(&udev, class_dev);
 
        /* run dev.d/ scripts if we created a node or changed a netif name */
@@ -136,11 +145,11 @@ static void exec_list(struct list_head *device_list)
        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);
-                               list_del(&loop_device->list);
+                               list_del(&loop_device->node);
                                free(loop_device);
                                break;
                        }
@@ -148,7 +157,7 @@ static void exec_list(struct list_head *device_list)
        }
 
        /* 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) {
@@ -160,14 +169,14 @@ static void exec_list(struct list_head *device_list)
                        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 */
-       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);
-               list_del(&loop_device->list);
+               list_del(&loop_device->node);
                free(loop_device);
        }
 }
@@ -299,7 +308,12 @@ int main(int argc, char *argv[], char *envp[])
 {
        struct sigaction act;
 
+       logging_init("udev");
        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));
@@ -317,10 +331,11 @@ int main(int argc, char *argv[], char *envp[])
        setenv("ACTION", "add", 1);
        setenv("UDEV_START", "1", 1);
 
-       namedev_init();
+       udev_rules_init();
 
        udev_scan_block();
        udev_scan_class();
 
+       logging_close();
        return 0;
 }