jail: Add MS_NODEV MS_NOEXEC MS_NOSUID mount options where needed
[project/procd.git] / plug / coldplug.c
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
19 #include <unistd.h>
20
21 #include "../procd.h"
22
23 #include "hotplug.h"
24
25 static struct uloop_process udevtrigger;
26
27 static void coldplug_complete(struct uloop_timeout *t)
28 {
29 DEBUG(4, "Coldplug complete\n");
30 hotplug_last_event(NULL);
31 procd_state_next();
32 }
33
34 static void udevtrigger_complete(struct uloop_process *proc, int ret)
35 {
36 DEBUG(4, "Finished udevtrigger\n");
37 hotplug_last_event(coldplug_complete);
38 }
39
40 void procd_coldplug(void)
41 {
42 char *argv[] = { "udevtrigger", NULL };
43 unsigned int oldumask = umask(0);
44
45 umount2("/dev/pts", MNT_DETACH);
46 umount2("/dev/", MNT_DETACH);
47 mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755,size=512K");
48 symlink("/tmp/shm", "/dev/shm");
49 mkdir("/dev/pts", 0755);
50 umask(oldumask);
51 mount("devpts", "/dev/pts", "devpts", MS_NOEXEC | MS_NOSUID, 0);
52 udevtrigger.cb = udevtrigger_complete;
53 udevtrigger.pid = fork();
54 if (!udevtrigger.pid) {
55 execvp(argv[0], argv);
56 ERROR("Failed to start coldplug\n");
57 exit(-1);
58 }
59
60 if (udevtrigger.pid <= 0) {
61 ERROR("Failed to start new coldplug instance\n");
62 return;
63 }
64
65 uloop_process_add(&udevtrigger);
66
67 DEBUG(4, "Launched coldplug instance, pid=%d\n", (int) udevtrigger.pid);
68 }