summaryrefslogtreecommitdiff
path: root/userspace/init.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-12-02 01:15:04 +0100
committerMichal Idziorek <m.i@gmx.at>2014-12-02 01:15:04 +0100
commitde8c758de78cd7091f80b582cf706fc441f6ca72 (patch)
tree767a3350dd1f0b656770b96ffffa9a3fb2f12657 /userspace/init.c
parentc2c03f41e078481921bad82487eded0fc51ebb59 (diff)
spawn shells forever
Diffstat (limited to 'userspace/init.c')
-rw-r--r--userspace/init.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/userspace/init.c b/userspace/init.c
index 8c3bcd7..6dc6215 100644
--- a/userspace/init.c
+++ b/userspace/init.c
@@ -1,20 +1,30 @@
-
int main(int argc, char **argv)
{
- int pid=fork();
- if(pid==0)
- {
- execve("/bin/foolshell",0,0);
- }
- else
+ printf("fool-init: spawning a Fool's Shell\n");
+
+ // loop forever and spawn shells if the top-shell exits
+ while(1)
{
- printf("fool-init: forked child (pid: %i) spawning a Fools Shell\n",pid);
+
+ int pid=fork();
int status;
- int pid_ret=wait(&status);
- puts("child state has changed!");
- execve("/bin/init",0,0);
+ if(pid==0)
+ {
+ execve("/bin/foolshell",0,0); // replace process with our foolshell :)
+ puts("FATAL ERROR: Something terrible happened. Unable to Execute SHELL!");
+ while(1);// hang
+
+ }
+
+ // wait until our child process state changes (exits)
+ // and respawn SHELL
+ wait(&status);
+
+ printf("fool-init: catched exit of process %d.\n",pid);
+ printf("fool-init: respawning a Fools Shell\n");
+
}
return 0;
}