From: Yu Watanabe Date: Tue, 8 Jul 2025 08:37:33 +0000 (+0900) Subject: core: allow to use PIDFile= in user session services X-Git-Tag: v258-rc1~135^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e269126778875e7e8927d795132109fb9a9b3a1;p=thirdparty%2Fsystemd.git core: allow to use PIDFile= in user session services Fixes #38108. Co-authored-by: 铝箔 <38349409+Sodium-Aluminate@users.noreply.github.com> --- diff --git a/src/core/service.c b/src/core/service.c index 5f03a462ec6..aabaaedf5df 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1204,11 +1204,13 @@ static int service_load_pid_file(Service *s, bool may_warn) { if (fstat(fileno(f), &st) < 0) return log_unit_error_errno(UNIT(s), errno, "Failed to fstat() PID file '%s': %m", s->pid_file); - if (st.st_uid != 0) + if (st.st_uid != getuid()) return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(EPERM), - "New main PID "PID_FMT" from PID file does not belong to service, and PID file is not owned by root. Refusing.", pidref.pid); + "New main PID "PID_FMT" from PID file does not belong to service, and PID file is owned by "UID_FMT" (must be owned by "UID_FMT"). Refusing.", + pidref.pid, st.st_uid, getuid()); - log_unit_debug(UNIT(s), "New main PID "PID_FMT" does not belong to service, accepting anyway since PID file is owned by root.", pidref.pid); + log_unit_debug(UNIT(s), "New main PID "PID_FMT" does not belong to service, accepting anyway since PID file is owned by "UID_FMT".", + pidref.pid, st.st_uid); } if (s->main_pid_known) {