chiark / gitweb /
extras/keymap: add recently added keymap files to Makefile.am
[elogind.git] / udev / udevd.c
index 14736366d0d299d88d0a3288f5ef0b42357c3774..69d509ce915baddcd9fd5ed25d961d9477e0f75c 100644 (file)
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <time.h>
 #include <getopt.h>
 #include <dirent.h>
+#include <sys/time.h>
 #include <sys/prctl.h>
 #include <sys/socket.h>
 #include <sys/signalfd.h>
 #define UDEVD_PRIORITY                 -4
 #define UDEV_PRIORITY                  -2
 
-static int debug;
+static bool debug;
 
 static void log_fn(struct udev *udev, int priority,
                   const char *file, int line, const char *fn,
                   const char *format, va_list args)
 {
        if (debug) {
-               fprintf(stderr, "[%d] %s: ", (int) getpid(), fn);
-               vfprintf(stderr, format, args);
+               char buf[1024];
+               struct timeval tv;
+               struct timezone tz;
+
+               vsnprintf(buf, sizeof(buf), format, args);
+               gettimeofday(&tv, &tz);
+               fprintf(stderr, "%llu.%06u [%u] %s: %s",
+                       (unsigned long long) tv.tv_sec, (unsigned int) tv.tv_usec,
+                       (int) getpid(), fn, buf);
        } else {
                vsyslog(priority, format, args);
        }
 }
 
-static int debug_trace;
+static bool debug_trace;
 static struct udev_rules *rules;
 static struct udev_queue_export *udev_queue_export;
 static struct udev_ctrl *udev_ctrl;
 static struct udev_monitor *monitor;
 static int worker_watch[2];
 static pid_t settle_pid;
-static int stop_exec_queue;
-static int reload_config;
+static bool stop_exec_queue;
+static bool reload_config;
 static int max_childs;
 static int childs;
 static struct udev_list_node event_list;
 static struct udev_list_node worker_list;
-static int udev_exit;
+static bool udev_exit;
 static volatile sig_atomic_t worker_exit;
 
 enum poll_fd {
@@ -173,7 +182,7 @@ static void event_sig_handler(int signum)
                _exit(1);
                break;
        case SIGTERM:
-               worker_exit = 1;
+               worker_exit = true;
                break;
        }
 }
@@ -265,6 +274,7 @@ static void worker_new(struct event *event)
                        struct worker_message msg;
                        int err;
 
+                       info(event->udev, "seq %llu running\n", udev_device_get_seqnum(dev));
                        udev_event = udev_event_new(dev);
                        if (udev_event == NULL)
                                _exit(3);
@@ -588,17 +598,17 @@ static void handle_ctrl_msg(struct udev_ctrl *uctrl)
 
        if (udev_ctrl_get_stop_exec_queue(ctrl_msg) > 0) {
                info(udev, "udevd message (STOP_EXEC_QUEUE) received\n");
-               stop_exec_queue = 1;
+               stop_exec_queue = true;
        }
 
        if (udev_ctrl_get_start_exec_queue(ctrl_msg) > 0) {
                info(udev, "udevd message (START_EXEC_QUEUE) received\n");
-               stop_exec_queue = 0;
+               stop_exec_queue = false;
        }
 
        if (udev_ctrl_get_reload_rules(ctrl_msg) > 0) {
                info(udev, "udevd message (RELOAD_RULES) received\n");
-               reload_config = 1;
+               reload_config = true;
        }
 
        str = udev_ctrl_get_set_env(ctrl_msg);
@@ -667,7 +677,7 @@ static int handle_inotify(struct udev *udev)
                ev = (struct inotify_event *)(buf + pos);
                if (ev->len) {
                        dbg(udev, "inotify event: %x for %s\n", ev->mask, ev->name);
-                       reload_config = 1;
+                       reload_config = true;
                        continue;
                }
 
@@ -702,7 +712,7 @@ static void handle_signal(struct udev *udev, int signo)
        switch (signo) {
        case SIGINT:
        case SIGTERM:
-               udev_exit = 1;
+               udev_exit = true;
                break;
        case SIGCHLD:
                while (1) {
@@ -737,7 +747,7 @@ static void handle_signal(struct udev *udev, int signo)
                }
                break;
        case SIGHUP:
-               reload_config = 1;
+               reload_config = true;
                break;
        }
 }
@@ -775,7 +785,7 @@ int main(int argc, char *argv[])
        int fd;
        sigset_t mask;
        const char *value;
-       int daemonize = 0;
+       int daemonize = false;
        int resolve_names = 1;
        static const struct option options[] = {
                { "daemon", no_argument, NULL, 'd' },
@@ -806,13 +816,13 @@ int main(int argc, char *argv[])
 
                switch (option) {
                case 'd':
-                       daemonize = 1;
+                       daemonize = true;
                        break;
                case 't':
-                       debug_trace = 1;
+                       debug_trace = true;
                        break;
                case 'D':
-                       debug = 1;
+                       debug = true;
                        if (udev_get_log_priority(udev) < LOG_INFO)
                                udev_set_log_priority(udev, LOG_INFO);
                        break;