Just signal the process if we can't get the process group.
authorDavin McCall <davmac@davmac.org>
Wed, 22 May 2019 10:33:15 +0000 (20:33 +1000)
committerDavin McCall <davmac@davmac.org>
Wed, 22 May 2019 10:33:15 +0000 (20:33 +1000)
On OpenBSD (and possibly others) we can't get the process group of a
process that's in a different session, so fall back to signalling the
process.

src/baseproc-service.cc

index b6809c45a6ab79b2308c02ade495f5f96a0cda11..a0d41651a7159af619635a3c0a8221d7e9cc2028 100644 (file)
@@ -331,8 +331,13 @@ void base_process_service::kill_pg(int signo) noexcept
     else {
         pid_t pgid = bp_sys::getpgid(pid);
         if (pgid == -1) {
-            // only should happen if pid is invalid, which should never happen...
-            log(loglevel_t::ERROR, get_name(), ": can't signal process: ", strerror(errno));
+            // 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::WARN, get_name(), ": can't signal process group: ", strerror(errno));
+            log(loglevel_t::WARN, get_name(), ": will signal process only "
+                    "(consider using option = signal-process-only)");
+
+            bp_sys::kill(pid, signo);
             return;
         }
         bp_sys::kill(-pgid, signo);