From b442b8ca2e86be837ecc74395ce30816e9116a92 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Tue, 25 Jan 2022 18:20:21 +0100 Subject: [PATCH] tizen: ensure standard reboot/poweroff not return to shell Change-Id: Iece3b236f3f2848179dacd3a7ac8afdb008af482 --- src/systemctl/systemctl.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 60869f0..26adc76 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3057,6 +3057,7 @@ static int start_unit(int argc, char *argv[], void *userdata) { _cleanup_free_ char **stopped_units = NULL; /* Do not use _cleanup_strv_free_ */ _cleanup_strv_free_ char **names = NULL; int r, ret = EXIT_SUCCESS; + bool deviced_delegated_shutdown = false; sd_bus *bus; char **name; @@ -3109,6 +3110,11 @@ static int start_unit(int argc, char *argv[], void *userdata) { job_type = "start"; mode = action_table[arg_action].mode; one_name = action_table[arg_action].target; + + // special handling is only for /sbin/{reboot,poweroff,halt}, see below for rationale and effect + if (streq(one_name, "reboot.target") || streq(one_name, "poweroff.target") || streq(one_name, "halt.target")) + deviced_delegated_shutdown = true; + } if (one_name) { @@ -3170,6 +3176,17 @@ static int start_unit(int argc, char *argv[], void *userdata) { } } + if (deviced_delegated_shutdown) { + /* In regular Linux/systemd starting {reboot,halt,exit,poweroff}.target will cause shutdown.target + * to be enqueued which would handle most of shutdown procedure. + * In Tizen these targets just request shutdown to deviced which handles shutdown logic by itself. + * This means that this program will at some point in time lose connection to private systemd bus + * and terminate. This is unwanted behaviour, as it might cause execution of commands after + * reboot invocation, ie. "if ! condition; then /sbin/reboot; fi; rm -rf /thing" */ + while (true) + pause(); + } + if (!arg_no_block) { const char* extra_args[4]; -- 2.7.4