Merge pull request #7570 from keszybz/sulogin-shell-reload-manager
Reload manager before exit from sulogin shell
This commit is contained in:
commit
9e32914aa5
10
meson.build
10
meson.build
|
@ -1299,7 +1299,6 @@ subdir('src/resolve')
|
||||||
subdir('src/timedate')
|
subdir('src/timedate')
|
||||||
subdir('src/timesync')
|
subdir('src/timesync')
|
||||||
subdir('src/vconsole')
|
subdir('src/vconsole')
|
||||||
subdir('src/sulogin-shell')
|
|
||||||
subdir('src/boot/efi')
|
subdir('src/boot/efi')
|
||||||
|
|
||||||
subdir('src/test')
|
subdir('src/test')
|
||||||
|
@ -2377,6 +2376,15 @@ if conf.get('ENABLE_NETWORKD') == 1
|
||||||
install_dir : rootbindir)
|
install_dir : rootbindir)
|
||||||
public_programs += [exe]
|
public_programs += [exe]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
executable('systemd-sulogin-shell',
|
||||||
|
['src/sulogin-shell/sulogin-shell.c'],
|
||||||
|
include_directories : includes,
|
||||||
|
link_with : [libshared],
|
||||||
|
install_rpath : rootlibexecdir,
|
||||||
|
install : true,
|
||||||
|
install_dir : rootlibexecdir)
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
foreach tuple : tests
|
foreach tuple : tests
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
# SPDX-License-Identifier: LGPL-2.1+
|
|
||||||
#
|
|
||||||
# Copyright 2017 Zbigniew Jędrzejewski-Szmek
|
|
||||||
#
|
|
||||||
# systemd is free software; you can redistribute it and/or modify it
|
|
||||||
# under the terms of the GNU Lesser General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2.1 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# systemd is distributed in the hope that it will be useful, but
|
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
# Lesser General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
|
||||||
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
executable('systemd-sulogin-shell',
|
|
||||||
['sulogin-shell.c'],
|
|
||||||
include_directories : includes,
|
|
||||||
link_with : [libshared],
|
|
||||||
dependencies : [],
|
|
||||||
install_rpath : rootlibexecdir,
|
|
||||||
install : true,
|
|
||||||
install_dir : rootlibexecdir)
|
|
|
@ -23,21 +23,43 @@
|
||||||
|
|
||||||
#include "bus-util.h"
|
#include "bus-util.h"
|
||||||
#include "bus-error.h"
|
#include "bus-error.h"
|
||||||
|
#include "def.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "process-util.h"
|
#include "process-util.h"
|
||||||
#include "sd-bus.h"
|
#include "sd-bus.h"
|
||||||
#include "signal-util.h"
|
#include "signal-util.h"
|
||||||
|
|
||||||
static int start_default_target(void) {
|
static int reload_manager(sd_bus *bus) {
|
||||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = bus_connect_system_systemd(&bus);
|
log_info("Reloading system manager configuration");
|
||||||
if (r < 0) {
|
|
||||||
log_error_errno(r, "Failed to get D-Bus connection: %m");
|
r = sd_bus_message_new_method_call(
|
||||||
return false;
|
bus,
|
||||||
}
|
&m,
|
||||||
|
"org.freedesktop.systemd1",
|
||||||
|
"/org/freedesktop/systemd1",
|
||||||
|
"org.freedesktop.systemd1.Manager",
|
||||||
|
"Reload");
|
||||||
|
if (r < 0)
|
||||||
|
return bus_log_create_error(r);
|
||||||
|
|
||||||
|
/* Note we use an extra-long timeout here. This is because a reload or reexec means generators are rerun which
|
||||||
|
* are timed out after DEFAULT_TIMEOUT_USEC. Let's use twice that time here, so that the generators can have
|
||||||
|
* their timeout, and for everything else there's the same time budget in place. */
|
||||||
|
|
||||||
|
r = sd_bus_call(bus, m, DEFAULT_TIMEOUT_USEC * 2, &error, NULL);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to reload daemon: %s", bus_error_message(&error, r));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int start_default_target(sd_bus *bus) {
|
||||||
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
log_info("Starting default target");
|
log_info("Starting default target");
|
||||||
|
|
||||||
|
@ -57,14 +79,12 @@ static int start_default_target(void) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fork_wait(const char* const cmdline[]) {
|
static int fork_wait(const char* const cmdline[]) {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0)
|
||||||
log_error_errno(errno, "fork(): %m");
|
return log_error_errno(errno, "fork(): %m");
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
|
|
||||||
/* Child */
|
/* Child */
|
||||||
|
@ -78,18 +98,19 @@ static void fork_wait(const char* const cmdline[]) {
|
||||||
_exit(EXIT_FAILURE); /* Operational error */
|
_exit(EXIT_FAILURE); /* Operational error */
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_for_terminate_and_warn(cmdline[0], pid, false);
|
return wait_for_terminate_and_warn(cmdline[0], pid, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_mode(const char* mode) {
|
static void print_mode(const char* mode) {
|
||||||
printf("You are in %s mode. After logging in, type \"journalctl -xb\" to view\n"
|
printf("You are in %s mode. After logging in, type \"journalctl -xb\" to view\n"
|
||||||
"system logs, \"systemctl reboot\" to reboot, \"systemctl default\" or ^D to boot\n"
|
"system logs, \"systemctl reboot\" to reboot, \"systemctl default\" or \"exit\"\n"
|
||||||
"into default mode.\n", mode);
|
"to boot into default mode.\n", mode);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
static const char* const sulogin_cmdline[] = {SULOGIN, NULL};
|
static const char* const sulogin_cmdline[] = {SULOGIN, NULL};
|
||||||
|
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
log_set_target(LOG_TARGET_AUTO);
|
log_set_target(LOG_TARGET_AUTO);
|
||||||
|
@ -98,9 +119,17 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
print_mode(argc > 1 ? argv[1] : "");
|
print_mode(argc > 1 ? argv[1] : "");
|
||||||
|
|
||||||
fork_wait(sulogin_cmdline);
|
(void) fork_wait(sulogin_cmdline);
|
||||||
|
|
||||||
r = start_default_target();
|
r = bus_connect_system_systemd(&bus);
|
||||||
|
if (r < 0) {
|
||||||
|
log_warning_errno(r, "Failed to get D-Bus connection: %m");
|
||||||
|
r = 0;
|
||||||
|
} else {
|
||||||
|
(void) reload_manager(bus);
|
||||||
|
|
||||||
|
r = start_default_target(bus);
|
||||||
|
}
|
||||||
|
|
||||||
return r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue