core/service: check error first and log about errno

Follow-up for becdfcb9f1
This commit is contained in:
Mike Yuan
2023-10-19 21:37:39 +08:00
parent f65a40fb0b
commit bca0805311
+2 -2
View File
@@ -1074,10 +1074,10 @@ static int service_is_suitable_main_pid(Service *s, PidRef *pid, int prio) {
return log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(EPERM), "New main PID "PID_FMT" is the control process, refusing.", pid->pid);
r = pidref_is_alive(pid);
if (r < 0)
return log_unit_full_errno(UNIT(s), prio, r, "Failed to check if main PID "PID_FMT" exists or is a zombie: %m", pid->pid);
if (r == 0)
return log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(ESRCH), "New main PID "PID_FMT" does not exist or is a zombie.", pid->pid);
if (r < 0)
return log_unit_full_errno(UNIT(s), prio, r, "Failed to check if main PID "PID_FMT" exists or is a zombie.", pid->pid);
owner = manager_get_unit_by_pidref(UNIT(s)->manager, pid);
if (owner == UNIT(s)) {