|
Lines 19-31
Link Here
|
| 19 |
* |
19 |
* |
| 20 |
*/ |
20 |
*/ |
| 21 |
|
21 |
|
|
|
22 |
#define _GNU_SOURCE |
| 22 |
#include <errno.h> |
23 |
#include <errno.h> |
| 23 |
#include <string.h> |
24 |
#include <string.h> |
| 24 |
#include <stdlib.h> |
25 |
#include <stdlib.h> |
| 25 |
#include <stdio.h> |
26 |
#include <stdio.h> |
|
|
27 |
#include <fcntl.h> |
| 26 |
#include <unistd.h> |
28 |
#include <unistd.h> |
| 27 |
#include <dirent.h> |
29 |
#include <dirent.h> |
| 28 |
#include <fcntl.h> |
|
|
| 29 |
#include <limits.h> |
30 |
#include <limits.h> |
| 30 |
#include <sys/stat.h> |
31 |
#include <sys/stat.h> |
| 31 |
#include <sys/vfs.h> |
32 |
#include <sys/vfs.h> |
|
Lines 49-65
extern char * const env[];
Link Here
|
| 49 |
static pid_t udevd_pid; |
50 |
static pid_t udevd_pid; |
| 50 |
|
51 |
|
| 51 |
|
52 |
|
| 52 |
static void spawn_wait(char * const command[], const char *message) |
53 |
static pid_t spawn_silent(char * const command[], const char *log) |
| 53 |
{ |
|
|
| 54 |
int status = 0; |
| 55 |
|
| 56 |
if (waitpid(spawn(command), &status, 0) < 0 || !(WIFEXITED(status))) { |
| 57 |
warn(message); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
static void spawn_silent(char * const command[]) |
| 63 |
{ |
54 |
{ |
| 64 |
int fd = 0; |
55 |
int fd = 0; |
| 65 |
pid_t pid = fork(); |
56 |
pid_t pid = fork(); |
|
Lines 67-85
static void spawn_silent(char * const command[])
Link Here
|
| 67 |
if (pid < 0) |
58 |
if (pid < 0) |
| 68 |
fatal(command[0]); |
59 |
fatal(command[0]); |
| 69 |
else if (pid == 0) { |
60 |
else if (pid == 0) { |
| 70 |
fd = open("/dev/null", O_WRONLY, 0666); |
61 |
if (log) |
| 71 |
if (fd >= 0) { |
62 |
fd = creat(log, 0640); |
| 72 |
dup2(fd, 1); |
63 |
else |
| 73 |
dup2(fd, 2); |
64 |
fd = open(log = "/dev/null", O_WRONLY, 0644); |
| 74 |
close(fd); |
65 |
if (fd < 0) |
| 75 |
} |
66 |
fatal(log); |
|
|
67 |
close(1); |
| 68 |
close(2); |
| 69 |
dup3(fd, 1, O_CLOEXEC); |
| 70 |
dup3(1, 2, O_CLOEXEC); |
| 71 |
close(fd); |
| 76 |
execve(command[0], &command[1], env); |
72 |
execve(command[0], &command[1], env); |
| 77 |
perror(command[0]); |
73 |
fatal(command[0]); |
| 78 |
exit(1); |
|
|
| 79 |
} |
74 |
} |
| 80 |
|
75 |
|
| 81 |
if (waitpid(pid, &fd, 0) >= 0) { |
76 |
return pid; |
| 82 |
fd = WIFEXITED(fd); |
77 |
} |
|
|
78 |
|
| 79 |
|
| 80 |
static void spawn_wait(char * const command[], const char *message) |
| 81 |
{ |
| 82 |
int status = 0; |
| 83 |
|
| 84 |
if (waitpid(spawn_silent(command, NULL), &status, 0) < 0 || !(WIFEXITED(status))) { |
| 85 |
warn(message); |
| 83 |
} |
86 |
} |
| 84 |
} |
87 |
} |
| 85 |
|
88 |
|
|
Lines 105-120
void udev_start(void)
Link Here
|
| 105 |
|
108 |
|
| 106 |
printf("Spawning udevd... "); |
109 |
printf("Spawning udevd... "); |
| 107 |
|
110 |
|
| 108 |
udevd_pid = spawn(udevd); |
111 |
udevd_pid = spawn_silent(udevd, "/var/log/udevd.log"); |
| 109 |
spawn_wait(priority, "udev_priority"); |
112 |
spawn_wait(priority, "udev_priority"); |
| 110 |
spawn_wait(startup, "udev_startup"); |
113 |
spawn_wait(startup, "udev_startup"); |
| 111 |
spawn_silent(reload); |
114 |
spawn_silent(reload, NULL); |
| 112 |
|
115 |
|
| 113 |
if (mkdir_dev(".udev/queue") < 0) |
116 |
if (mkdir_dev(".udev/queue") < 0) |
| 114 |
fatal("cannot create /dev/.udev/queue"); |
117 |
fatal("cannot create /dev/.udev/queue"); |
| 115 |
|
118 |
|
| 116 |
spawn_silent(subsys); |
119 |
spawn_silent(subsys, NULL); |
| 117 |
spawn_silent(devices); |
120 |
spawn_silent(devices, NULL); |
| 118 |
udev_settle(); |
121 |
udev_settle(); |
| 119 |
|
122 |
|
| 120 |
printf("done\n"); |
123 |
printf("done\n"); |
| 121 |
- |
|
|