695
697
if (u->source_path)
696
698
fprintf(f, "%s\tSource Path: %s\n", prefix, u->source_path);
700
STRV_FOREACH(j, u->dropin_paths)
701
fprintf(f, "%s\tDropIn Path: %s\n", prefix, *j);
698
703
if (u->job_timeout > 0)
699
fprintf(f, "%s\tJob Timeout: %s\n", prefix, format_timespan(timespan, sizeof(timespan), u->job_timeout));
704
fprintf(f, "%s\tJob Timeout: %s\n", prefix, format_timespan(timespan, sizeof(timespan), u->job_timeout, 0));
701
706
condition_dump_list(u->conditions, f, prefix);
909
914
if (u->on_failure_isolate &&
910
915
set_size(u->dependencies[UNIT_ON_FAILURE]) > 1) {
912
log_error("More than one OnFailure= dependencies specified for %s but OnFailureIsolate= enabled. Refusing.",
917
log_error_unit(u->id,
918
"More than one OnFailure= dependencies specified for %s but OnFailureIsolate= enabled. Refusing.", u->id);
929
934
unit_add_to_dbus_queue(u);
930
935
unit_add_to_gc_queue(u);
932
log_debug("Failed to load configuration for %s: %s", u->id, strerror(-r));
937
log_debug_unit(u->id, "Failed to load configuration for %s: %s",
938
u->id, strerror(-r));
1062
1068
* but we don't want to recheck the condition in that case. */
1063
1069
if (state != UNIT_ACTIVATING &&
1064
1070
!unit_condition_test(u)) {
1065
log_debug("Starting of %s requested but condition failed. Ignoring.", u->id);
1071
log_debug_unit(u->id, "Starting of %s requested but condition failed. Ignoring.", u->id);
1066
1072
return -EALREADY;
1069
1075
/* Forward to the main object, if we aren't it. */
1070
1076
if ((following = unit_following(u))) {
1071
log_debug("Redirecting start request from %s to %s.", u->id, following->id);
1077
log_debug_unit(u->id, "Redirecting start request from %s to %s.",
1078
u->id, following->id);
1072
1079
return unit_start(following);
1119
1126
return -EALREADY;
1121
1128
if ((following = unit_following(u))) {
1122
log_debug("Redirecting stop request from %s to %s.", u->id, following->id);
1129
log_debug_unit(u->id, "Redirecting stop request from %s to %s.",
1130
u->id, following->id);
1123
1131
return unit_stop(following);
1159
1167
return -ENOEXEC;
1161
1169
if ((following = unit_following(u))) {
1162
log_debug("Redirecting reload request from %s to %s.", u->id, following->id);
1170
log_debug_unit(u->id, "Redirecting reload request from %s to %s.",
1171
u->id, following->id);
1163
1172
return unit_reload(following);
1212
1221
if (unit_pending_active(other))
1215
log_info("Service %s is not needed anymore. Stopping.", u->id);
1224
log_info_unit(u->id, "Service %s is not needed anymore. Stopping.", u->id);
1217
1226
/* Ok, nobody needs us anymore. Sniff. Then let's commit suicide */
1218
1227
manager_add_job(u->manager, JOB_STOP, u, JOB_FAIL, true, NULL, NULL);
1240
1249
!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
1241
1250
manager_add_job(u->manager, JOB_START, other, JOB_FAIL, false, NULL, NULL);
1243
SET_FOREACH(other, u->dependencies[UNIT_REQUISITE], i)
1244
if (!set_get(u->dependencies[UNIT_AFTER], other) &&
1245
!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
1246
manager_add_job(u->manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
1248
1252
SET_FOREACH(other, u->dependencies[UNIT_WANTS], i)
1249
1253
if (!set_get(u->dependencies[UNIT_AFTER], other) &&
1250
1254
!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
1309
1313
if (set_size(u->dependencies[UNIT_ON_FAILURE]) <= 0)
1312
log_info("Triggering OnFailure= dependencies of %s.", u->id);
1316
log_info_unit(u->id, "Triggering OnFailure= dependencies of %s.", u->id);
1314
1318
SET_FOREACH(other, u->dependencies[UNIT_ON_FAILURE], i) {
1317
if ((r = manager_add_job(u->manager, JOB_START, other, u->on_failure_isolate ? JOB_ISOLATE : JOB_REPLACE, true, NULL, NULL)) < 0)
1318
log_error("Failed to enqueue OnFailure= job: %s", strerror(-r));
1321
r = manager_add_job(u->manager, JOB_START, other, u->on_failure_isolate ? JOB_ISOLATE : JOB_REPLACE, true, NULL, NULL);
1323
log_error_unit(u->id, "Failed to enqueue OnFailure= job: %s", strerror(-r));
1454
1459
check_unneeded_dependencies(u);
1456
1461
if (ns != os && ns == UNIT_FAILED) {
1457
log_struct_unit(LOG_NOTICE,
1459
"MESSAGE=Unit %s entered failed state", u->id,
1462
log_notice_unit(u->id,
1463
"MESSAGE=Unit %s entered failed state.", u->id);
1461
1464
unit_trigger_on_failure(u);
1522
1525
int unit_watch_fd(Unit *u, int fd, uint32_t events, Watch *w) {
1523
struct epoll_event ev;
1526
struct epoll_event ev = {
1526
1532
assert(fd >= 0);
1528
1534
assert(w->type == WATCH_INVALID || (w->type == WATCH_FD && w->fd == fd && w->data.unit == u));
1534
1536
if (epoll_ctl(u->manager->epoll_fd,
1535
1537
w->type == WATCH_INVALID ? EPOLL_CTL_ADD : EPOLL_CTL_MOD,
1624
1624
if (w->type == WATCH_INVALID) {
1625
struct epoll_event ev;
1629
ev.events = EPOLLIN;
1625
struct epoll_event ev = {
1631
1630
if (epoll_ctl(u->manager->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0)
2587
t = unit_find_dropin_paths(u);
2588
loaded_cnt = strv_length(t);
2589
current_cnt = strv_length(u->dropin_paths);
2591
if (loaded_cnt == current_cnt) {
2592
if (loaded_cnt == 0)
2595
if (strv_overlap(u->dropin_paths, t)) {
2596
STRV_FOREACH(path, u->dropin_paths) {
2598
if (stat(*path, &st) < 0)
2601
if (u->dropin_mtime > 0 &&
2602
timespec_load(&st.st_mtim) > u->dropin_mtime)
2588
2613
void unit_reset_failed(Unit *u) {
2644
2669
return UNIT_VTABLE(u)->kill(u, w, signo, error);
2672
int unit_kill_common(
2682
if (who == KILL_MAIN && main_pid <= 0) {
2684
dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no main processes", unit_type_to_string(u->type));
2686
dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "No main process to kill");
2690
if (who == KILL_CONTROL && control_pid <= 0) {
2691
if (control_pid < 0)
2692
dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no control processes", unit_type_to_string(u->type));
2694
dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
2698
if (who == KILL_CONTROL || who == KILL_ALL)
2699
if (control_pid > 0)
2700
if (kill(control_pid, signo) < 0)
2703
if (who == KILL_MAIN || who == KILL_ALL)
2705
if (kill(main_pid, signo) < 0)
2708
if (who == KILL_ALL) {
2709
_cleanup_set_free_ Set *pid_set = NULL;
2712
pid_set = set_new(trivial_hash_func, trivial_compare_func);
2716
/* Exclude the control/main pid from being killed via the cgroup */
2717
if (control_pid > 0) {
2718
q = set_put(pid_set, LONG_TO_PTR(control_pid));
2724
q = set_put(pid_set, LONG_TO_PTR(main_pid));
2729
q = cgroup_bonding_kill_list(u->cgroup_bondings, signo, false, false, pid_set, NULL);
2730
if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT)
2647
2737
int unit_following_set(Unit *u, Set **s) {
2821
2911
mkdir_p(p, 0755);
2822
return write_one_line_file_atomic_label(q, data);
2912
return write_string_file_atomic_label(q, data);
2825
2915
int unit_remove_drop_in(Unit *u, bool runtime, const char *name) {