diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/automount.c | 78 | ||||
-rw-r--r-- | src/core/dbus-unit.c | 4 | ||||
-rw-r--r-- | src/core/service.c | 14 | ||||
-rw-r--r-- | src/core/unit.c | 1 |
4 files changed, 59 insertions, 38 deletions
diff --git a/src/core/automount.c b/src/core/automount.c index 8ff1ca90f7..99e8047620 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -101,17 +101,17 @@ static void unmount_autofs(Automount *a) { a->pipe_event_source = sd_event_source_unref(a->pipe_event_source); a->pipe_fd = safe_close(a->pipe_fd); - /* If we reload/reexecute things we keep the mount point - * around */ - if (a->where && - (UNIT(a)->manager->exit_code != MANAGER_RELOAD && - UNIT(a)->manager->exit_code != MANAGER_REEXECUTE)) { + /* If we reload/reexecute things we keep the mount point around */ + if (!IN_SET(UNIT(a)->manager->exit_code, MANAGER_RELOAD, MANAGER_REEXECUTE)) { + automount_send_ready(a, a->tokens, -EHOSTDOWN); automount_send_ready(a, a->expire_tokens, -EHOSTDOWN); - r = repeat_unmount(a->where, MNT_DETACH); - if (r < 0) - log_error_errno(r, "Failed to unmount: %m"); + if (a->where) { + r = repeat_unmount(a->where, MNT_DETACH); + if (r < 0) + log_error_errno(r, "Failed to unmount: %m"); + } } } @@ -186,6 +186,22 @@ static int automount_verify(Automount *a) { return 0; } +static int automount_set_where(Automount *a) { + int r; + + assert(a); + + if (a->where) + return 0; + + r = unit_name_to_path(UNIT(a)->id, &a->where); + if (r < 0) + return r; + + path_kill_slashes(a->where); + return 1; +} + static int automount_load(Unit *u) { Automount *a = AUTOMOUNT(u); int r; @@ -201,13 +217,9 @@ static int automount_load(Unit *u) { if (u->load_state == UNIT_LOADED) { Unit *x; - if (!a->where) { - r = unit_name_to_path(u->id, &a->where); - if (r < 0) - return r; - } - - path_kill_slashes(a->where); + r = automount_set_where(a); + if (r < 0) + return r; r = unit_load_related_unit(u, ".mount", &x); if (r < 0) @@ -256,26 +268,30 @@ static int automount_coldplug(Unit *u) { assert(a); assert(a->state == AUTOMOUNT_DEAD); - if (a->deserialized_state != a->state) { + if (a->deserialized_state == a->state) + return 0; + + if (IN_SET(a->deserialized_state, AUTOMOUNT_WAITING, AUTOMOUNT_RUNNING)) { + + r = automount_set_where(a); + if (r < 0) + return r; r = open_dev_autofs(u->manager); if (r < 0) return r; - if (a->deserialized_state == AUTOMOUNT_WAITING || - a->deserialized_state == AUTOMOUNT_RUNNING) { - assert(a->pipe_fd >= 0); + assert(a->pipe_fd >= 0); - r = sd_event_add_io(u->manager->event, &a->pipe_event_source, a->pipe_fd, EPOLLIN, automount_dispatch_io, u); - if (r < 0) - return r; + r = sd_event_add_io(u->manager->event, &a->pipe_event_source, a->pipe_fd, EPOLLIN, automount_dispatch_io, u); + if (r < 0) + return r; - (void) sd_event_source_set_description(a->pipe_event_source, "automount-io"); - if (a->deserialized_state == AUTOMOUNT_RUNNING) { - r = automount_start_expire(a); - if (r < 0) - log_unit_warning_errno(UNIT(a), r, "Failed to start expiration timer, ignoring: %m"); - } + (void) sd_event_source_set_description(a->pipe_event_source, "automount-io"); + if (a->deserialized_state == AUTOMOUNT_RUNNING) { + r = automount_start_expire(a); + if (r < 0) + log_unit_warning_errno(UNIT(a), r, "Failed to start expiration timer, ignoring: %m"); } automount_set_state(a, a->deserialized_state); @@ -733,6 +749,12 @@ static void automount_enter_runnning(Automount *a) { assert(a); + /* If the user masked our unit in the meantime, fail */ + if (UNIT(a)->load_state != UNIT_LOADED) { + log_unit_error(UNIT(a), "Suppressing automount event since unit is no longer loaded."); + goto fail; + } + /* We don't take mount requests anymore if we are supposed to * shut down anyway */ if (unit_stop_pending(UNIT(a))) { diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index f1306a023f..f15bb2196c 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1131,7 +1131,7 @@ void bus_unit_send_change_signal(Unit *u) { if (!u->id) return; - r = bus_foreach_bus(u->manager, NULL, u->sent_dbus_new_signal ? send_changed_signal : send_new_signal, u); + r = bus_foreach_bus(u->manager, u->bus_track, u->sent_dbus_new_signal ? send_changed_signal : send_new_signal, u); if (r < 0) log_unit_debug_errno(u, r, "Failed to send unit change signal for %s: %m", u->id); @@ -1177,7 +1177,7 @@ void bus_unit_send_removed_signal(Unit *u) { if (!u->id) return; - r = bus_foreach_bus(u->manager, NULL, send_removed_signal, u); + r = bus_foreach_bus(u->manager, u->bus_track, send_removed_signal, u); if (r < 0) log_unit_debug_errno(u, r, "Failed to send unit remove signal for %s: %m", u->id); } diff --git a/src/core/service.c b/src/core/service.c index 5581ec8b06..74054887b9 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -849,11 +849,8 @@ static int service_load_pid_file(Service *s, bool may_warn) { return r; r = unit_watch_pid(UNIT(s), pid); - if (r < 0) { - /* FIXME: we need to do something here */ - log_unit_warning_errno(UNIT(s), r, "Failed to watch PID "PID_FMT" for service: %m", pid); - return r; - } + if (r < 0) /* FIXME: we need to do something here */ + return log_unit_warning_errno(UNIT(s), r, "Failed to watch PID "PID_FMT" for service: %m", pid); return 0; } @@ -1374,8 +1371,7 @@ static int service_spawn( return r; r = unit_watch_pid(UNIT(s), pid); - if (r < 0) - /* FIXME: we need to do something here */ + if (r < 0) /* FIXME: we need to do something here */ return r; *_pid = pid; @@ -3097,6 +3093,8 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds) log_unit_warning(u, "Failed to parse MAINPID= field in notification message: %s", e); else if (pid == s->control_pid) log_unit_warning(u, "A control process cannot also be the main process"); + else if (pid == getpid() || pid == 1) + log_unit_warning(u, "Service manager can't be main process, ignoring sd_notify() MAINPID= field"); else { service_set_main_pid(s, pid); unit_watch_pid(UNIT(s), pid); @@ -3286,7 +3284,7 @@ static void service_bus_name_owner_change( if (r >= 0) r = sd_bus_creds_get_pid(creds, &pid); if (r >= 0) { - log_unit_debug(u, "D-Bus name %s is now owned by process %u", name, (unsigned) pid); + log_unit_debug(u, "D-Bus name %s is now owned by process " PID_FMT, name, pid); service_set_main_pid(s, pid); unit_watch_pid(UNIT(s), pid); diff --git a/src/core/unit.c b/src/core/unit.c index 174dd42819..b091a0999b 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -402,6 +402,7 @@ void unit_add_to_dbus_queue(Unit *u) { /* Shortcut things if nobody cares */ if (sd_bus_track_count(u->manager->subscribed) <= 0 && + sd_bus_track_count(u->bus_track) <= 0 && set_isempty(u->manager->private_buses)) { u->sent_dbus_new_signal = true; return; |