[haiku-commits] haiku: hrev52158 - in src: tests/system/libroot/posix system/libroot/posix

  • From: Jérôme Duval <jerome.duval@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 2 Aug 2018 05:21:43 -0400 (EDT)

hrev52158 adds 1 changeset to branch 'master'
old head: edb6d3b17b6617314ad58fc82e61752378b08574
new head: 20694a04585f349f3815d13c1fbbccee66c782d6
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=20694a04585f+%5Eedb6d3b17b66

----------------------------------------------------------------------------

20694a04585f: posix_spawn(): dup2() returns a fd on success, -1 on error.
  
  * duplicate the just opened file descriptor, instead of the target file 
descriptor.
  * fixes #14308.

                                   [ Jérôme Duval <jerome.duval@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev52158
Commit:      20694a04585f349f3815d13c1fbbccee66c782d6
URL:         https://git.haiku-os.org/haiku/commit/?id=20694a04585f
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Thu Aug  2 09:12:13 2018 UTC

Ticket:      https://dev.haiku-os.org/ticket/14308

----------------------------------------------------------------------------

4 files changed, 34 insertions(+), 1 deletion(-)
src/system/libroot/posix/spawn.cpp               |  2 +-
src/tests/system/libroot/posix/Jamfile           |  2 ++
.../system/libroot/posix/posix_spawn_redir_err.c |  7 ++++++
.../libroot/posix/posix_spawn_redir_test.c       | 24 ++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/src/system/libroot/posix/spawn.cpp 
b/src/system/libroot/posix/spawn.cpp
index 7206dbc9a4..d849906ea5 100644
--- a/src/system/libroot/posix/spawn.cpp
+++ b/src/system/libroot/posix/spawn.cpp
@@ -402,7 +402,7 @@ process_file_actions(const posix_spawn_file_actions_t 
*_actions, int *errfd)
                        if (fd == -1)
                                return errno;
                        if (fd != action->fd) {
-                               if (dup2(action->fd, fd) != 0)
+                               if (dup2(fd, action->fd) == -1)
                                        return errno;
                                if (close(fd) != 0)
                                        return errno;
diff --git a/src/tests/system/libroot/posix/Jamfile 
b/src/tests/system/libroot/posix/Jamfile
index ee5e4f60f9..a1c690b5b6 100644
--- a/src/tests/system/libroot/posix/Jamfile
+++ b/src/tests/system/libroot/posix/Jamfile
@@ -40,6 +40,8 @@ SimpleTest init_rld_after_fork_test : 
init_rld_after_fork_test.cpp ;
 SimpleTest user_thread_fork_test : user_thread_fork_test.cpp ;
 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 ;
 
 # XSI tests
 SimpleTest xsi_msg_queue_test1 : xsi_msg_queue_test1.cpp ;
diff --git a/src/tests/system/libroot/posix/posix_spawn_redir_err.c 
b/src/tests/system/libroot/posix/posix_spawn_redir_err.c
new file mode 100644
index 0000000000..b9e1d7833a
--- /dev/null
+++ b/src/tests/system/libroot/posix/posix_spawn_redir_err.c
@@ -0,0 +1,7 @@
+#include <unistd.h>
+
+int main() {
+  const char msg[] = "something";
+  write(2, msg, sizeof(msg));
+  return 0;
+}
diff --git a/src/tests/system/libroot/posix/posix_spawn_redir_test.c 
b/src/tests/system/libroot/posix/posix_spawn_redir_test.c
new file mode 100644
index 0000000000..45bfd8b563
--- /dev/null
+++ b/src/tests/system/libroot/posix/posix_spawn_redir_test.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <spawn.h>
+#include <errno.h>
+
+#define panic(str) if (ret != 0) { errno = ret; perror(str); return 1; }
+
+int main() {
+        int ret;
+        pid_t child;
+        char* const av[] = { "posix_spawn_redir_err", NULL };
+        posix_spawn_file_actions_t child_fd_acts;
+        ret = posix_spawn_file_actions_init(&child_fd_acts);
+        panic("init");
+        ret = posix_spawn_file_actions_addopen(&child_fd_acts, 1, "errlog",
+                O_WRONLY | O_CREAT | O_TRUNC, 0644);
+        panic("addopen");
+        ret = posix_spawn_file_actions_adddup2(&child_fd_acts, 1, 2);
+        panic("adddup2");
+        ret = posix_spawn(&child, "./posix_spawn_redir_err", &child_fd_acts, 
NULL, av, NULL);
+        panic("spawn");
+        return 0;
+}
+


Other related posts:

  • » [haiku-commits] haiku: hrev52158 - in src: tests/system/libroot/posix system/libroot/posix - Jérôme Duval