From fc420dfbe62103eaf77876f3b25894c6a031c0db Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Mar 2019 11:52:32 +0100 Subject: [PATCH 1/4] update TODO --- TODO | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 0178d431d5..18fdf4e257 100644 --- a/TODO +++ b/TODO @@ -23,6 +23,9 @@ Janitorial Clean-ups: Features: +* check ID_RENAMING= property from PID1's .device logic, and don't consider + devices that are being renamed. + * make MAINPID= message reception checks even stricter: if service uses User=, then check sending UID and ignore message if it doesn't match the user or root. @@ -63,7 +66,7 @@ Features: * paranoia: whenever we process passwords, call mlock() on the memory first. i.e. look for all places we use string_erase()/string_free_erase() and - augment them with mlock() + augment them with mlock(). Also use MADV_DONTDUMP * whenever oom_kill memory.event event is triggered print a nice log message From 66034f9c07017b4b91d11c3697b620880845774a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Mar 2019 11:52:54 +0100 Subject: [PATCH 2/4] shutdown: fix up return type of sync_making_progress() We shouldn't return negative errnos as "bool", hence fix the type of the function to "int". --- src/core/shutdown.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 56e9a2480a..48469103da 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -169,10 +169,10 @@ static int switch_root_initramfs(void) { * value input. For all other issues, report the failure and indicate that * the sync is not making progress. */ -static bool sync_making_progress(unsigned long long *prev_dirty) { +static int sync_making_progress(unsigned long long *prev_dirty) { _cleanup_fclose_ FILE *f = NULL; unsigned long long val = 0; - bool r = false; + int ret; f = fopen("/proc/meminfo", "re"); if (!f) @@ -205,11 +205,9 @@ static bool sync_making_progress(unsigned long long *prev_dirty) { val += ull; } - r = *prev_dirty > val; - + ret = *prev_dirty > val; *prev_dirty = val; - - return r; + return ret; } static void sync_with_progress(void) { @@ -243,7 +241,7 @@ static void sync_with_progress(void) { else if (r == -ETIMEDOUT) { /* Reset the check counter if the "Dirty" value is * decreasing */ - if (sync_making_progress(&dirty)) + if (sync_making_progress(&dirty) > 0) checks = 0; } else { log_error_errno(r, "Failed to sync filesystems and block devices: %m"); From 3a736a32164672550fead7417a2159751ac94df5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Mar 2019 11:53:39 +0100 Subject: [PATCH 3/4] shutdown: (void)ify more stuff --- src/core/shutdown.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 48469103da..842ba57f13 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -343,14 +343,14 @@ int main(int argc, char *argv[]) { bool changed = false; if (use_watchdog) - watchdog_ping(); + (void) watchdog_ping(); /* Let's trim the cgroup tree on each iteration so that we leave an empty cgroup tree around, so that container managers get a nice notify event when we are down */ if (cgroup) - cg_trim(SYSTEMD_CGROUP_CONTROLLER, cgroup, false); + (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, cgroup, false); if (need_umount) { log_info("Unmounting file systems."); @@ -440,7 +440,7 @@ int main(int argc, char *argv[]) { arguments[0] = NULL; arguments[1] = arg_verb; arguments[2] = NULL; - execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, arguments, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); + (void) execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, arguments, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); (void) rlimit_nofile_safe(); From 9e71f5d9838af32b9484d1757129c419e57866ae Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Mar 2019 12:12:33 +0100 Subject: [PATCH 4/4] shutdown: rearrange shutdown sources in source tree Let's move the shutdown binary into its own subdirectory in src/shutdown, after all it is relatively isolated from the normal PID 1 sources, being a different binary and all. Unfortunately it's not possible to move some of the code, since it is shared with PID 1, that I wished we could move, but I still think it's worth it. --- meson.build | 6 ++++++ src/core/meson.build | 10 ---------- src/shutdown/meson.build | 5 +++++ src/{core => shutdown}/shutdown.c | 0 src/{core => shutdown}/umount.c | 0 src/{core => shutdown}/umount.h | 0 src/test/meson.build | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 src/shutdown/meson.build rename src/{core => shutdown}/shutdown.c (100%) rename src/{core => shutdown}/umount.c (100%) rename src/{core => shutdown}/umount.h (100%) diff --git a/meson.build b/meson.build index 239f13c061..f2b975abc5 100644 --- a/meson.build +++ b/meson.build @@ -1441,6 +1441,7 @@ includes = include_directories('src/basic', 'src/udev', 'src/libudev', 'src/core', + 'src/shutdown', 'src/libsystemd/sd-bus', 'src/libsystemd/sd-device', 'src/libsystemd/sd-event', @@ -1527,6 +1528,7 @@ public_programs = [] subdir('src/libudev') subdir('src/shared') subdir('src/core') +subdir('src/shutdown') subdir('src/udev') subdir('src/network') @@ -2676,6 +2678,10 @@ public_programs += exe executable('systemd-shutdown', systemd_shutdown_sources, + 'src/core/mount-setup.c', + 'src/core/mount-setup.h', + 'src/core/killall.c', + 'src/core/killall.h', include_directories : includes, link_with : [libshared], dependencies : [libmount], diff --git a/src/core/meson.build b/src/core/meson.build index 88fb093732..6f387c4796 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -163,16 +163,6 @@ libcore = static_library( systemd_sources = files('main.c') -systemd_shutdown_sources = files(''' - shutdown.c - umount.c - umount.h - mount-setup.c - mount-setup.h - killall.c - killall.h -'''.split()) - in_files = [['macros.systemd', rpmmacrosdir], ['system.conf', pkgsysconfdir], ['systemd.pc', pkgconfigdatadir], diff --git a/src/shutdown/meson.build b/src/shutdown/meson.build new file mode 100644 index 0000000000..ebf0bed242 --- /dev/null +++ b/src/shutdown/meson.build @@ -0,0 +1,5 @@ +systemd_shutdown_sources = files(''' + shutdown.c + umount.c + umount.h +'''.split()) diff --git a/src/core/shutdown.c b/src/shutdown/shutdown.c similarity index 100% rename from src/core/shutdown.c rename to src/shutdown/shutdown.c diff --git a/src/core/umount.c b/src/shutdown/umount.c similarity index 100% rename from src/core/umount.c rename to src/shutdown/umount.c diff --git a/src/core/umount.h b/src/shutdown/umount.h similarity index 100% rename from src/core/umount.h rename to src/shutdown/umount.h diff --git a/src/test/meson.build b/src/test/meson.build index c53b9653f9..e43f119230 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -716,8 +716,8 @@ tests += [ [['src/test/test-umount.c', 'src/core/mount-setup.c', 'src/core/mount-setup.h', - 'src/core/umount.c', - 'src/core/umount.h'], + 'src/shutdown/umount.c', + 'src/shutdown/umount.h'], [], [libmount]],