Try to fix case where we can't getpgid() treating pid == pgid.
authorDavin McCall <davmac@davmac.org>
Fri, 24 May 2019 10:54:02 +0000 (20:54 +1000)
committerDavin McCall <davmac@davmac.org>
Fri, 24 May 2019 10:54:02 +0000 (20:54 +1000)
The logic behind this is: if we can't use getpgid(), it's because the
process is in a different session. If that's the case, it must be a
process group leader with pgid == pid.

src/baseproc-service.cc

index a413ebea7a2a5fdc562f85de2b0c69794d962477..88bb6e60a208c9fd1203bd21b6b72e5e7768a940 100644 (file)
@@ -332,13 +332,9 @@ void base_process_service::kill_pg(int signo) noexcept
         pid_t pgid = bp_sys::getpgid(pid);
         if (pgid == -1) {
             // On some OSes (eg OpenBSD) we aren't allowed to get the pgid of a process in a different
-            // session. Just kill the process in that case.
-            log(loglevel_t::INFO, get_name(), ": can't signal process group: ", strerror(errno));
-            log(loglevel_t::INFO, get_name(), ": will signal process only "
-                    "(consider using 'options = signal-process-only')");
-
-            bp_sys::kill(pid, signo);
-            return;
+            // session. If the process is in a different session, however, it must be a process group
+            // leader and the pgid must equal the process id.
+            pgid = pid;
         }
         bp_sys::kill(-pgid, signo);
     }