Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137325006
D28684.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D28684.diff
View Options
diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/h_fileactions.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/h_fileactions.c
--- a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/h_fileactions.c
+++ b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/h_fileactions.c
@@ -49,48 +49,61 @@
main(int argc, char **argv)
{
int res = EXIT_SUCCESS;
+ long lowfd;
char buf[BUFSIZE];
struct stat sb0, sb1;
+ if (argc < 2) {
+ fprintf(stderr, "%s: Not enough arguments: %d\n", getprogname(),
+ argc);
+ return EXIT_FAILURE;
+ }
+ lowfd = strtol(argv[1], NULL, 10);
+ if (lowfd < 3) {
+ fprintf(stderr, "%s: Invalid lowfd %d (as str: %s) \n",
+ getprogname(), argc, argv[1]);
+ return EXIT_FAILURE;
+ }
+
strcpy(buf, "test...");
- /* file desc 3 should be closed via addclose */
- if (read(3, buf, BUFSIZE) != -1 || errno != EBADF) {
- fprintf(stderr, "%s: filedesc 3 is not closed\n",
+ /* First fd should be closed via addclose */
+ if (read(lowfd, buf, BUFSIZE) != -1 || errno != EBADF) {
+ fprintf(stderr, "%s: first filedesc is not closed\n",
getprogname());
res = EXIT_FAILURE;
}
- /* file desc 4 should be closed via closeonexec */
- if (read(4, buf, BUFSIZE) != -1 || errno != EBADF) {
- fprintf(stderr, "%s: filedesc 4 is not closed\n",
+ /* Next file desc should be closed via closeonexec */
+ if (read(lowfd + 1, buf, BUFSIZE) != -1 || errno != EBADF) {
+ fprintf(stderr, "%s: filedesc +1 is not closed\n",
getprogname());
res = EXIT_FAILURE;
}
- /* file desc 5 remains open */
- if (write(5, buf, BUFSIZE) <= 0) {
- fprintf(stderr, "%s: could not write to filedesc 5\n",
+ /* file desc + 2 remains open */
+ if (write(lowfd + 2, buf, BUFSIZE) <= 0) {
+ fprintf(stderr, "%s: could not write to filedesc +2\n",
getprogname());
res = EXIT_FAILURE;
}
- /* file desc 6 should be open (via addopen) */
- if (write(6, buf, BUFSIZE) <= 0) {
- fprintf(stderr, "%s: could not write to filedesc 6\n",
+ /* file desc + 3 should be open (via addopen) */
+ if (write(lowfd + 3, buf, BUFSIZE) <= 0) {
+ fprintf(stderr, "%s: could not write to filedesc +3\n",
getprogname());
res = EXIT_FAILURE;
}
- /* file desc 7 should refer to stdout */
+ /* file desc + 4 should refer to stdout */
fflush(stdout);
if (fstat(fileno(stdout), &sb0) != 0) {
fprintf(stderr, "%s: could not fstat stdout\n",
getprogname());
res = EXIT_FAILURE;
}
- if (fstat(7, &sb1) != 0) {
- fprintf(stderr, "%s: could not fstat filedesc 7\n",
+ if (fstat(lowfd + 4, &sb1) != 0) {
+ fprintf(stderr, "%s: could not fstat filedesc +4\n",
getprogname());
res = EXIT_FAILURE;
}
- if (write(7, buf, strlen(buf)) <= 0) {
- fprintf(stderr, "%s: could not write to filedesc 7\n",
+ if (write(lowfd + 4, buf, strlen(buf)) <= 0) {
+ fprintf(stderr, "%s: could not write to filedesc +4\n",
getprogname());
res = EXIT_FAILURE;
}
diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c
--- a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c
+++ b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c
@@ -301,26 +301,34 @@
{
int fd1, fd2, fd3, status, err;
pid_t pid;
- char * const args[2] = { __UNCONST("h_fileactions"), NULL };
+ char *args[3] = { __UNCONST("h_fileactions"), NULL, NULL };
+ int lowfd;
+ char lowfdstr[32];
char helper[FILENAME_MAX];
posix_spawn_file_actions_t fa;
posix_spawn_file_actions_init(&fa);
- closefrom(fileno(stderr)+1);
+ /* Note: this assumes no gaps in the fd table */
+ lowfd = open("/", O_RDONLY);
+ ATF_REQUIRE(lowfd > 0);
+ ATF_REQUIRE_EQ(0, close(lowfd));
+ snprintf(lowfdstr, sizeof(lowfdstr), "%d", lowfd);
+ args[1] = lowfdstr;
fd1 = open("/dev/null", O_RDONLY);
- ATF_REQUIRE(fd1 == 3);
+ ATF_REQUIRE_EQ(fd1, lowfd);
fd2 = open("/dev/null", O_WRONLY, O_CLOEXEC);
- ATF_REQUIRE(fd2 == 4);
+ ATF_REQUIRE_EQ(fd2, lowfd + 1);
fd3 = open("/dev/null", O_WRONLY);
- ATF_REQUIRE(fd3 == 5);
+ ATF_REQUIRE_EQ(fd3, lowfd + 2);
posix_spawn_file_actions_addclose(&fa, fd1);
- posix_spawn_file_actions_addopen(&fa, 6, "/dev/null", O_RDWR, 0);
- posix_spawn_file_actions_adddup2(&fa, 1, 7);
+ posix_spawn_file_actions_addopen(&fa, lowfd + 3, "/dev/null", O_RDWR,
+ 0);
+ posix_spawn_file_actions_adddup2(&fa, 1, lowfd + 4);
snprintf(helper, sizeof helper, "%s/h_fileactions",
atf_tc_get_config_var(tc, "srcdir"));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 23, 11:56 AM (1 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26013147
Default Alt Text
D28684.diff (4 KB)
Attached To
Mode
D28684: libc: Fix t_spawn_fileactions test after ATF update
Attached
Detach File
Event Timeline
Log In to Comment