posix_spawn(): dup2() again this time on file_action_dup2.
* fixes #14322.
This commit is contained in:
parent
5d0fd0e422
commit
c90a0ee947
@ -408,7 +408,7 @@ process_file_actions(const posix_spawn_file_actions_t *_actions, int *errfd)
|
||||
return errno;
|
||||
}
|
||||
} else if (action->type == file_action_dup2) {
|
||||
if (dup2(action->action.dup2_action.srcfd, action->fd) != 0)
|
||||
if (dup2(action->action.dup2_action.srcfd, action->fd) == -1)
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ SimpleTest pthread_barrier_test : pthread_barrier_test.cpp ;
|
||||
SimpleTest posix_spawn_test : posix_spawn_test.cpp ;
|
||||
SimpleTest posix_spawn_redir_test : posix_spawn_redir_test.c ;
|
||||
SimpleTest posix_spawn_redir_err : posix_spawn_redir_err.c ;
|
||||
SimpleTest posix_spawn_pipe_test : posix_spawn_pipe_test.c ;
|
||||
SimpleTest posix_spawn_pipe_err : posix_spawn_pipe_err.c ;
|
||||
|
||||
# XSI tests
|
||||
SimpleTest xsi_msg_queue_test1 : xsi_msg_queue_test1.cpp ;
|
||||
|
10
src/tests/system/libroot/posix/posix_spawn_pipe_err.c
Normal file
10
src/tests/system/libroot/posix/posix_spawn_pipe_err.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include "posix_spawn_pipe_test.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
puts(testOut);
|
||||
fputs(testErr, stderr);
|
||||
return 0;
|
||||
}
|
56
src/tests/system/libroot/posix/posix_spawn_pipe_test.c
Normal file
56
src/tests/system/libroot/posix/posix_spawn_pipe_test.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include "posix_spawn_pipe_test.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define panic(n, str) if (n != 0) { perror(str); return 1; }
|
||||
#define readIdx 0
|
||||
#define writeIdx 1
|
||||
|
||||
int main() {
|
||||
int out[2], err[2];
|
||||
posix_spawn_file_actions_t fdops;
|
||||
pid_t pid;
|
||||
char* const argv[] = { "./posix_spawn_pipe_err", NULL };
|
||||
|
||||
panic(pipe(out), "pipe stdout");
|
||||
panic(pipe(err), "pipe stderr");
|
||||
|
||||
errno = posix_spawn_file_actions_init(&fdops);
|
||||
panic(errno, "init");
|
||||
errno = posix_spawn_file_actions_addclose(&fdops, out[readIdx]);
|
||||
panic(errno, "close stdout read");
|
||||
errno = posix_spawn_file_actions_adddup2(&fdops, out[writeIdx], 1);
|
||||
panic(errno, "dup2 stdout write");
|
||||
errno = posix_spawn_file_actions_addclose(&fdops, err[readIdx]);
|
||||
panic(errno, "close stderr read");
|
||||
errno = posix_spawn_file_actions_adddup2(&fdops, err[writeIdx], 2);
|
||||
panic(errno, "dup2 stderr write");
|
||||
errno = posix_spawn(&pid, "./posix_spawn_pipe_err", &fdops, NULL, argv, NULL);
|
||||
panic(errno, "spawn");
|
||||
|
||||
FILE *cOut = fdopen(out[readIdx], "r");
|
||||
if (cOut == NULL) panic(-1, "cOut");
|
||||
FILE *cErr = fdopen(err[readIdx], "r");
|
||||
if (cErr == NULL) panic(-1, "cErr");
|
||||
|
||||
char *buf = NULL;
|
||||
size_t bufsize = 0;
|
||||
getline(&buf, &bufsize, cOut);
|
||||
panic(ferror(cOut), "getline cOut");
|
||||
if (strcmp(buf, testOut) != 0) {
|
||||
printf("stdout got: %s", buf);
|
||||
printf("stdout exp: %s", testOut);
|
||||
}
|
||||
getline(&buf, &bufsize, cErr);
|
||||
panic(ferror(cErr), "getline cErr");
|
||||
if (strcmp(buf, testErr) != 0) {
|
||||
printf("stderr got: %s", buf);
|
||||
printf("stderr exp: %s", testErr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
5
src/tests/system/libroot/posix/posix_spawn_pipe_test.h
Normal file
5
src/tests/system/libroot/posix/posix_spawn_pipe_test.h
Normal file
@ -0,0 +1,5 @@
|
||||
#ifndef t_h
|
||||
#define t_h
|
||||
#define testOut "test out\n"
|
||||
#define testErr "test err\n"
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user