From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Subject: bug#35550: Installer: wpa_supplicant fails to start Date: Tue, 07 May 2019 10:05:08 +0200 Message-ID: <87imumadvv.fsf@gnu.org> References: <87sgtv8hcz.fsf@gnu.org> <875zqr8dnw.fsf@gnu.org> <87k1f4y23d.fsf@gnu.org> <20190506220030.4a608b37@scratchpost.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([209.51.188.92]:55138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNv72-0003uK-Q6 for bug-guix@gnu.org; Tue, 07 May 2019 04:06:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNv6z-00008W-1V for bug-guix@gnu.org; Tue, 07 May 2019 04:06:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44602) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNv6x-00006n-8c for bug-guix@gnu.org; Tue, 07 May 2019 04:06:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hNv6w-0001A8-G1 for bug-guix@gnu.org; Tue, 07 May 2019 04:06:02 -0400 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <20190506220030.4a608b37@scratchpost.org> (Danny Milosavljevic's message of "Mon, 6 May 2019 22:00:30 +0200") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Danny Milosavljevic Cc: sirgazil , 35550@debbugs.gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Danny, Danny Milosavljevic skribis: > what happens when the loop reads the pid file when it contains just half = of a > numeral? It won't detect it, right? Correct. I=E2=80=99m proposing the addition below to be on the verrrry safe side. WDYT? The weird thing, as I mentioned earlier, is that systemd and Pies do not protect against truncated PID files, and I couldn=E2=80=99t find any =E2=80=9Cdocumentation=E2=80=9D of the problem on the intertubes. For syst= emd it=E2=80=99s maybe less of a problem since services are started in a cgroup, I think. Thanks, Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index b937609..ef27d88 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -709,10 +709,16 @@ results." set when starting a service." (environ)) -(define* (read-pid-file file #:key (max-delay 5)) +(define* (read-pid-file file #:key (max-delay 5) + (validate-pid? #f)) "Wait for MAX-DELAY seconds for FILE to show up, and read its content as a number. Return #f if FILE was not created or does not contain a number; -otherwise return the number that was read (a PID)." +otherwise return the number that was read (a PID). + +When VALIDATE-PID? is true, succeed if and only if the number that was read is +the PID of an existing process in the current PID namespace. This test cannot +be used if FILE might contain a PID from another PID namespace (i.e., the +daemon writing FILE is running in a separate PID namespace.)" (define start (current-time)) (let loop () @@ -736,11 +742,13 @@ otherwise return the number that was read (a PID)." (try-again)) ((? integer? pid) ;; It's possible, though unlikely, that PID is not a valid PID, for - ;; instance because writes to FILE did not complete. However, we - ;; don't do (kill pid 0) because if the process lives in a separate - ;; PID namespace, then PID is probably invalid in our own - ;; namespace. - pid))) + ;; instance because writes to FILE did not complete. When + ;; VALIDATE-PID? is true, check that PID is valid in the current + ;; PID namespace. + (if (or (not validate-pid?) + (catch-system-error (kill pid 0) #t)) + pid + (try-again))))) (lambda args (let ((errno (system-error-errno args))) (if (= ENOENT errno) @@ -931,7 +939,8 @@ start." environment-variables))) (if pid-file (match (read-pid-file pid-file - #:max-delay pid-file-timeout) + #:max-delay pid-file-timeout + #:validate-pid? #t) (#f (catch-system-error (kill pid SIGTERM)) #f) --=-=-=--