unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Danny Milosavljevic <dannym@scratchpost.org>
Cc: sirgazil <sirgazil@zoho.com>, 35550@debbugs.gnu.org
Subject: bug#35550: Installer: wpa_supplicant fails to start
Date: Tue, 07 May 2019 10:05:08 +0200	[thread overview]
Message-ID: <87imumadvv.fsf@gnu.org> (raw)
In-Reply-To: <20190506220030.4a608b37@scratchpost.org> (Danny Milosavljevic's message of "Mon, 6 May 2019 22:00:30 +0200")

[-- Attachment #1: Type: text/plain, Size: 592 bytes --]

Hi Danny,

Danny Milosavljevic <dannym@scratchpost.org> 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’m 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’t find any
“documentation” of the problem on the intertubes.  For systemd it’s
maybe less of a problem since services are started in a cgroup, I think.

Thanks,
Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2388 bytes --]

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)

  reply	other threads:[~2019-05-07  8:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 19:31 bug#35550: Installer: wpa_supplicant fails to start Ludovic Courtès
2019-05-03 20:51 ` Ludovic Courtès
2019-05-04 15:28   ` Ludovic Courtès
2019-05-05 20:26   ` Ludovic Courtès
2019-05-05 22:21   ` Ludovic Courtès
2019-05-06 19:47     ` pelzflorian (Florian Pelz)
2019-05-07  7:53       ` Ludovic Courtès
2019-05-06 20:00     ` Danny Milosavljevic
2019-05-07  8:05       ` Ludovic Courtès [this message]
2019-05-08 14:32         ` Ludovic Courtès
2019-05-08 22:25           ` Ludovic Courtès
2019-05-09  6:46             ` pelzflorian (Florian Pelz)
2019-05-09 10:18               ` Ludovic Courtès
2019-05-11 18:13           ` Ludovic Courtès
2019-05-03 21:26 ` Ricardo Wurmus
2019-05-04  3:26 ` sirgazil
2019-05-04 12:49   ` Ludovic Courtès
2019-05-04 14:07     ` pelzflorian (Florian Pelz)
2019-05-04 15:32       ` Ludovic Courtès
2019-05-04 15:47         ` pelzflorian (Florian Pelz)
2019-05-04 21:14           ` Ludovic Courtès
2019-05-04 21:34             ` pelzflorian (Florian Pelz)
2019-05-05 16:29               ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imumadvv.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=35550@debbugs.gnu.org \
    --cc=dannym@scratchpost.org \
    --cc=sirgazil@zoho.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).