I cannot duplicate this failure locally, but in GHA the following test
case fails with
Process group 0 != expected 704
child exited with code 1
FAIL winsup.api/spawnpgid.exe (exit status: 1)
I suspect there must be a race between the child process calling getpgid
and the parent running "vchild->pgid = myself->pgid" in sigproc.cc
proc_subproc PROC_ADD_CHILD.
---
winsup/testsuite/Makefile.am | 1 +
winsup/testsuite/winsup.api/spawnpgid.c | 59 +++++++++++++++++++++++++
2 files changed, 60 insertions(+)
create mode 100644 winsup/testsuite/winsup.api/spawnpgid.c
diff --git a/winsup/testsuite/Makefile.am b/winsup/testsuite/Makefile.am
index 67898f62a6..8f101695d5 100644
--- a/winsup/testsuite/Makefile.am
+++ b/winsup/testsuite/Makefile.am
@@ -48,6 +48,7 @@ check_PROGRAMS = \
winsup.api/shmtest \
winsup.api/sigchld \
winsup.api/signal-into-win32-api \
+ winsup.api/spawnpgid \
winsup.api/systemcall \
winsup.api/user_malloc \
winsup.api/waitpid \
diff --git a/winsup/testsuite/winsup.api/spawnpgid.c
b/winsup/testsuite/winsup.api/spawnpgid.c
new file mode 100644
index 0000000000..214af9306d
--- /dev/null
+++ b/winsup/testsuite/winsup.api/spawnpgid.c
@@ -0,0 +1,59 @@
+#include <process.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int handle_child (char *arg)
+{
+ pid_t pgid = getpgid (0);
+ pid_t expectedpgid = atoi (arg);
+ if (!expectedpgid)
+ expectedpgid = getpid ();
+ if (pgid != expectedpgid)
+ {
+ fprintf (stderr, "Process group %d != expected %d\n", pgid,
expectedpgid);
+ return 1;
+ }
+ return 0;
+}
+
+int main (int argc, char **argv)
+{
+ int status;
+ char buf[12];
+ const char * const childargv[] = {"pgroup", "--child", buf, NULL};
+
+ /* unbuffer stdout */
+ setvbuf(stdout, NULL, _IONBF, 0);
+
+ if (argc == 3 && !strcmp (argv[1], "--child"))
+ return handle_child (argv[2]);
+
+ /* ensure pgroup inherited by default */
+ sprintf (buf, "%d", getpgid (0));
+ status = spawnv (_P_WAIT, "/proc/self/exe", childargv);
+ if (status < 0)
+ {
+ perror ("spawnv");
+ return 1;
+ }
+ else if (WIFSIGNALED (status))
+ {
+ fprintf (stderr, "child termintated with signal %d\n", WTERMSIG
(status));
+ return 1;
+ }
+ else if (WIFEXITED (status) && WEXITSTATUS (status) != 0)
+ {
+ fprintf (stderr, "child exited with code %d\n", WEXITSTATUS (status));
+ return 1;
+ }
+ else if (!WIFEXITED (status))
+ {
+ fprintf (stderr, "child terminated with status %x\n", status);
+ return 1;
+ }
+
+ return 0;
+}
--
2.49.0.windows.1
--
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple