aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-11-07 19:06:54 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2025-11-07 19:06:54 +0000
commit43253d337ef7a0b74e482e8bf847cb7c12744da0 (patch)
treeb2e2e7289d7d99cc9ed87b9fdcf8cace4f7e7b05
parent1667855c0c05f26b378ed8a011336770485321e5 (diff)
downloads6-43253d337ef7a0b74e482e8bf847cb7c12744da0.tar.gz
POSIX guarantees that pid == pgid for session leaders!
-rw-r--r--src/include/s6/supervise.h4
-rw-r--r--src/libs6/s6_svstatus_pack.c5
-rw-r--r--src/libs6/s6_svstatus_unpack.c14
-rw-r--r--src/supervision/s6-supervise.c31
-rw-r--r--src/supervision/s6-svstat.c16
5 files changed, 23 insertions, 47 deletions
diff --git a/src/include/s6/supervise.h b/src/include/s6/supervise.h
index dc71cea..066cb50 100644
--- a/src/include/s6/supervise.h
+++ b/src/include/s6/supervise.h
@@ -12,7 +12,7 @@
#define S6_SUPERVISE_EVENTDIR "event"
#define S6_SVSCAN_CTLDIR ".s6-svscan"
#define S6_SVSTATUS_FILENAME S6_SUPERVISE_CTLDIR "/status"
-#define S6_SVSTATUS_SIZE 43
+#define S6_SVSTATUS_SIZE 35
#define S6_DTALLY_FILENAME S6_SUPERVISE_CTLDIR "/death_tally"
#define S6_MAX_DEATH_TALLY 4096
@@ -26,7 +26,6 @@ struct s6_svstatus_s
tain stamp ;
tain readystamp ;
pid_t pid ;
- pid_t pgid ;
int wstat ;
unsigned int flagpaused : 1 ;
unsigned int flagfinishing : 1 ;
@@ -39,7 +38,6 @@ struct s6_svstatus_s
.stamp = TAIN_ZERO, \
.readystamp = TAIN_ZERO, \
.pid = 0, \
- .pgid = 0, \
.wstat = 0, \
.flagpaused = 0, \
.flagfinishing = 0, \
diff --git a/src/libs6/s6_svstatus_pack.c b/src/libs6/s6_svstatus_pack.c
index 5e1c7d8..a769c08 100644
--- a/src/libs6/s6_svstatus_pack.c
+++ b/src/libs6/s6_svstatus_pack.c
@@ -11,9 +11,8 @@ void s6_svstatus_pack (char *pack, s6_svstatus_t const *sv)
tain_pack(pack, &sv->stamp) ;
tain_pack(pack + 12, &sv->readystamp) ;
uint64_pack_big(pack + 24, (uint64_t)sv->pid) ;
- uint64_pack_big(pack + 32, (uint64_t)sv->pgid) ;
- uint16_pack_big(pack + 40, (uint16_t)sv->wstat) ;
- pack[42] =
+ uint16_pack_big(pack + 32, (uint16_t)sv->wstat) ;
+ pack[34] =
sv->flagpaused |
(sv->flagfinishing << 1) |
(sv->flagwantup << 2) |
diff --git a/src/libs6/s6_svstatus_unpack.c b/src/libs6/s6_svstatus_unpack.c
index b9b5d78..59ab4cd 100644
--- a/src/libs6/s6_svstatus_unpack.c
+++ b/src/libs6/s6_svstatus_unpack.c
@@ -1,9 +1,11 @@
/* ISC license. */
#include <stdint.h>
+
#include <skalibs/uint16.h>
#include <skalibs/uint64.h>
#include <skalibs/tai.h>
+
#include <s6/supervise.h>
void s6_svstatus_unpack (char const *pack, s6_svstatus_t *sv)
@@ -14,12 +16,10 @@ void s6_svstatus_unpack (char const *pack, s6_svstatus_t *sv)
tain_unpack(pack + 12, &sv->readystamp) ;
uint64_unpack_big(pack + 24, &pid) ;
sv->pid = pid ;
- uint64_unpack_big(pack + 32, &pid) ;
- sv->pgid = pid ;
- uint16_unpack_big(pack + 40, &wstat) ;
+ uint16_unpack_big(pack + 32, &wstat) ;
sv->wstat = wstat ;
- sv->flagpaused = pack[42] & 1 ;
- sv->flagfinishing = !!(pack[42] & 2) ;
- sv->flagwantup = !!(pack[42] & 4) ;
- sv->flagready = !!(pack[42] & 8) ;
+ sv->flagpaused = pack[34] & 1 ;
+ sv->flagfinishing = !!(pack[34] & 2) ;
+ sv->flagwantup = !!(pack[34] & 4) ;
+ sv->flagready = !!(pack[34] & 8) ;
}
diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c
index ca44fc8..50a739f 100644
--- a/src/supervision/s6-supervise.c
+++ b/src/supervision/s6-supervise.c
@@ -138,7 +138,6 @@ static inline int read_downsig (void)
static void set_down_and_ready (char const *s, unsigned int n)
{
status.pid = 0 ;
- status.pgid = 0 ;
status.flagfinishing = 0 ;
status.flagready = 1 ;
state = DOWN ;
@@ -163,7 +162,7 @@ static void bail (void)
static void killI (void)
{
- if (status.pgid > 0) killpg(status.pgid, SIGINT) ;
+ killpg(status.pid, SIGINT) ;
}
static void sigint (void)
@@ -267,27 +266,21 @@ static void killr (void)
static void killP (void)
{
- if (status.pgid > 0)
- {
- killpg(status.pgid, SIGSTOP) ;
- status.flagpaused = 1 ;
- announce() ;
- }
+ killpg(status.pid, SIGSTOP) ;
+ status.flagpaused = 1 ;
+ announce() ;
}
static void killC (void)
{
- if (status.pgid > 0)
- {
- killpg(status.pgid, SIGCONT) ;
- status.flagpaused = 0 ;
- announce() ;
- }
+ killpg(status.pid, SIGCONT) ;
+ status.flagpaused = 0 ;
+ announce() ;
}
static void killK (void)
{
- if (status.pgid > 0) killpg(status.pgid, SIGKILL) ;
+ killpg(status.pid, SIGKILL) ;
}
static void trystart (void)
@@ -388,9 +381,6 @@ static void trystart (void)
fd_close(notifyp[1]) ;
notifyfd = notifyp[0] ;
}
- status.pgid = getsid(status.pid) ;
- if (status.pgid == -1)
- strerr_warnwu1sys("getsid (process group control commands will have no effect)") ;
settimeout_infinite() ;
nextstart = tain_zero ;
state = UP ;
@@ -462,7 +452,7 @@ static int uplastup_z (void)
char fmt0[UINT_FMT] ;
char fmt1[UINT_FMT] ;
char fmt2[PID_FMT] ;
- char const *cargv[6] = { "finish", fmt0, fmt1, servicename, status.pgid > 0 ? fmt2 : "-1", 0 } ;
+ char const *cargv[6] = { "finish", fmt0, fmt1, servicename, fmt2, 0 } ;
status.flagpaused = 0 ;
status.flagready = 0 ;
@@ -475,7 +465,7 @@ static int uplastup_z (void)
}
fmt0[uint_fmt(fmt0, WIFSIGNALED(status.wstat) ? 256 : WEXITSTATUS(status.wstat))] = 0 ;
fmt1[uint_fmt(fmt1, WTERMSIG(status.wstat))] = 0 ;
- if (status.pgid > 0) fmt2[pid_fmt(fmt2, status.pgid)] = 0 ;
+ fmt2[pid_fmt(fmt2, status.pid)] = 0 ;
if (!read_uint("max-death-tally", &n)) n = 100 ;
if (n > S6_MAX_DEATH_TALLY) n = S6_MAX_DEATH_TALLY ;
@@ -509,7 +499,6 @@ static int uplastup_z (void)
tain_add_g(&deadline, &tto) ;
else settimeout_infinite() ;
}
- status.pgid = getpgid(status.pid) ;
status.flagfinishing = 1 ;
announce() ;
ftrigw_notifyb_nosig(S6_SUPERVISE_EVENTDIR, "d", 1) ;
diff --git a/src/supervision/s6-svstat.c b/src/supervision/s6-svstat.c
index 930570c..318e89c 100644
--- a/src/supervision/s6-svstat.c
+++ b/src/supervision/s6-svstat.c
@@ -69,16 +69,6 @@ static void pr_pid (buffer *b, s6_svstatus_t const *st)
else buffer_putsnoflush(b, "-1") ;
}
-static void pr_pgid (buffer *b, s6_svstatus_t const *st)
-{
- if (st->pgid > 0)
- {
- char fmt[PID_FMT] ;
- buffer_putnoflush(b, fmt, pid_fmt(fmt, st->pgid)) ;
- }
- else buffer_putsnoflush(b, "-1") ;
-}
-
static void pr_tain (buffer *b, tain const *a)
{
char fmt[TIMESTAMP] ;
@@ -152,7 +142,7 @@ static funcmap_t const fmtable[] =
{ .s = "exitcode", .f = &pr_exitcode },
{ .s = "normallyup", .f = &pr_normallyup },
{ .s = "paused", .f = &pr_paused },
- { .s = "pgid", .f = &pr_pgid },
+ { .s = "pgid", .f = &pr_pid },
{ .s = "pid", .f = &pr_pid },
{ .s = "ready", .f = &pr_ready },
{ .s = "readyfor", .f = &pr_readyseconds },
@@ -200,7 +190,7 @@ static void legacy (s6_svstatus_t *st, int flagnum)
buffer_putnoflush(buffer_1small,"up (pid ", 8) ;
buffer_putnoflush(buffer_1small, fmt, pid_fmt(fmt, status.pid)) ;
buffer_putnoflush(buffer_1small, " pgid ", 6) ;
- buffer_putnoflush(buffer_1small, fmt, pid_fmt(fmt, status.pgid)) ;
+ buffer_putnoflush(buffer_1small, fmt, pid_fmt(fmt, status.pid)) ;
buffer_putnoflush(buffer_1small, ") ", 2) ;
}
else
@@ -277,7 +267,7 @@ int main (int argc, char const *const *argv)
case 'N' : checkfields() ; fields[n++] = &pr_normallyup ; break ;
case 'r' : checkfields() ; fields[n++] = &pr_ready ; break ;
case 'p' : checkfields() ; fields[n++] = &pr_pid ; break ;
- case 'g' : checkfields() ; fields[n++] = &pr_pgid ; break ;
+ case 'g' : checkfields() ; fields[n++] = &pr_pid ; break ;
case 'e' : checkfields() ; fields[n++] = &pr_exitcode ; break ;
case 's' : checkfields() ; fields[n++] = &pr_signal ; break ;
case 't' : checkfields() ; fields[n++] = &pr_upseconds ; break ;