aboutsummaryrefslogtreecommitdiff
path: root/posix/tst-posix_spawn-setsid.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2017-04-21 10:40:56 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2017-04-25 08:51:12 -0300
commitdaeb1fa2e1b33323e719015f5f546988bd4cc73b (patch)
treec09f990c8f116d298a1168c6b9620d94cb2ba1c1 /posix/tst-posix_spawn-setsid.c
parent9581e76dbb4a8dad8a4493ef6833685153edd1d9 (diff)
downloadglibc-daeb1fa2e1b33323e719015f5f546988bd4cc73b.zip
glibc-daeb1fa2e1b33323e719015f5f546988bd4cc73b.tar.gz
glibc-daeb1fa2e1b33323e719015f5f546988bd4cc73b.tar.bz2
[BZ 21340] add support for POSIX_SPAWN_SETSID
This patch adds support for the POSIX_SPAWN_SETSID flag. It was recently accepted by the Austin Group: http://austingroupbugs.net/view.php?id=1044 Checked on x86_64 Daurnimator <quae@daurnimator.com> Adhemerval Zanella <adhemerval.zanella@linaro.org> [BZ #21340] * posix/Makefile (tests): Add tst-posix_spawn-setsid to list of tests. * posix/spawn.h: define POSIX_SPAWN_SETSID flag. * posix/spawnattr_setflags.c (ALL_FLAGS): Add POSIX_SPAWN_SETSID to valid flags. * posix/tst-posix_spawn-setsid.c: Add test for POSIX_SPAWN_SETSID. * sysdeps/mach/hurd/spawni.c (__spawni): Implementation of POSIX_SPAWN_SETSID. * sysdeps/posix/spawni.c (__spawni): Likewise. * sysdeps/unix/sysv/linux/spawni.c (__spawni_child): Likewise. * NEWS: Add note about POSIX_SPAWN_SETSID support.
Diffstat (limited to 'posix/tst-posix_spawn-setsid.c')
-rw-r--r--posix/tst-posix_spawn-setsid.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/posix/tst-posix_spawn-setsid.c b/posix/tst-posix_spawn-setsid.c
new file mode 100644
index 0000000..256bd72
--- /dev/null
+++ b/posix/tst-posix_spawn-setsid.c
@@ -0,0 +1,95 @@
+/* Test posix_spawn setsid attribute.
+ Copyright (C) 2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <spawn.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+static void
+do_test_setsid (bool test_setsid)
+{
+ pid_t sid, child_sid;
+ int res;
+
+ /* Current session ID. */
+ sid = getsid(0);
+ if (sid == (pid_t) -1)
+ FAIL_EXIT1 ("getsid (0): %m");
+
+ posix_spawnattr_t attrp;
+ /* posix_spawnattr_init should not fail (it basically memset the
+ attribute). */
+ posix_spawnattr_init (&attrp);
+ if (test_setsid)
+ {
+ res = posix_spawnattr_setflags (&attrp, POSIX_SPAWN_SETSID);
+ if (res != 0)
+ {
+ errno = res;
+ FAIL_EXIT1 ("posix_spawnattr_setflags: %m");
+ }
+ }
+
+ /* Program to run. */
+ char *args[2] = { (char *) "true", NULL };
+ pid_t child;
+
+ res = posix_spawnp (&child, "true", NULL, &attrp, args, environ);
+ /* posix_spawnattr_destroy is noop. */
+ posix_spawnattr_destroy (&attrp);
+
+ if (res != 0)
+ {
+ errno = res;
+ FAIL_EXIT1 ("posix_spawnp: %m");
+ }
+
+ /* Child should have a different session ID than parent. */
+ child_sid = getsid (child);
+
+ if (child_sid == (pid_t) -1)
+ FAIL_EXIT1 ("getsid (%i): %m", child);
+
+ if (test_setsid)
+ {
+ if (child_sid == sid)
+ FAIL_EXIT1 ("child session ID matched parent one");
+ }
+ else
+ {
+ if (child_sid != sid)
+ FAIL_EXIT1 ("child session ID did not match parent one");
+ }
+}
+
+static int
+do_test (void)
+{
+ do_test_setsid (false);
+ do_test_setsid (true);
+
+ return 0;
+}
+
+#include <support/test-driver.c>