1 /* Test posix_spawn setsid attribute.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
24 #include <sys/resource.h>
27 #include <support/check.h>
30 do_test_setsid (bool test_setsid
)
35 /* Current session ID. */
37 if (sid
== (pid_t
) -1)
38 FAIL_EXIT1 ("getsid (0): %m");
40 posix_spawnattr_t attrp
;
41 /* posix_spawnattr_init should not fail (it basically memset the
43 posix_spawnattr_init (&attrp
);
46 res
= posix_spawnattr_setflags (&attrp
, POSIX_SPAWN_SETSID
);
50 FAIL_EXIT1 ("posix_spawnattr_setflags: %m");
55 char *args
[2] = { (char *) "true", NULL
};
58 res
= posix_spawnp (&child
, "true", NULL
, &attrp
, args
, environ
);
59 /* posix_spawnattr_destroy is noop. */
60 posix_spawnattr_destroy (&attrp
);
65 FAIL_EXIT1 ("posix_spawnp: %m");
68 /* Child should have a different session ID than parent. */
69 child_sid
= getsid (child
);
71 if (child_sid
== (pid_t
) -1)
72 FAIL_EXIT1 ("getsid (%i): %m", child
);
77 FAIL_EXIT1 ("child session ID matched parent one");
82 FAIL_EXIT1 ("child session ID did not match parent one");
89 do_test_setsid (false);
90 do_test_setsid (true);
95 #include <support/test-driver.c>