hrev52177 adds 1 changeset to branch 'master'
old head: 5d0fd0e4220b461e2021d5768ebaa936c13417f8
new head: c90a0ee947fa2beaf598f456b559c4c281c119cf
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=c90a0ee947fa+%5E5d0fd0e4220b
----------------------------------------------------------------------------
c90a0ee947fa: posix_spawn(): dup2() again this time on file_action_dup2.
* fixes #14322.
[ Jérôme Duval <jerome.duval@xxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev52177
Commit: c90a0ee947fa2beaf598f456b559c4c281c119cf
URL: https://git.haiku-os.org/haiku/commit/?id=c90a0ee947fa
Author: Jérôme Duval <jerome.duval@xxxxxxxxx>
Date: Mon Aug 6 17:13:32 2018 UTC
Ticket: https://dev.haiku-os.org/ticket/14322
----------------------------------------------------------------------------
5 files changed, 74 insertions(+), 1 deletion(-)
src/system/libroot/posix/spawn.cpp | 2 +-
src/tests/system/libroot/posix/Jamfile | 2 +
.../system/libroot/posix/posix_spawn_pipe_err.c | 10 ++++
.../system/libroot/posix/posix_spawn_pipe_test.c | 56 ++++++++++++++++++++
.../system/libroot/posix/posix_spawn_pipe_test.h | 5 ++
----------------------------------------------------------------------------
diff --git a/src/system/libroot/posix/spawn.cpp
b/src/system/libroot/posix/spawn.cpp
index d849906ea5..5bbd454f50 100644
--- a/src/system/libroot/posix/spawn.cpp
+++ b/src/system/libroot/posix/spawn.cpp
@@ -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;
}
}
diff --git a/src/tests/system/libroot/posix/Jamfile
b/src/tests/system/libroot/posix/Jamfile
index a1c690b5b6..4db77cf867 100644
--- a/src/tests/system/libroot/posix/Jamfile
+++ b/src/tests/system/libroot/posix/Jamfile
@@ -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 ;
diff --git a/src/tests/system/libroot/posix/posix_spawn_pipe_err.c
b/src/tests/system/libroot/posix/posix_spawn_pipe_err.c
new file mode 100644
index 0000000000..762bea3af1
--- /dev/null
+++ b/src/tests/system/libroot/posix/posix_spawn_pipe_err.c
@@ -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;
+}
diff --git a/src/tests/system/libroot/posix/posix_spawn_pipe_test.c
b/src/tests/system/libroot/posix/posix_spawn_pipe_test.c
new file mode 100644
index 0000000000..62da03c07f
--- /dev/null
+++ b/src/tests/system/libroot/posix/posix_spawn_pipe_test.c
@@ -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;
+}
diff --git a/src/tests/system/libroot/posix/posix_spawn_pipe_test.h
b/src/tests/system/libroot/posix/posix_spawn_pipe_test.h
new file mode 100644
index 0000000000..396fe34f00
--- /dev/null
+++ b/src/tests/system/libroot/posix/posix_spawn_pipe_test.h
@@ -0,0 +1,5 @@
+#ifndef t_h
+#define t_h
+#define testOut "test out\n"
+#define testErr "test err\n"
+#endif