Module Name: src
Committed By: martin
Date: Sun May 2 11:18:11 UTC 2021
Modified Files:
src/tests/lib/libc/gen/posix_spawn: h_spawn.c t_spawnattr.c
Log Message:
Add test for POSIX_SPAWN_RESETIDS flag
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/gen/posix_spawn/h_spawn.c
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/libc/gen/posix_spawn/h_spawn.c
diff -u src/tests/lib/libc/gen/posix_spawn/h_spawn.c:1.1 src/tests/lib/libc/gen/posix_spawn/h_spawn.c:1.2
--- src/tests/lib/libc/gen/posix_spawn/h_spawn.c:1.1 Mon Feb 13 21:03:08 2012
+++ src/tests/lib/libc/gen/posix_spawn/h_spawn.c Sun May 2 11:18:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: h_spawn.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+/* $NetBSD: h_spawn.c,v 1.2 2021/05/02 11:18:11 martin Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -32,6 +32,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
int
main(int argc, char **argv)
@@ -39,11 +41,25 @@ main(int argc, char **argv)
unsigned long ret;
char *endp;
- if (argc < 2) {
+ if (argc == 2 && strcmp(argv[1], "--resetids") == 0) {
+ if (getuid() != geteuid() || getgid() != getegid()) {
+ fprintf(stderr, "uid/gid do not match effective ids, "
+ "uid: %d euid: %d gid: %d egid: %d\n",
+ getuid(), geteuid(), getgid(), getegid());
+ exit(255);
+ }
+ return 0;
+ } else if (argc != 2) {
fprintf(stderr, "usage:\n\t%s (retcode)\n", getprogname());
exit(255);
}
ret = strtoul(argv[1], &endp, 10);
+ if (*endp != 0) {
+ fprintf(stderr,
+ "invalid arg: %s\n"
+ "usage:\n\t%s (retcode)\n", endp, getprogname());
+ exit(255);
+ }
fprintf(stderr, "%s exiting with status %lu\n", getprogname(), ret);
return ret;
Index: src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c
diff -u src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.3 src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.4
--- src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c:1.3 Thu Dec 21 03:31:43 2017
+++ src/tests/lib/libc/gen/posix_spawn/t_spawnattr.c Sun May 2 11:18:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: t_spawnattr.c,v 1.3 2017/12/21 03:31:43 christos Exp $ */
+/* $NetBSD: t_spawnattr.c,v 1.4 2021/05/02 11:18:11 martin Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -165,9 +165,43 @@ ATF_TC_BODY(t_spawnattr, tc)
posix_spawnattr_destroy(&attr);
}
+ATF_TC(t_spawn_resetids);
+
+ATF_TC_HEAD(t_spawn_resetids, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "posix_spawn a child and with POSIX_SPAWN_RESETIDS flag");
+}
+
+ATF_TC_BODY(t_spawn_resetids, tc)
+{
+ char buf[FILENAME_MAX];
+ char * const args[] = {
+ __UNCONST("h_spawn"), __UNCONST("--resetids"), NULL
+ };
+ posix_spawnattr_t attr;
+ int err, status;
+ pid_t pid;
+
+ posix_spawnattr_init(&attr);
+ posix_spawnattr_setflags(&attr, POSIX_SPAWN_RESETIDS);
+
+ snprintf(buf, sizeof buf, "%s/h_spawn",
+ atf_tc_get_config_var(tc, "srcdir"));
+
+ err = posix_spawn(&pid, buf, NULL, &attr, args, NULL);
+ ATF_REQUIRE(err == 0);
+ ATF_REQUIRE(pid > 0);
+ waitpid(pid, &status, 0);
+ ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+
+ posix_spawnattr_destroy(&attr);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, t_spawnattr);
+ ATF_TP_ADD_TC(tp, t_spawn_resetids);
return atf_no_error();
}