diff --git a/compat/systemd.c b/compat/systemd.c index 3548f317..b1f47063 100644 --- a/compat/systemd.c +++ b/compat/systemd.c @@ -81,7 +81,8 @@ struct systemd_job_watch { }; static int -job_removed_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) +job_removed_handler(sd_bus_message *m, void *userdata, + __unused sd_bus_error *ret_error) { struct systemd_job_watch *watch = userdata; const char *path = NULL; @@ -109,7 +110,7 @@ systemd_move_to_new_cgroup(char **cause) sd_bus_message *m = NULL, *reply = NULL; sd_bus *bus = NULL; sd_bus_slot *slot = NULL; - char *name, *desc, *slice; + char *name, *desc, *slice, *unit; sd_id128_t uuid; int r; uint64_t elapsed_usec; @@ -241,6 +242,26 @@ systemd_move_to_new_cgroup(char **cause) goto finish; } + /* + * Try locating systemd unit that started the server, and mark pane units + * as dependent on it. Use "Before" to make sure systemd will not try to + * kill them first. + */ + if (sd_pid_get_user_unit(parent_pid, &unit) == 0 || + sd_pid_get_unit(parent_pid, &unit) == 0) { + r = sd_bus_message_append(m, "(sv)", "Before", "as", 1, unit); + if (r >= 0) { + r = sd_bus_message_append(m, "(sv)", "PartOf", "as", 1, + unit); + } + free(unit); + if (r < 0) { + xasprintf(cause, "failed to append to properties: %s", + strerror(-r)); + goto finish; + } + } + /* End properties array. */ r = sd_bus_message_close_container(m); if (r < 0) {