2 * this code is protected by the GNU affero GPLv3
3 * author:Sylvain BERTRAND <sylvain.bertrand AT legeek DOT net>
5 #include <ulinux/compiler_misc.h>
6 #include <ulinux/compiler_types.h>
7 #include <ulinux/sysc.h>
8 #include <ulinux/types.h>
9 #include <ulinux/error.h>
10 #include <ulinux/signal/signal.h>
11 #include <ulinux/signal/siginfo.h>
12 #include <ulinux/wait.h>
17 #include "ulinux_namespace.h"
19 static void sigs_setup(void)
26 OUT(PRE
"setting up signals...\n");
27 r
= rt_sigprocmask(SIG_BLOCK
, &mask
, sizeof(mask
));
29 OUT("ERROR:unable to block all signals (except KILL and STOP)\n");
35 static i
sysstart_clone(void)
40 OUT(PRE
"clone and execve /bin/sysstart...\n");
43 OUT("ERROR(%ld):unable to clone sysinit for /bin/sysstart\n", r
);
51 r
= rt_sigprocmask(SIG_UNBLOCK
, &mask
, sizeof(mask
));
53 OUT("ERROR(%ld):unable to unblock all signals for /bin/sysstart\n", r
);
57 r
= execve("/bin/sysstart", 0);
59 OUT("ERROR(%ld):unable to execve /bin/sysstart\n", r
);
65 static i
getty_spawn(void *tty
)
71 argv
[0] = "bin/agetty";
75 OUT(PRE
"getty %s...\n", tty
);
79 OUT("ERROR(%ld):unable to clone for getty(%s)\n", r
, tty
);
84 return r
;/* return the child process id */
87 r
= rt_sigprocmask(SIG_UNBLOCK
, &mask
, sizeof(mask
));
89 OUT("ERROR(%ld):unable to unblock all signals for getty(%s)\n", r
, tty
);
95 OUT("ERROR(%ld):unable to setsid the getty(%s) clone\n", r
, tty
);
99 r
= execve("/bin/agetty", argv
);
101 OUT("ERROR(%ld):unable to run /bin/agetty(%s)\n", r
, tty
);
107 static void sysstart(void)
112 pid
= sysstart_clone();
113 r
= waitid(P_PID
, pid
, 0, WEXITED
|WALL
);
115 OUT("ERROR(%ld):unable to wait for /bin/sysstart to exit\n", r
);
121 /* minimal, we don't even have ttys to restart */
122 static void main_loop(void)
127 r
= waitid(P_ALL
, 0, 0, WEXITED
|WALL
);
129 OUT("ERROR(%ld):unable to wait on orphan process terminations\n", r
);
134 /* we allow ourself 2 ttys to restart */
135 static void main_loop(void)
140 tty1
= getty_spawn("tty1");
141 tty2
= getty_spawn("tty2");
144 struct siginfo siginfo
;
147 r
= waitid(P_ALL
, 0, &siginfo
, WEXITED
|WALL
);
149 OUT("ERROR(%ld):unable to wait on /bin/agetty clone and orphan process terminations\n", r
);
152 if (siginfo
.fields
.sigchld
.pid
== tty1
)
153 tty1
= getty_spawn("tty1");
154 else if (siginfo
.fields
.sigchld
.pid
== tty2
)
155 tty2
= getty_spawn("tty2");
165 /* vim: set ts=4 sw=0 noexpandtab: */