diff options
Diffstat (limited to 'src/core')
49 files changed, 301 insertions, 83 deletions
diff --git a/src/core/automount.c b/src/core/automount.c index d362d6579d..4c229247c5 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -29,6 +29,7 @@ #include <sys/stat.h> #include <unistd.h> +#include "alloc-util.h" #include "async.h" #include "automount.h" #include "bus-error.h" @@ -39,10 +40,14 @@ #include "io-util.h" #include "label.h" #include "mkdir.h" +#include "mount-util.h" #include "mount.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "special.h" +#include "stdio-util.h" +#include "string-table.h" #include "string-util.h" #include "unit-name.h" #include "unit.h" @@ -84,26 +89,11 @@ static void automount_init(Unit *u) { UNIT(a)->ignore_on_isolate = true; } -static void repeat_unmount(const char *path) { - assert(path); - - for (;;) { - /* If there are multiple mounts on a mount point, this - * removes them all */ - - if (umount2(path, MNT_DETACH) >= 0) - continue; - - if (errno != EINVAL) - log_error_errno(errno, "Failed to unmount: %m"); - - break; - } -} - static int automount_send_ready(Automount *a, Set *tokens, int status); static void unmount_autofs(Automount *a) { + int r; + assert(a); if (a->pipe_fd < 0) @@ -119,8 +109,11 @@ static void unmount_autofs(Automount *a) { * around */ if (a->where && (UNIT(a)->manager->exit_code != MANAGER_RELOAD && - UNIT(a)->manager->exit_code != MANAGER_REEXECUTE)) - repeat_unmount(a->where); + UNIT(a)->manager->exit_code != MANAGER_REEXECUTE)) { + r = repeat_unmount(a->where, MNT_DETACH); + if (r < 0) + log_error_errno(r, "Failed to unmount: %m"); + } } static void automount_done(Unit *u) { @@ -140,13 +133,12 @@ static void automount_done(Unit *u) { static int automount_add_mount_links(Automount *a) { _cleanup_free_ char *parent = NULL; - int r; assert(a); - r = path_get_parent(a->where, &parent); - if (r < 0) - return r; + parent = dirname_malloc(a->where); + if (!parent) + return -ENOMEM; return unit_require_mounts_for(UNIT(a), parent); } @@ -611,12 +603,16 @@ static void automount_enter_waiting(Automount *a) { return; fail: + log_unit_error_errno(UNIT(a), r, "Failed to initialize automounter: %m"); + safe_close_pair(p); - if (mounted) - repeat_unmount(a->where); + if (mounted) { + r = repeat_unmount(a->where, MNT_DETACH); + if (r < 0) + log_error_errno(r, "Failed to unmount, ignoring: %m"); + } - log_unit_error_errno(UNIT(a), r, "Failed to initialize automounter: %m"); automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES); } diff --git a/src/core/bus-endpoint.c b/src/core/bus-endpoint.c index 0c4b3e7c8b..d22a80c91f 100644 --- a/src/core/bus-endpoint.c +++ b/src/core/bus-endpoint.c @@ -19,10 +19,11 @@ #include <stdlib.h> -#include "kdbus.h" +#include "alloc-util.h" +#include "bus-endpoint.h" #include "bus-kernel.h" #include "bus-policy.h" -#include "bus-endpoint.h" +#include "kdbus.h" int bus_kernel_set_endpoint_policy(int fd, uid_t uid, BusEndpoint *ep) { diff --git a/src/core/bus-policy.c b/src/core/bus-policy.c index 2490903a8c..4907c268e8 100644 --- a/src/core/bus-policy.c +++ b/src/core/bus-policy.c @@ -19,9 +19,11 @@ #include <stdlib.h> +#include "alloc-util.h" #include "bus-kernel.h" #include "bus-policy.h" #include "kdbus.h" +#include "string-table.h" #include "user-util.h" #include "util.h" diff --git a/src/core/busname.c b/src/core/busname.c index 335a1fdc4c..3592f72fe5 100644 --- a/src/core/busname.c +++ b/src/core/busname.c @@ -21,6 +21,7 @@ #include <sys/mman.h> +#include "alloc-util.h" #include "bus-internal.h" #include "bus-kernel.h" #include "bus-policy.h" @@ -30,9 +31,12 @@ #include "fd-util.h" #include "formats-util.h" #include "kdbus.h" +#include "parse-util.h" +#include "process-util.h" #include "service.h" #include "signal-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" static const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = { diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 2a2cf02774..bed01fde21 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -22,12 +22,17 @@ #include <fcntl.h> #include <fnmatch.h> +#include "alloc-util.h" #include "cgroup-util.h" #include "cgroup.h" #include "fd-util.h" +#include "fileio.h" +#include "fs-util.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #define CGROUP_CPU_QUOTA_PERIOD_USEC ((usec_t) 100 * USEC_PER_MSEC) @@ -1204,7 +1209,7 @@ int unit_search_main_pid(Unit *u, pid_t *ret) { continue; /* Ignore processes that aren't our kids */ - if (get_parent_of_pid(npid, &ppid) >= 0 && ppid != mypid) + if (get_process_ppid(npid, &ppid) >= 0 && ppid != mypid) continue; if (pid != 0) diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 6a43be873a..3fd295baa9 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -19,11 +19,13 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "alloc-util.h" #include "bus-util.h" #include "cgroup-util.h" #include "cgroup.h" #include "dbus-cgroup.h" #include "fd-util.h" +#include "fileio.h" #include "path-util.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy); diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 6f1e0dc6ac..04a5a22b72 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -26,8 +26,9 @@ #endif #include "af-list.h" +#include "alloc-util.h" #include "bus-util.h" -#include "capability.h" +#include "capability-util.h" #include "dbus-execute.h" #include "env-util.h" #include "execute.h" @@ -36,13 +37,16 @@ #include "ioprio.h" #include "missing.h" #include "namespace.h" +#include "parse-util.h" #include "path-util.h" -#include "strv.h" -#include "utf8.h" - +#include "process-util.h" +#include "rlimit-util.h" #ifdef HAVE_SECCOMP #include "seccomp-util.h" #endif +#include "strv.h" +#include "syslog-util.h" +#include "utf8.h" BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput); @@ -109,7 +113,7 @@ static int property_get_oom_score_adjust( n = 0; if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0) - safe_atoi(t, &n); + safe_atoi32(t, &n); } return sd_bus_message_append(reply, "i", n); diff --git a/src/core/dbus-job.c b/src/core/dbus-job.c index e95ec5c0cb..8c30d66250 100644 --- a/src/core/dbus-job.c +++ b/src/core/dbus-job.c @@ -21,12 +21,13 @@ #include "sd-bus.h" +#include "alloc-util.h" +#include "dbus-job.h" #include "dbus.h" #include "job.h" #include "log.h" #include "selinux-access.h" #include "string-util.h" -#include "dbus-job.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, job_type, JobType); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_state, job_state, JobState); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 1ef259ec7a..1f9f25093d 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -23,6 +23,7 @@ #include <sys/prctl.h> #include <unistd.h> +#include "alloc-util.h" #include "architecture.h" #include "build.h" #include "bus-common-errors.h" @@ -35,13 +36,16 @@ #include "dbus.h" #include "env-util.h" #include "fd-util.h" +#include "fileio.h" #include "formats-util.h" #include "install.h" #include "log.h" #include "path-util.h" #include "selinux-access.h" +#include "stat-util.h" #include "string-util.h" #include "strv.h" +#include "syslog-util.h" #include "virt.h" #include "watchdog.h" diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c index f8fb373bf0..16375b2311 100644 --- a/src/core/dbus-scope.c +++ b/src/core/dbus-scope.c @@ -19,17 +19,18 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "selinux-access.h" -#include "unit.h" -#include "scope.h" -#include "dbus.h" -#include "bus-util.h" -#include "bus-internal.h" +#include "alloc-util.h" #include "bus-common-errors.h" -#include "dbus-unit.h" +#include "bus-internal.h" +#include "bus-util.h" #include "dbus-cgroup.h" #include "dbus-kill.h" #include "dbus-scope.h" +#include "dbus-unit.h" +#include "dbus.h" +#include "scope.h" +#include "selinux-access.h" +#include "unit.h" static int bus_scope_abandon(sd_bus_message *message, void *userdata, sd_bus_error *error) { Scope *s = userdata; diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 22b8690c54..c41b3e1723 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -19,6 +19,7 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "alloc-util.h" #include "async.h" #include "bus-util.h" #include "dbus-cgroup.h" @@ -26,6 +27,7 @@ #include "dbus-kill.h" #include "dbus-service.h" #include "fd-util.h" +#include "fileio.h" #include "path-util.h" #include "service.h" #include "string-util.h" diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c index 5941b72bc0..be5ef261a6 100644 --- a/src/core/dbus-socket.c +++ b/src/core/dbus-socket.c @@ -19,13 +19,14 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "alloc-util.h" #include "bus-util.h" #include "dbus-cgroup.h" #include "dbus-execute.h" +#include "dbus-socket.h" #include "socket.h" #include "string-util.h" #include "unit.h" -#include "dbus-socket.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, socket_result, SocketResult); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only); diff --git a/src/core/dbus-timer.c b/src/core/dbus-timer.c index 8ea2cf84a4..a8a280d961 100644 --- a/src/core/dbus-timer.c +++ b/src/core/dbus-timer.c @@ -19,11 +19,12 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "unit.h" -#include "timer.h" -#include "dbus-timer.h" +#include "alloc-util.h" #include "bus-util.h" +#include "dbus-timer.h" #include "strv.h" +#include "timer.h" +#include "unit.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, timer_result, TimerResult); diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 7220fe688f..6320cd1aa9 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -21,15 +21,18 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "cgroup-util.h" +#include "dbus-unit.h" #include "dbus.h" +#include "locale-util.h" #include "log.h" #include "selinux-access.h" #include "special.h" #include "string-util.h" #include "strv.h" -#include "dbus-unit.h" +#include "user-util.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_load_state, unit_load_state, UnitLoadState); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_job_mode, job_mode, JobMode); diff --git a/src/core/dbus.c b/src/core/dbus.c index 37410a9870..834745aeb5 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -25,6 +25,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-internal.h" @@ -45,6 +46,7 @@ #include "string-util.h" #include "strv.h" #include "strxcpyx.h" +#include "user-util.h" #define CONNECTIONS_MAX 4096 diff --git a/src/core/device.c b/src/core/device.c index 9127d2d225..23ee7aee7e 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -24,15 +24,18 @@ #include "libudev.h" +#include "alloc-util.h" #include "dbus-device.h" +#include "device.h" #include "log.h" +#include "parse-util.h" #include "path-util.h" +#include "stat-util.h" #include "string-util.h" #include "swap.h" #include "udev-util.h" #include "unit-name.h" #include "unit.h" -#include "device.h" static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = { [DEVICE_DEAD] = UNIT_INACTIVE, diff --git a/src/core/execute.c b/src/core/execute.c index 3f2607ff1a..d751065af0 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -53,6 +53,7 @@ #include "sd-messages.h" #include "af-list.h" +#include "alloc-util.h" #ifdef HAVE_APPARMOR #include "apparmor-util.h" #endif @@ -60,7 +61,7 @@ #include "barrier.h" #include "bus-endpoint.h" #include "cap-list.h" -#include "capability.h" +#include "capability-util.h" #include "def.h" #include "env-util.h" #include "errno-list.h" @@ -69,6 +70,8 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" +#include "glob-util.h" #include "io-util.h" #include "ioprio.h" #include "log.h" @@ -76,8 +79,10 @@ #include "missing.h" #include "mkdir.h" #include "namespace.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" +#include "rlimit-util.h" #include "rm-rf.h" #ifdef HAVE_SECCOMP #include "seccomp-util.h" @@ -86,8 +91,10 @@ #include "selinux-util.h" #include "signal-util.h" #include "smack-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" +#include "syslog-util.h" #include "terminal-util.h" #include "unit.h" #include "user-util.h" diff --git a/src/core/failure-action.c b/src/core/failure-action.c index 3412accf3e..c7c95984b7 100644 --- a/src/core/failure-action.c +++ b/src/core/failure-action.c @@ -23,10 +23,11 @@ #include <sys/reboot.h> #include <linux/reboot.h> -#include "bus-util.h" #include "bus-error.h" -#include "special.h" +#include "bus-util.h" #include "failure-action.h" +#include "special.h" +#include "string-table.h" #include "terminal-util.h" static void log_and_status(Manager *m, const char *message) { diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c index f1563afff9..cc7515905d 100644 --- a/src/core/hostname-setup.c +++ b/src/core/hostname-setup.c @@ -23,6 +23,7 @@ #include <stdio.h> #include <stdlib.h> +#include "alloc-util.h" #include "fileio.h" #include "hostname-util.h" #include "log.h" diff --git a/src/core/ima-setup.c b/src/core/ima-setup.c index 0c0982b0b4..9572fa17d9 100644 --- a/src/core/ima-setup.c +++ b/src/core/ima-setup.c @@ -25,6 +25,7 @@ #include <errno.h> #include "fd-util.h" +#include "fileio.h" #include "ima-setup.h" #include "log.h" #include "util.h" diff --git a/src/core/job.c b/src/core/job.c index 8a0e0a0ea4..120381fc3b 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -24,20 +24,23 @@ #include "sd-id128.h" #include "sd-messages.h" +#include "alloc-util.h" #include "async.h" #include "dbus-job.h" #include "dbus.h" #include "escape.h" +#include "job.h" #include "log.h" #include "macro.h" +#include "parse-util.h" #include "set.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" #include "unit.h" #include "virt.h" -#include "job.h" Job* job_new_raw(Unit *unit) { Job *j; diff --git a/src/core/kill.c b/src/core/kill.c index bddfa4460f..1466d5ce64 100644 --- a/src/core/kill.c +++ b/src/core/kill.c @@ -19,9 +19,10 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "util.h" -#include "signal-util.h" #include "kill.h" +#include "signal-util.h" +#include "string-table.h" +#include "util.h" void kill_context_init(KillContext *c) { assert(c); diff --git a/src/core/killall.c b/src/core/killall.c index cb11987166..77f145b4d1 100644 --- a/src/core/killall.c +++ b/src/core/killall.c @@ -24,9 +24,11 @@ #include <sys/wait.h> #include <unistd.h> +#include "alloc-util.h" #include "fd-util.h" #include "formats-util.h" #include "killall.h" +#include "parse-util.h" #include "process-util.h" #include "set.h" #include "string-util.h" diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c index 2068ffd69b..651f79a1fe 100644 --- a/src/core/kmod-setup.c +++ b/src/core/kmod-setup.c @@ -27,7 +27,7 @@ #endif #include "macro.h" -#include "capability.h" +#include "capability-util.h" #include "bus-util.h" #include "kmod-setup.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 31fdc48823..ecfdb80deb 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -32,6 +32,7 @@ #include <sys/resource.h> #include <sys/stat.h> +#include "alloc-util.h" #include "af-list.h" #include "bus-error.h" #include "bus-internal.h" @@ -44,22 +45,27 @@ #include "errno-list.h" #include "escape.h" #include "fd-util.h" +#include "fs-util.h" #include "ioprio.h" #include "load-fragment.h" #include "log.h" #include "missing.h" +#include "parse-util.h" #include "path-util.h" +#include "process-util.h" #ifdef HAVE_SECCOMP #include "seccomp-util.h" #endif #include "securebits.h" #include "signal-util.h" +#include "stat-util.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" #include "unit-printf.h" #include "unit.h" #include "utf8.h" +#include "web-util.h" int config_parse_warn_compat( const char *unit, diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c index c72892b343..145ba2a28d 100644 --- a/src/core/machine-id-setup.c +++ b/src/core/machine-id-setup.c @@ -29,16 +29,22 @@ #include "sd-id128.h" +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" +#include "hexdecoct.h" #include "io-util.h" #include "log.h" #include "machine-id-setup.h" #include "macro.h" #include "mkdir.h" +#include "mount-util.h" #include "path-util.h" #include "process-util.h" +#include "stat-util.h" #include "string-util.h" +#include "umask-util.h" #include "util.h" #include "virt.h" diff --git a/src/core/main.c b/src/core/main.c index b0ca6fa10e..593b974566 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -40,11 +40,12 @@ #include "sd-daemon.h" #include "sd-bus.h" +#include "alloc-util.h" #include "architecture.h" #include "build.h" #include "bus-error.h" #include "bus-util.h" -#include "capability.h" +#include "capability-util.h" #include "clock-util.h" #include "conf-parser.h" #include "cpu-set-util.h" @@ -55,6 +56,7 @@ #include "fdset.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "hostname-setup.h" #include "ima-setup.h" #include "killall.h" @@ -67,12 +69,17 @@ #include "missing.h" #include "mount-setup.h" #include "pager.h" +#include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" +#include "rlimit-util.h" #include "selinux-setup.h" #include "selinux-util.h" #include "signal-util.h" #include "smack-setup.h" #include "special.h" +#include "stat-util.h" +#include "stdio-util.h" #include "strv.h" #include "switch-root.h" #include "terminal-util.h" diff --git a/src/core/manager.c b/src/core/manager.c index 287676ff27..04111091e7 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -40,6 +40,7 @@ #include "sd-daemon.h" #include "sd-messages.h" +#include "alloc-util.h" #include "audit-fd.h" #include "boot-timestamps.h" #include "bus-common-errors.h" @@ -54,6 +55,8 @@ #include "escape.h" #include "exit-status.h" #include "fd-util.h" +#include "fileio.h" +#include "fs-util.h" #include "hashmap.h" #include "io-util.h" #include "locale-setup.h" @@ -62,6 +65,7 @@ #include "manager.h" #include "missing.h" #include "mkdir.h" +#include "parse-util.h" #include "path-lookup.h" #include "path-util.h" #include "process-util.h" @@ -69,11 +73,14 @@ #include "rm-rf.h" #include "signal-util.h" #include "special.h" +#include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" #include "time-util.h" #include "transaction.h" +#include "umask-util.h" #include "unit-name.h" #include "util.h" #include "virt.h" diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 9b16eaa0e2..b2596d1cd1 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -25,22 +25,25 @@ #include <unistd.h> #include <ftw.h> -#include "mount-setup.h" -#include "dev-setup.h" +#include "alloc-util.h" #include "bus-util.h" +#include "cgroup-util.h" +#include "dev-setup.h" +#include "efivars.h" +#include "label.h" #include "log.h" #include "macro.h" -#include "util.h" -#include "label.h" -#include "set.h" -#include "strv.h" +#include "missing.h" #include "mkdir.h" +#include "mount-setup.h" +#include "mount-util.h" #include "path-util.h" -#include "missing.h" -#include "virt.h" -#include "efivars.h" +#include "set.h" #include "smack-util.h" -#include "cgroup-util.h" +#include "strv.h" +#include "user-util.h" +#include "util.h" +#include "virt.h" typedef enum MountMode { MNT_NONE = 0, diff --git a/src/core/mount.c b/src/core/mount.c index ebdb3503e9..2761f632bd 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -26,6 +26,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "dbus-mount.h" #include "escape.h" #include "exit-status.h" @@ -35,10 +36,14 @@ #include "manager.h" #include "mkdir.h" #include "mount-setup.h" +#include "mount-util.h" #include "mount.h" +#include "parse-util.h" #include "path-util.h" +#include "process-util.h" #include "smack-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" @@ -251,9 +256,10 @@ static int mount_add_mount_links(Mount *m) { if (!path_equal(m->where, "/")) { /* Adds in links to other mount points that might lie further * up in the hierarchy */ - r = path_get_parent(m->where, &parent); - if (r < 0) - return r; + + parent = dirname_malloc(m->where); + if (!parent) + return -ENOMEM; r = unit_require_mounts_for(UNIT(m), parent); if (r < 0) diff --git a/src/core/namespace.c b/src/core/namespace.c index 4d11d54bfe..81ba09ea5d 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -28,17 +28,22 @@ #include <unistd.h> #include <linux/fs.h> +#include "alloc-util.h" #include "dev-setup.h" #include "fd-util.h" #include "loopback-setup.h" #include "missing.h" #include "mkdir.h" +#include "mount-util.h" #include "namespace.h" #include "path-util.h" #include "selinux-util.h" #include "socket-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" +#include "umask-util.h" +#include "user-util.h" #include "util.h" typedef enum MountMode { diff --git a/src/core/path.c b/src/core/path.c index 11054d8c78..35e1753583 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -28,10 +28,14 @@ #include "bus-util.h" #include "dbus-path.h" #include "fd-util.h" +#include "fs-util.h" +#include "glob-util.h" #include "macro.h" #include "mkdir.h" #include "path.h" #include "special.h" +#include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "unit-name.h" #include "unit.h" diff --git a/src/core/scope.c b/src/core/scope.c index 9f72851382..6bacb226e8 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -22,15 +22,17 @@ #include <errno.h> #include <unistd.h> +#include "alloc-util.h" #include "dbus-scope.h" #include "load-dropin.h" #include "log.h" +#include "scope.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" #include "unit.h" -#include "scope.h" static const UnitActiveState state_translation_table[_SCOPE_STATE_MAX] = { [SCOPE_DEAD] = UNIT_INACTIVE, diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c index cf38fa0ebe..4bcdd27389 100644 --- a/src/core/selinux-access.c +++ b/src/core/selinux-access.c @@ -32,13 +32,16 @@ #endif #include "sd-bus.h" + +#include "alloc-util.h" +#include "audit-fd.h" #include "bus-util.h" -#include "util.h" #include "log.h" +#include "path-util.h" #include "selinux-util.h" -#include "audit-fd.h" +#include "stdio-util.h" #include "strv.h" -#include "path-util.h" +#include "util.h" static bool initialized = false; diff --git a/src/core/service.c b/src/core/service.c index abcbd4954f..31a0d3aebe 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -23,6 +23,7 @@ #include <signal.h> #include <unistd.h> +#include "alloc-util.h" #include "async.h" #include "bus-error.h" #include "bus-kernel.h" @@ -35,15 +36,18 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "load-dropin.h" #include "load-fragment.h" #include "log.h" #include "manager.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "service.h" #include "signal-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" @@ -171,7 +175,7 @@ static int service_set_main_pid(Service *s, pid_t pid) { s->main_pid = pid; s->main_pid_known = true; - if (get_parent_of_pid(pid, &ppid) >= 0 && ppid != getpid()) { + if (get_process_ppid(pid, &ppid) >= 0 && ppid != getpid()) { log_unit_warning(UNIT(s), "Supervising process "PID_FMT" which is not our child. We'll most likely not notice when it exits.", pid); s->main_pid_alien = true; } else diff --git a/src/core/show-status.c b/src/core/show-status.c index 7951ea7303..e4e12a3365 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -19,9 +19,14 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "alloc-util.h" +#include "fd-util.h" +#include "io-util.h" +#include "parse-util.h" +#include "show-status.h" #include "string-util.h" +#include "terminal-util.h" #include "util.h" -#include "show-status.h" int parse_show_status(const char *v, ShowStatus *ret) { int r; @@ -41,3 +46,81 @@ int parse_show_status(const char *v, ShowStatus *ret) { *ret = r ? SHOW_STATUS_YES : SHOW_STATUS_NO; return 0; } + +int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) { + static const char status_indent[] = " "; /* "[" STATUS "] " */ + _cleanup_free_ char *s = NULL; + _cleanup_close_ int fd = -1; + struct iovec iovec[6] = {}; + int n = 0; + static bool prev_ephemeral; + + assert(format); + + /* This is independent of logging, as status messages are + * optional and go exclusively to the console. */ + + if (vasprintf(&s, format, ap) < 0) + return log_oom(); + + fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC); + if (fd < 0) + return fd; + + if (ellipse) { + char *e; + size_t emax, sl; + int c; + + c = fd_columns(fd); + if (c <= 0) + c = 80; + + sl = status ? sizeof(status_indent)-1 : 0; + + emax = c - sl - 1; + if (emax < 3) + emax = 3; + + e = ellipsize(s, emax, 50); + if (e) { + free(s); + s = e; + } + } + + if (prev_ephemeral) + IOVEC_SET_STRING(iovec[n++], "\r" ANSI_ERASE_TO_END_OF_LINE); + prev_ephemeral = ephemeral; + + if (status) { + if (!isempty(status)) { + IOVEC_SET_STRING(iovec[n++], "["); + IOVEC_SET_STRING(iovec[n++], status); + IOVEC_SET_STRING(iovec[n++], "] "); + } else + IOVEC_SET_STRING(iovec[n++], status_indent); + } + + IOVEC_SET_STRING(iovec[n++], s); + if (!ephemeral) + IOVEC_SET_STRING(iovec[n++], "\n"); + + if (writev(fd, iovec, n) < 0) + return -errno; + + return 0; +} + +int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) { + va_list ap; + int r; + + assert(format); + + va_start(ap, format); + r = status_vprintf(status, ellipse, ephemeral, format, ap); + va_end(ap); + + return r; +} diff --git a/src/core/show-status.h b/src/core/show-status.h index a2b2153746..c79d4acb66 100644 --- a/src/core/show-status.h +++ b/src/core/show-status.h @@ -21,6 +21,10 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <stdbool.h> + +#include "macro.h" + /* Manager status */ typedef enum ShowStatus { @@ -32,3 +36,6 @@ typedef enum ShowStatus { } ShowStatus; int parse_show_status(const char *v, ShowStatus *ret); + +int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0); +int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5); diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 33383a4b0b..3a95b5fd72 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -31,12 +31,14 @@ #include <sys/stat.h> #include <unistd.h> +#include "alloc-util.h" #include "cgroup-util.h" #include "def.h" #include "fileio.h" #include "killall.h" #include "log.h" #include "missing.h" +#include "parse-util.h" #include "process-util.h" #include "string-util.h" #include "switch-root.h" diff --git a/src/core/slice.c b/src/core/slice.c index 8fb6d28a3c..4602144150 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -21,6 +21,7 @@ #include <errno.h> +#include "alloc-util.h" #include "dbus-slice.h" #include "log.h" #include "special.h" diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index 34df392184..0661ff9ecd 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -28,6 +28,8 @@ #include <stdlib.h> #include <string.h> +#include "alloc-util.h" +#include "dirent-util.h" #include "fd-util.h" #include "fileio.h" #include "log.h" diff --git a/src/core/snapshot.c b/src/core/snapshot.c index 15726c344e..ba3135f401 100644 --- a/src/core/snapshot.c +++ b/src/core/snapshot.c @@ -21,12 +21,15 @@ #include <errno.h> +#include "alloc-util.h" #include "bus-common-errors.h" #include "dbus-snapshot.h" +#include "parse-util.h" +#include "parse-util.h" +#include "snapshot.h" #include "string-util.h" #include "unit-name.h" #include "unit.h" -#include "snapshot.h" static const UnitActiveState state_translation_table[_SNAPSHOT_STATE_MAX] = { [SNAPSHOT_DEAD] = UNIT_INACTIVE, diff --git a/src/core/snapshot.h b/src/core/snapshot.h index 97747e18bd..bd52dea408 100644 --- a/src/core/snapshot.h +++ b/src/core/snapshot.h @@ -23,6 +23,8 @@ typedef struct Snapshot Snapshot; +#include "unit.h" + struct Snapshot { Unit meta; diff --git a/src/core/socket.c b/src/core/socket.c index 7f401025ed..f62466c6a0 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -31,6 +31,7 @@ #include "sd-event.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "copy.h" @@ -43,12 +44,15 @@ #include "log.h" #include "missing.h" #include "mkdir.h" +#include "parse-util.h" #include "path-util.h" +#include "process-util.h" #include "selinux-util.h" #include "signal-util.h" #include "smack-util.h" #include "socket.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" @@ -1168,9 +1172,9 @@ static int usbffs_dispatch_eps(SocketPort *p) { _cleanup_free_ char *path = NULL; int r, i, n, k; - r = path_get_parent(p->path, &path); - if (r < 0) - return r; + path = dirname_malloc(p->path); + if (!path) + return -ENOMEM; r = scandir(path, &ent, usbffs_select_ep, alphasort); if (r < 0) diff --git a/src/core/swap.c b/src/core/swap.c index d864c7b304..6eff6ffb4c 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -26,14 +26,18 @@ #include "libudev.h" +#include "alloc-util.h" #include "dbus-swap.h" #include "escape.h" #include "exit-status.h" #include "fd-util.h" #include "formats-util.h" #include "fstab-util.h" +#include "parse-util.h" #include "path-util.h" +#include "process-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "swap.h" #include "udev-util.h" diff --git a/src/core/timer.c b/src/core/timer.c index 908d45ac73..cc2afedabf 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -21,10 +21,14 @@ #include <errno.h> +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "dbus-timer.h" +#include "fs-util.h" +#include "parse-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "timer.h" #include "unit-name.h" diff --git a/src/core/transaction.c b/src/core/transaction.c index d1c1b9a3cd..69f28c902f 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -22,10 +22,11 @@ #include <unistd.h> #include <fcntl.h> +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" -#include "transaction.h" #include "terminal-util.h" +#include "transaction.h" static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies); diff --git a/src/core/umount.c b/src/core/umount.c index 8735bed7b1..9d1f7660db 100644 --- a/src/core/umount.c +++ b/src/core/umount.c @@ -29,6 +29,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "escape.h" #include "fd-util.h" #include "fstab-util.h" diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 4a5c7efdb0..721c8ccce9 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -19,6 +19,7 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "alloc-util.h" #include "cgroup-util.h" #include "formats-util.h" #include "macro.h" diff --git a/src/core/unit.c b/src/core/unit.c index 572b1c1b78..8d56401231 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -28,6 +28,7 @@ #include "sd-id128.h" #include "sd-messages.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-util.h" #include "cgroup-util.h" @@ -44,10 +45,12 @@ #include "macro.h" #include "missing.h" #include "mkdir.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "set.h" #include "special.h" +#include "stat-util.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" @@ -416,12 +419,11 @@ static void unit_remove_transient(Unit *u) { STRV_FOREACH(i, u->dropin_paths) { _cleanup_free_ char *p = NULL; - int r; (void) unlink(*i); - r = path_get_parent(*i, &p); - if (r >= 0) + p = dirname_malloc(*i); + if (p) (void) rmdir(p); } } |