[Toybox] [PATCH] SIGHUP to init.c triggers inittab reload

Chris Sarra chrissarra at google.com
Tue Sep 1 19:22:32 PDT 2020


---
 toys/pending/init.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/toys/pending/init.c b/toys/pending/init.c
index 64b61481..b147911f 100644
--- a/toys/pending/init.c
+++ b/toys/pending/init.c
@@ -188,6 +188,25 @@ static void inittab_parsing(void)
   }
 }
 
+static void reload_inittab(void)
+{
+  // Remove all inactive actions, then reload /etc/inittab
+  struct action_list_seed **y;
+  y = &action_list_pointer;
+  while (*y) {
+    if (!(*y)->pid) {
+      struct action_list_seed *x = *y;
+      free(x->terminal_name);
+      free(x->command);
+      *y = (*y)->next;
+      free(x);
+      continue;
+    }
+    y = &(*y)->next;
+  }
+  inittab_parsing();
+}
+
 static void run_command(char *command)
 {
   char *final_command[128];
@@ -405,7 +424,7 @@ static void restart_init_handler(int sig_no)
 static void catch_signal(int sig_no)
 {
   caught_signal = sig_no;
-  error_msg("signal seen");
+  error_msg("signal seen: %d", sig_no);
 }
 
 static void pause_handler(int sig_no)
@@ -439,6 +458,10 @@ static int check_if_pending_signals(void)
     caught_signal = 0;
     signal_caught = 1;
     if (sig == SIGINT) run_action_from_list(CTRLALTDEL);
+    else if (sig == SIGHUP) {
+      error_msg("reloading inittab");
+      reload_inittab();
+    }
   }
 }
 
-- 
2.28.0.402.g5ffc5be6b7-goog



More information about the Toybox mailing list