jail: read and apply umask from OCI if defined
[project/procd.git] / inittab.c
index c27c3241f4e1b359eb69e7177f7ac633de7d5441..45118f4f1eaf05867e98040562131dc7df8e233e 100644 (file)
--- a/inittab.c
+++ b/inittab.c
@@ -104,7 +104,7 @@ static void fork_worker(struct init_action *a)
                tcsetpgrp(STDIN_FILENO, p);
 
                execvp(a->argv[0], a->argv);
-               ERROR("Failed to execute %s\n", a->argv[0]);
+               ERROR("Failed to execute %s: %m\n", a->argv[0]);
                exit(-1);
        }
 
@@ -120,14 +120,22 @@ static void child_exit(struct uloop_process *proc, int ret)
 {
        struct init_action *a = container_of(proc, struct init_action, proc);
 
-       DEBUG(4, "pid:%d\n", proc->pid);
-        uloop_timeout_set(&a->tout, a->respawn);
+       DEBUG(4, "pid:%d, exitcode:%d\n", proc->pid, ret);
+       proc->pid = 0;
+
+       if (!dev_exist(a->id)) {
+               DEBUG(4, "Skipping respawn: device '%s' does not exist anymore\n", a->id);
+               return;
+       }
+
+       uloop_timeout_set(&a->tout, a->respawn);
 }
 
 static void respawn(struct uloop_timeout *tout)
 {
        struct init_action *a = container_of(tout, struct init_action, tout);
-       fork_worker(a);
+       if (!a->proc.pid)
+               fork_worker(a);
 }
 
 static void rcdone(struct runqueue *q)
@@ -157,13 +165,17 @@ static void askfirst(struct init_action *a)
        }
 
        a->tout.cb = respawn;
-       for (i = MAX_ARGS - 1; i >= 1; i--)
-               a->argv[i] = a->argv[i - 1];
-       a->argv[0] = ask;
+       /* shift arguments only if not yet done */
+       if (a->argv[0] != ask) {
+               for (i = MAX_ARGS - 1; i >= 1; i--)
+                       a->argv[i] = a->argv[i - 1];
+               a->argv[0] = ask;
+       }
        a->respawn = 500;
 
        a->proc.cb = child_exit;
-       fork_worker(a);
+       if (!a->proc.pid)
+               fork_worker(a);
 }
 
 static void askconsole(struct init_action *a)
@@ -191,13 +203,17 @@ static void askconsole(struct init_action *a)
        }
 
        a->tout.cb = respawn;
-       for (i = MAX_ARGS - 1; i >= 1; i--)
-               a->argv[i] = a->argv[i - 1];
-       a->argv[0] = ask;
+       /* shift arguments only if not yet done */
+       if (a->argv[0] != ask) {
+               for (i = MAX_ARGS - 1; i >= 1; i--)
+                       a->argv[i] = a->argv[i - 1];
+               a->argv[0] = ask;
+       }
        a->respawn = 500;
 
        a->proc.cb = child_exit;
-       fork_worker(a);
+       if (!a->proc.pid)
+               fork_worker(a);
 }
 
 static void rcrespawn(struct init_action *a)
@@ -206,7 +222,8 @@ static void rcrespawn(struct init_action *a)
        a->respawn = 500;
 
        a->proc.cb = child_exit;
-       fork_worker(a);
+       if (!a->proc.pid)
+               fork_worker(a);
 }
 
 static struct init_handler handlers[] = {
@@ -259,12 +276,9 @@ void procd_inittab_run(const char *handler)
 
        list_for_each_entry(a, &actions, list)
                if (!strcmp(a->handler->name, handler)) {
-                       if (a->handler->multi) {
-                               a->handler->cb(a);
-                               continue;
-                       }
                        a->handler->cb(a);
-                       break;
+                       if (!a->handler->multi)
+                               break;
                }
 }
 
@@ -278,7 +292,7 @@ void procd_inittab(void)
        char *line;
 
        if (!fp) {
-               ERROR("Failed to open %s\n", tab);
+               ERROR("Failed to open %s: %m\n", tab);
                return;
        }