chiark / gitweb /
463473d7c726a762cf9229e338983fc72c5322a3
[elogind.git] / extras / run_directory / udev_run_hotplugd.c
1 /*
2  * udev_run_hotplugd.c - directory multiplexer
3  *
4  * Copyright (C) 2005 Kay Sievers <kay@vrfy.org>
5  *
6  *      This program is free software; you can redistribute it and/or modify it
7  *      under the terms of the GNU General Public License as published by the
8  *      Free Software Foundation version 2 of the License.
9  *
10  */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <stddef.h>
16 #include <dirent.h>
17 #include <errno.h>
18 #include <unistd.h>
19 #include <fcntl.h>
20 #include <limits.h>
21 #include <sys/types.h>
22 #include <sys/wait.h>
23 #include <sys/stat.h>
24
25 #include "../../udev_utils.h"
26 #include "../../list.h"
27 #include "../../logging.h"
28
29 extern int run_directory(const char *dir, const char *suffix, const char *subsystem);
30
31 #ifdef USE_LOG
32 void log_message (int priority, const char *format, ...)
33 {
34         va_list args;
35         static int udev_log = -1;
36
37         if (udev_log == -1) {
38                 const char *value;
39
40                 value = getenv("UDEV_LOG");
41                 if (value)
42                         udev_log = log_priority(value);
43                 else
44                         udev_log = LOG_ERR;
45         }
46
47         if (priority > udev_log)
48                 return;
49
50         va_start(args, format);
51         vsyslog(priority, format, args);
52         va_end(args);
53 }
54 #endif
55
56 int main(int argc, char *argv[], char *envp[])
57 {
58         const char *subsystem;
59         int fd;
60
61         if (getenv("DEVNAME") == NULL)
62                 exit(0);
63
64         subsystem = argv[1];
65         logging_init("udev_run_hotplugd");
66
67         fd = open("/dev/null", O_RDWR);
68         if (fd >= 0) {
69                 dup2(fd, STDOUT_FILENO);
70                 dup2(fd, STDIN_FILENO);
71                 dup2(fd, STDERR_FILENO);
72                 close(fd);
73         }
74
75         dbg("running dev.d directory");
76
77         run_directory("/etc/hotplug.d", ".hotplug", subsystem);
78         exit(0);
79 }