1 /* 2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org> 3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Lesser General Public License version 2.1 7 * as published by the Free Software Foundation 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 */ 14 15 #include <sys/stat.h> 16 #include <sys/types.h> 17 #include <sys/mount.h> 18 #include <sys/sysmacros.h> 19 20 #include <stdlib.h> 21 #include <unistd.h> 22 23 #include "../procd.h" 24 #include "../libc-compat.h" 25 26 #include "hotplug.h" 27 #include "../container.h" 28 29 static struct uloop_process udevtrigger; 30 31 static void coldplug_complete(struct uloop_timeout *t) 32 { 33 P_DEBUG(4, "Coldplug complete\n"); 34 hotplug_last_event(NULL); 35 procd_state_next(); 36 } 37 38 static void udevtrigger_complete(struct uloop_process *proc, int ret) 39 { 40 P_DEBUG(4, "Finished udevtrigger\n"); 41 hotplug_last_event(coldplug_complete); 42 } 43 44 void procd_coldplug(void) 45 { 46 char *argv[] = { "udevtrigger", NULL }; 47 unsigned int oldumask = umask(0); 48 49 if (!is_container()) { 50 umount2("/dev/pts", MNT_DETACH); 51 umount2("/dev/", MNT_DETACH); 52 mount("tmpfs", "/dev", "tmpfs", MS_NOATIME | MS_NOEXEC | MS_NOSUID, "mode=0755,size=512K"); 53 mknod("/dev/null", S_IFCHR | 0666, makedev(1, 3)); 54 mkdir("/dev/pts", 0755); 55 mount("devpts", "/dev/pts", "devpts", MS_NOATIME | MS_NOEXEC | MS_NOSUID, 0); 56 } 57 58 ignore(symlink("/tmp/shm", "/dev/shm")); 59 umask(oldumask); 60 udevtrigger.cb = udevtrigger_complete; 61 udevtrigger.pid = fork(); 62 if (!udevtrigger.pid) { 63 execvp(argv[0], argv); 64 ERROR("Failed to start coldplug: %m\n"); 65 exit(EXIT_FAILURE); 66 } 67 68 if (udevtrigger.pid <= 0) { 69 ERROR("Failed to start new coldplug instance: %m\n"); 70 return; 71 } 72 73 uloop_process_add(&udevtrigger); 74 75 P_DEBUG(4, "Launched coldplug instance, pid=%d\n", (int) udevtrigger.pid); 76 } 77
This page was automatically generated by LXR 0.3.1. • OpenWrt