Skip to content

Commit 0d96caa

Browse files
deepak-rawatkeszybz
authored andcommitted
logind: Add new flag for kexec reboot
Add new flag to allow kexec reboot if kernel is already loaded.
1 parent a93af34 commit 0d96caa

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

man/org.freedesktop.login1.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,13 @@ node /org/freedesktop/login1 {
555555
extendability, defined as follows:</para>
556556
<programlisting>
557557
#define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) &lt;&lt; 0)
558+
#define SD_LOGIND_KEXEC_REBOOT (UINT64_C(1) &lt;&lt; 1)
558559
</programlisting>
559560
<para> When the <varname>flags</varname> is 0 then these methods behave just like the versions
560561
without flags. When <constant>SD_LOGIND_ROOT_CHECK_INHIBITORS</constant> (0x01) is set, active
561-
inhibitors are honoured for privileged users too.</para>
562+
inhibitors are honoured for privileged users too. When <constant>SD_LOGIND_KEXEC_REBOOT</constant>
563+
(0x02) is set, then <function>RebootWithFlags()</function> perform kexec reboot if kexec
564+
kernel is loaded.</para>
562565

563566
<para><function>SetRebootParameter()</function> sets a parameter for a subsequent reboot operation.
564567
See the description of <command>reboot</command> in

src/basic/login-util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
#include <unistd.h>
66

77
#define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0)
8+
#define SD_LOGIND_KEXEC_REBOOT (UINT64_C(1) << 1)
89

910
/* For internal use only */
1011
#define SD_LOGIND_INTERACTIVE (UINT64_C(1) << 63)
1112

12-
#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC (SD_LOGIND_ROOT_CHECK_INHIBITORS)
13-
#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_ALL (SD_LOGIND_ROOT_CHECK_INHIBITORS|SD_LOGIND_INTERACTIVE)
13+
#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC (SD_LOGIND_ROOT_CHECK_INHIBITORS|SD_LOGIND_KEXEC_REBOOT)
14+
#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_ALL (SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC|SD_LOGIND_INTERACTIVE)
1415

1516
bool session_id_valid(const char *id);
1617

src/login/logind-dbus.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,8 @@ static int method_do_shutdown_or_sleep(
18801880
return r;
18811881
if ((flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC) != 0)
18821882
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags parameter");
1883+
if (!streq(unit_name, SPECIAL_REBOOT_TARGET) && (flags & SD_LOGIND_KEXEC_REBOOT))
1884+
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags parameter");
18831885
} else {
18841886
/* Old style method: no flags parameter, but interactive bool passed as boolean in
18851887
* payload. Let's convert this argument to the new-style flags parameter for our internal
@@ -1893,6 +1895,9 @@ static int method_do_shutdown_or_sleep(
18931895
flags = interactive ? SD_LOGIND_INTERACTIVE : 0;
18941896
}
18951897

1898+
if ((flags & SD_LOGIND_KEXEC_REBOOT) && kexec_loaded())
1899+
unit_name = SPECIAL_KEXEC_TARGET;
1900+
18961901
/* Don't allow multiple jobs being executed at the same time */
18971902
if (m->action_what > 0)
18981903
return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS,

src/systemctl/systemctl-compat-halt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ int halt_main(void) {
161161

162162
/* Try logind if we are a normal user and no special mode applies. Maybe polkit allows us to
163163
* shutdown the machine. */
164-
if (IN_SET(arg_action, ACTION_POWEROFF, ACTION_REBOOT, ACTION_HALT)) {
164+
if (IN_SET(arg_action, ACTION_POWEROFF, ACTION_REBOOT, ACTION_KEXEC, ACTION_HALT)) {
165165
r = logind_reboot(arg_action);
166166
if (r >= 0)
167167
return r;

src/systemctl/systemctl-logind.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ int logind_reboot(enum action a) {
5050
} actions[_ACTION_MAX] = {
5151
[ACTION_POWEROFF] = { "PowerOff", "power off system" },
5252
[ACTION_REBOOT] = { "Reboot", "reboot system" },
53+
[ACTION_KEXEC] = { "Reboot", "kexec reboot system" },
5354
[ACTION_HALT] = { "Halt", "halt system" },
5455
[ACTION_SUSPEND] = { "Suspend", "suspend system" },
5556
[ACTION_HIBERNATE] = { "Hibernate", "hibernate system" },
@@ -79,6 +80,7 @@ int logind_reboot(enum action a) {
7980
return 0;
8081

8182
SET_FLAG(flags, SD_LOGIND_ROOT_CHECK_INHIBITORS, arg_check_inhibitors > 0);
83+
SET_FLAG(flags, SD_LOGIND_KEXEC_REBOOT, a == ACTION_KEXEC);
8284

8385
method_with_flags = strjoina(actions[a].method, "WithFlags");
8486

src/systemctl/systemctl-start-special.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ int start_special(int argc, char *argv[], void *userdata) {
201201
if (IN_SET(a,
202202
ACTION_POWEROFF,
203203
ACTION_REBOOT,
204+
ACTION_KEXEC,
204205
ACTION_HALT,
205206
ACTION_SUSPEND,
206207
ACTION_HIBERNATE,
@@ -220,9 +221,9 @@ int start_special(int argc, char *argv[], void *userdata) {
220221

221222
arg_no_block = true;
222223

223-
} else if (IN_SET(a, ACTION_EXIT, ACTION_KEXEC))
224-
/* Since exit/kexec are so close in behaviour to power-off/reboot, let's also make
225-
* them asynchronous, in order to not confuse the user needlessly with unexpected
224+
} else if (IN_SET(a, ACTION_EXIT))
225+
/* Since exit is so close in behaviour to power-off/reboot, let's also make
226+
* it asynchronous, in order to not confuse the user needlessly with unexpected
226227
* behaviour. */
227228
arg_no_block = true;
228229

0 commit comments

Comments
 (0)