diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-09-15 08:31:21 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-09-15 08:31:21 +0000 |
commit | 5c434a60afadd065ab25900dc11756067d58fc1d (patch) | |
tree | 3179852ae53180fc42d983b0292ed9fab2a53131 /src | |
parent | d1e367b5bcff3b7c9db57fe7ce8f25ab45a6894b (diff) | |
download | gnunet-5c434a60afadd065ab25900dc11756067d58fc1d.tar.gz gnunet-5c434a60afadd065ab25900dc11756067d58fc1d.zip |
0001602: A patch to fix process spawning with redirected std streams
Diffstat (limited to 'src')
-rw-r--r-- | src/util/Makefile.am | 2 | ||||
-rw-r--r-- | src/util/disk.c | 28 | ||||
-rw-r--r-- | src/util/scheduler.c | 2 | ||||
-rw-r--r-- | src/util/test_os_start_process.c | 9 | ||||
-rw-r--r-- | src/util/test_scheduler.c | 2 |
5 files changed, 37 insertions, 6 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 6d88537e5..38d60167b 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -14,6 +14,8 @@ libgnunetutilwin_la_LIBADD = \ | |||
14 | -lshell32 -liconv -lstdc++ \ | 14 | -lshell32 -liconv -lstdc++ \ |
15 | -lcomdlg32 -lgdi32 | 15 | -lcomdlg32 -lgdi32 |
16 | WINLIB = libgnunetutilwin.la | 16 | WINLIB = libgnunetutilwin.la |
17 | noinst_PROGRAMS = test_os_start_process_cat | ||
18 | test_os_start_process_cat_SOURCES = test_os_start_process_cat.c | ||
17 | endif | 19 | endif |
18 | 20 | ||
19 | if USE_COVERAGE | 21 | if USE_COVERAGE |
diff --git a/src/util/disk.c b/src/util/disk.c index 88f11be51..fbcf6b964 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -1649,7 +1649,7 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) | |||
1649 | * @return handle to the new pipe, NULL on error | 1649 | * @return handle to the new pipe, NULL on error |
1650 | */ | 1650 | */ |
1651 | struct GNUNET_DISK_PipeHandle * | 1651 | struct GNUNET_DISK_PipeHandle * |
1652 | GNUNET_DISK_pipe (int blocking) | 1652 | GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) |
1653 | { | 1653 | { |
1654 | struct GNUNET_DISK_PipeHandle *p; | 1654 | struct GNUNET_DISK_PipeHandle *p; |
1655 | struct GNUNET_DISK_FileHandle *fds; | 1655 | struct GNUNET_DISK_FileHandle *fds; |
@@ -1699,6 +1699,7 @@ GNUNET_DISK_pipe (int blocking) | |||
1699 | } | 1699 | } |
1700 | #else | 1700 | #else |
1701 | BOOL ret; | 1701 | BOOL ret; |
1702 | HANDLE tmp_handle; | ||
1702 | 1703 | ||
1703 | ret = CreatePipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0); | 1704 | ret = CreatePipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0); |
1704 | if (!ret) | 1705 | if (!ret) |
@@ -1707,6 +1708,31 @@ GNUNET_DISK_pipe (int blocking) | |||
1707 | SetErrnoFromWinError (GetLastError ()); | 1708 | SetErrnoFromWinError (GetLastError ()); |
1708 | return NULL; | 1709 | return NULL; |
1709 | } | 1710 | } |
1711 | if (!DuplicateHandle (GetCurrentProcess (), p->fd[0]->h, | ||
1712 | GetCurrentProcess (), &tmp_handle, 0, inherit_read == GNUNET_YES ? TRUE : FALSE, | ||
1713 | DUPLICATE_SAME_ACCESS)) | ||
1714 | { | ||
1715 | SetErrnoFromWinError (GetLastError ()); | ||
1716 | CloseHandle (p->fd[0]->h); | ||
1717 | CloseHandle (p->fd[1]->h); | ||
1718 | GNUNET_free (p); | ||
1719 | return NULL; | ||
1720 | } | ||
1721 | CloseHandle (p->fd[0]->h); | ||
1722 | p->fd[0]->h = tmp_handle; | ||
1723 | |||
1724 | if (!DuplicateHandle (GetCurrentProcess (), p->fd[1]->h, | ||
1725 | GetCurrentProcess (), &tmp_handle, 0, inherit_write == GNUNET_YES ? TRUE : FALSE, | ||
1726 | DUPLICATE_SAME_ACCESS)) | ||
1727 | { | ||
1728 | SetErrnoFromWinError (GetLastError ()); | ||
1729 | CloseHandle (p->fd[0]->h); | ||
1730 | CloseHandle (p->fd[1]->h); | ||
1731 | GNUNET_free (p); | ||
1732 | return NULL; | ||
1733 | } | ||
1734 | CloseHandle (p->fd[1]->h); | ||
1735 | p->fd[1]->h = tmp_handle; | ||
1710 | if (!blocking) | 1736 | if (!blocking) |
1711 | { | 1737 | { |
1712 | DWORD mode; | 1738 | DWORD mode; |
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 628e80afd..3acb27aa0 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -749,7 +749,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
749 | rs = GNUNET_NETWORK_fdset_create (); | 749 | rs = GNUNET_NETWORK_fdset_create (); |
750 | ws = GNUNET_NETWORK_fdset_create (); | 750 | ws = GNUNET_NETWORK_fdset_create (); |
751 | GNUNET_assert (shutdown_pipe_handle == NULL); | 751 | GNUNET_assert (shutdown_pipe_handle == NULL); |
752 | shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO); | 752 | shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); |
753 | GNUNET_assert (shutdown_pipe_handle != NULL); | 753 | GNUNET_assert (shutdown_pipe_handle != NULL); |
754 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_READ); | 754 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_READ); |
755 | GNUNET_assert (pr != NULL); | 755 | GNUNET_assert (pr != NULL); |
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 550ea0b39..97c5e99c0 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c | |||
@@ -105,11 +105,14 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
105 | char *fn; | 105 | char *fn; |
106 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; | 106 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; |
107 | const struct GNUNET_DISK_FileHandle *wh; | 107 | const struct GNUNET_DISK_FileHandle *wh; |
108 | 108 | #ifndef WINDOWS | |
109 | GNUNET_asprintf(&fn, "cat"); | 109 | GNUNET_asprintf(&fn, "cat"); |
110 | #else | ||
111 | GNUNET_asprintf(&fn, "./.libs/test_os_start_process_cat.exe"); | ||
112 | #endif | ||
110 | 113 | ||
111 | hello_pipe_stdin = GNUNET_DISK_pipe(GNUNET_YES); | 114 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); |
112 | hello_pipe_stdout = GNUNET_DISK_pipe(GNUNET_YES); | 115 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); |
113 | 116 | ||
114 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | 117 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) |
115 | { | 118 | { |
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index 52e4b3684..0ac186588 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c | |||
@@ -114,7 +114,7 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
114 | int *ok = cls; | 114 | int *ok = cls; |
115 | GNUNET_assert (5 == *ok); | 115 | GNUNET_assert (5 == *ok); |
116 | (*ok) = 6; | 116 | (*ok) = 6; |
117 | p = GNUNET_DISK_pipe (GNUNET_NO); | 117 | p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); |
118 | GNUNET_assert (NULL != p); | 118 | GNUNET_assert (NULL != p); |
119 | fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); | 119 | fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); |
120 | fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); | 120 | fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); |