Add an --in-chroot option to udevd. Skips operations that can only happen once per machine,
skips creating device files, and skips running RUN rules.
diff --git a/udev.h b/udev.h
index 33b39aa..82fe700 100644
a
|
b
|
extern char udev_config_filename[PATH_SIZE];
|
103 | 103 | extern char udev_rules_dir[PATH_SIZE]; |
104 | 104 | extern int udev_log_priority; |
105 | 105 | extern int udev_run; |
| 106 | extern int udev_in_chroot; |
106 | 107 | extern void udev_config_init(void); |
107 | 108 | |
108 | 109 | /* udev_device.c */ |
diff --git a/udev_device.c b/udev_device.c
index 62217ff..647a6a8 100644
a
|
b
|
int udev_device_event(struct udev_rules *rules, struct udevice *udev)
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /* look if we want to change the name of the netif */ |
237 | | if (strcmp(udev->name, udev->dev->kernel) != 0) { |
| 237 | if (!udev_in_chroot && strcmp(udev->name, udev->dev->kernel) != 0) { |
238 | 238 | char devpath[PATH_MAX]; |
239 | 239 | char *pos; |
240 | 240 | |
diff --git a/udevd.c b/udevd.c
index eb311df..0aabae1 100644
a
|
b
|
|
48 | 48 | static int debug_trace; |
49 | 49 | static int debug; |
50 | 50 | |
| 51 | int udev_in_chroot; |
| 52 | |
51 | 53 | static struct udev_rules rules; |
52 | 54 | static int udevd_sock = -1; |
53 | 55 | static int uevent_netlink_sock = -1; |
… |
… |
static int udev_event_process(struct udevd_uevent_msg *msg)
|
136 | 138 | alarm(udev->event_timeout); |
137 | 139 | |
138 | 140 | /* run programs collected by RUN-key*/ |
139 | | if (retval == 0 && !udev->ignore_device && udev_run) |
| 141 | if (retval == 0 && !udev->ignore_device && udev_run && !udev_in_chroot) |
140 | 142 | retval = udev_rules_run(udev); |
141 | 143 | |
142 | 144 | udev_device_cleanup(udev); |
… |
… |
static void udev_event_run(struct udevd_uevent_msg *msg)
|
233 | 235 | case 0: |
234 | 236 | /* child */ |
235 | 237 | close(uevent_netlink_sock); |
236 | | close(udevd_sock); |
| 238 | if (!udev_in_chroot) |
| 239 | close(udevd_sock); |
237 | 240 | if (inotify_fd >= 0) |
238 | 241 | close(inotify_fd); |
239 | 242 | close(signal_pipe[READ_END]); |
… |
… |
int main(int argc, char *argv[], char *envp[])
|
960 | 963 | static const struct option options[] = { |
961 | 964 | { "daemon", 0, NULL, 'd' }, |
962 | 965 | { "debug-trace", 0, NULL, 't' }, |
| 966 | { "in-chroot", 0, NULL, 'c' }, |
963 | 967 | { "debug", 0, NULL, 'D' }, |
964 | 968 | { "help", 0, NULL, 'h' }, |
965 | 969 | { "version", 0, NULL, 'V' }, |
… |
… |
int main(int argc, char *argv[], char *envp[])
|
974 | 978 | dbg("version %s\n", UDEV_VERSION); |
975 | 979 | |
976 | 980 | while (1) { |
977 | | option = getopt_long(argc, argv, "dDthV", options, NULL); |
| 981 | option = getopt_long(argc, argv, "dDcthV", options, NULL); |
978 | 982 | if (option == -1) |
979 | 983 | break; |
980 | 984 | |
… |
… |
int main(int argc, char *argv[], char *envp[])
|
985 | 989 | case 't': |
986 | 990 | debug_trace = 1; |
987 | 991 | break; |
| 992 | case 'c': |
| 993 | udev_in_chroot = 1; |
| 994 | break; |
988 | 995 | case 'D': |
989 | 996 | debug = 1; |
990 | 997 | if (udev_log_priority < LOG_INFO) |
991 | 998 | udev_log_priority = LOG_INFO; |
992 | 999 | break; |
993 | 1000 | case 'h': |
994 | | printf("Usage: udevd [--help] [--daemon] [--debug-trace] [--debug] [--version]\n"); |
| 1001 | printf("Usage: udevd [--help] [--daemon] [--debug-trace] [--in-chroot] [--debug] [--version]\n"); |
995 | 1002 | goto exit; |
996 | 1003 | case 'V': |
997 | 1004 | printf("%s\n", UDEV_VERSION); |
… |
… |
int main(int argc, char *argv[], char *envp[])
|
1021 | 1028 | dup2(fd, STDERR_FILENO); |
1022 | 1029 | |
1023 | 1030 | /* init sockets to receive events */ |
1024 | | if (init_udevd_socket() < 0) { |
| 1031 | if (!udev_in_chroot && init_udevd_socket() < 0) { |
1025 | 1032 | if (errno == EADDRINUSE) { |
1026 | 1033 | fprintf(stderr, "another udev daemon already running\n"); |
1027 | 1034 | err("another udev daemon already running\n"); |
… |
… |
int main(int argc, char *argv[], char *envp[])
|
1190 | 1197 | if (debug_trace) |
1191 | 1198 | putenv("DEBUG=1"); |
1192 | 1199 | |
1193 | | maxfd = udevd_sock; |
1194 | | maxfd = UDEV_MAX(maxfd, uevent_netlink_sock); |
| 1200 | maxfd = uevent_netlink_sock; |
1195 | 1201 | maxfd = UDEV_MAX(maxfd, signal_pipe[READ_END]); |
1196 | 1202 | maxfd = UDEV_MAX(maxfd, inotify_fd); |
1197 | 1203 | |
| 1204 | if (!udev_in_chroot) |
| 1205 | maxfd = UDEV_MAX(maxfd, udevd_sock); |
| 1206 | |
1198 | 1207 | while (!udev_exit) { |
1199 | 1208 | struct udevd_uevent_msg *msg; |
1200 | 1209 | int fdcount; |
1201 | 1210 | |
1202 | 1211 | FD_ZERO(&readfds); |
1203 | 1212 | FD_SET(signal_pipe[READ_END], &readfds); |
1204 | | FD_SET(udevd_sock, &readfds); |
1205 | 1213 | FD_SET(uevent_netlink_sock, &readfds); |
1206 | 1214 | if (inotify_fd >= 0) |
1207 | 1215 | FD_SET(inotify_fd, &readfds); |
| 1216 | if (!udev_in_chroot) |
| 1217 | FD_SET(udevd_sock, &readfds); |
1208 | 1218 | |
1209 | 1219 | fdcount = select(maxfd+1, &readfds, NULL, NULL, NULL); |
1210 | 1220 | if (fdcount < 0) { |
… |
… |
int main(int argc, char *argv[], char *envp[])
|
1214 | 1224 | } |
1215 | 1225 | |
1216 | 1226 | /* get control message */ |
1217 | | if (FD_ISSET(udevd_sock, &readfds)) |
| 1227 | if (!udev_in_chroot && FD_ISSET(udevd_sock, &readfds)) |
1218 | 1228 | get_ctrl_msg(); |
1219 | 1229 | |
1220 | 1230 | /* get netlink message */ |
… |
… |
exit:
|
1282 | 1292 | if (signal_pipe[WRITE_END] >= 0) |
1283 | 1293 | close(signal_pipe[WRITE_END]); |
1284 | 1294 | |
1285 | | if (udevd_sock >= 0) |
| 1295 | if (!udev_in_chroot && udevd_sock >= 0) |
1286 | 1296 | close(udevd_sock); |
1287 | 1297 | if (inotify_fd >= 0) |
1288 | 1298 | close(inotify_fd); |