X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Funit.c;h=b3b0892f5ebaa1bb0545376776cd8331e605145c;hp=88cddbd02355b2c0e3bc4d7a9ba328060b3d4cc1;hb=adb76a701d870b980f7949bcfece2c1547b4976d;hpb=e2cc6eca73cd1df8be552d7c23f9ff3d69c06f1e diff --git a/src/core/unit.c b/src/core/unit.c index 88cddbd02..b3b0892f5 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -92,6 +92,7 @@ Unit *unit_new(Manager *m, size_t size) { u->deserialized_job = _JOB_TYPE_INVALID; u->default_dependencies = true; u->unit_file_state = _UNIT_FILE_STATE_INVALID; + u->unit_file_preset = -1; u->on_failure_job_mode = JOB_REPLACE; return u; @@ -1726,7 +1727,7 @@ void unit_start_on_failure(Unit *u) { r = manager_add_job(u->manager, JOB_START, other, u->on_failure_job_mode, true, NULL, NULL); if (r < 0) - log_unit_error(u->id, "Failed to enqueue OnFailure= job: %s", strerror(-r)); + log_unit_error_errno(u->id, r, "Failed to enqueue OnFailure= job: %m"); } } @@ -1782,7 +1783,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su /* Make sure the cgroup is always removed when we become inactive */ if (UNIT_IS_INACTIVE_OR_FAILED(ns)) - unit_destroy_cgroup(u); + unit_destroy_cgroup_if_empty(u); /* Note that this doesn't apply to RemainAfterExit services exiting * successfully, since there's no change of state in that case. Which is @@ -3090,6 +3091,17 @@ UnitFileState unit_get_unit_file_state(Unit *u) { return u->unit_file_state; } +int unit_get_unit_file_preset(Unit *u) { + assert(u); + + if (u->unit_file_preset < 0 && u->fragment_path) + u->unit_file_preset = unit_file_query_preset( + u->manager->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, + NULL, basename(u->fragment_path)); + + return u->unit_file_preset; +} + Unit* unit_ref_set(UnitRef *ref, Unit *u) { assert(ref); assert(u); @@ -3260,7 +3272,7 @@ static int unit_drop_in_file(Unit *u, int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data) { - _cleanup_free_ char *dir = NULL; + _cleanup_free_ char *dir = NULL, *p = NULL, *q = NULL; int r; assert(u); @@ -3272,7 +3284,24 @@ int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, co if (r < 0) return r; - return write_drop_in(dir, u->id, 50, name, data); + r = write_drop_in(dir, u->id, 50, name, data); + if (r < 0) + return r; + + r = drop_in_file(dir, u->id, 50, name, &p, &q); + if (r < 0) + return r; + + r = strv_extend(&u->dropin_paths, q); + if (r < 0) + return r; + + strv_sort(u->dropin_paths); + strv_uniq(u->dropin_paths); + + u->dropin_mtime = now(CLOCK_REALTIME); + + return 0; } int unit_write_drop_in_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) { @@ -3435,7 +3464,7 @@ int unit_kill_context( _cleanup_free_ char *comm = NULL; get_process_comm(main_pid, &comm); - log_unit_warning(u->id, "Failed to kill main process " PID_FMT " (%s): %s", main_pid, strna(comm), strerror(-r)); + log_unit_warning_errno(u->id, r, "Failed to kill main process " PID_FMT " (%s): %m", main_pid, strna(comm)); } else { if (!main_pid_alien) wait_for_exit = true; @@ -3452,7 +3481,7 @@ int unit_kill_context( _cleanup_free_ char *comm = NULL; get_process_comm(control_pid, &comm); - log_unit_warning(u->id, "Failed to kill control process " PID_FMT " (%s): %s", control_pid, strna(comm), strerror(-r)); + log_unit_warning_errno(u->id, r, "Failed to kill control process " PID_FMT " (%s): %m", control_pid, strna(comm)); } else { wait_for_exit = true; @@ -3472,7 +3501,7 @@ int unit_kill_context( r = cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, sig, true, true, false, pid_set); if (r < 0) { if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) - log_unit_warning(u->id, "Failed to kill control group: %s", strerror(-r)); + log_unit_warning_errno(u->id, r, "Failed to kill control group: %m"); } else if (r > 0) { /* FIXME: For now, we will not wait for the