|
| 1 | +From 09e4f9a964a9f96c09d7ef53d07917dcc4bdf5d7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Joachim Wiberg <troglobit@gmail.com> |
| 3 | +Date: Sat, 21 Jun 2025 03:12:38 +0200 |
| 4 | +Subject: [PATCH] init: simplify for container usage |
| 5 | +Organization: Wires |
| 6 | + |
| 7 | +All logging of containers go through stderr to the host's syslog, so we |
| 8 | +do not need any console line cleanup, sleeps for output propagation, or |
| 9 | +extra warnings. |
| 10 | + |
| 11 | +Signed-off-by: Joachim Wiberg <troglobit@gmail.com> |
| 12 | +--- |
| 13 | + init/init.c | 21 ++++----------------- |
| 14 | + 1 file changed, 4 insertions(+), 17 deletions(-) |
| 15 | + |
| 16 | +diff --git a/init/init.c b/init/init.c |
| 17 | +index 1e1ce833d..d85494450 100644 |
| 18 | +--- a/init/init.c |
| 19 | ++++ b/init/init.c |
| 20 | +@@ -237,9 +237,8 @@ static void message(int where, const char *fmt, ...) |
| 21 | + unsigned l; |
| 22 | + char msg[128]; |
| 23 | + |
| 24 | +- msg[0] = '\r'; |
| 25 | + va_start(arguments, fmt); |
| 26 | +- l = 1 + vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments); |
| 27 | ++ l = vsnprintf(msg, sizeof(msg) - 2, fmt, arguments); |
| 28 | + if (l > sizeof(msg) - 2) |
| 29 | + l = sizeof(msg) - 2; |
| 30 | + va_end(arguments); |
| 31 | +@@ -735,9 +734,6 @@ static void pause_and_low_level_reboot(unsigned magic) |
| 32 | + { |
| 33 | + pid_t pid; |
| 34 | + |
| 35 | +- /* Allow time for last message to reach serial console, etc */ |
| 36 | +- sleep1(); |
| 37 | +- |
| 38 | + /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) |
| 39 | + * in linux/kernel/sys.c, which can cause the machine to panic when |
| 40 | + * the init process exits... */ |
| 41 | +@@ -751,7 +747,6 @@ static void pause_and_low_level_reboot(unsigned magic) |
| 42 | + * we would eternally sleep here - not what we want. |
| 43 | + */ |
| 44 | + waitpid(pid, NULL, 0); |
| 45 | +- sleep1(); /* paranoia */ |
| 46 | + _exit_SUCCESS(); |
| 47 | + } |
| 48 | + |
| 49 | +@@ -766,14 +761,11 @@ static void run_shutdown_and_kill_processes(void) |
| 50 | + |
| 51 | + /* Send signals to every process _except_ pid 1 */ |
| 52 | + kill(-1, SIGTERM); |
| 53 | +- message(L_CONSOLE, "Sent SIG%s to all processes", "TERM"); |
| 54 | + sync(); |
| 55 | + sleep1(); |
| 56 | + |
| 57 | + kill(-1, SIGKILL); |
| 58 | +- message(L_CONSOLE, "Sent SIG%s to all processes", "KILL"); |
| 59 | + sync(); |
| 60 | +- /*sleep1(); - callers take care about making a pause */ |
| 61 | + } |
| 62 | + |
| 63 | + /* Signal handling by init: |
| 64 | +@@ -810,7 +802,6 @@ static void run_shutdown_and_kill_processes(void) |
| 65 | + static void halt_reboot_pwoff(int sig) NORETURN; |
| 66 | + static void halt_reboot_pwoff(int sig) |
| 67 | + { |
| 68 | +- const char *m; |
| 69 | + unsigned rb; |
| 70 | + |
| 71 | + /* We may call run() and it unmasks signals, |
| 72 | +@@ -823,16 +814,12 @@ static void halt_reboot_pwoff(int sig) |
| 73 | + |
| 74 | + run_shutdown_and_kill_processes(); |
| 75 | + |
| 76 | +- m = "halt"; |
| 77 | + rb = RB_HALT_SYSTEM; |
| 78 | +- if (sig == SIGTERM) { |
| 79 | +- m = "reboot"; |
| 80 | ++ if (sig == SIGTERM) |
| 81 | + rb = RB_AUTOBOOT; |
| 82 | +- } else if (sig == SIGUSR2) { |
| 83 | +- m = "poweroff"; |
| 84 | ++ else if (sig == SIGUSR2) |
| 85 | + rb = RB_POWER_OFF; |
| 86 | +- } |
| 87 | +- message(L_CONSOLE, "Requesting system %s", m); |
| 88 | ++ |
| 89 | + pause_and_low_level_reboot(rb); |
| 90 | + /* not reached */ |
| 91 | + } |
| 92 | +-- |
| 93 | +2.43.0 |
| 94 | + |
0 commit comments