aboutsummaryrefslogtreecommitdiff
path: root/src/util/os_priority.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-02-16 14:02:23 +0000
committerNathan S. Evans <evans@in.tum.de>2010-02-16 14:02:23 +0000
commit17c88acd603c4f8ee1805c0db851cc9ce112f75f (patch)
tree5dc387f78a67ccffed8d546124ece2702fd1265e /src/util/os_priority.c
parentaee82888eabdaee16aa78529f78361afcf8b2b01 (diff)
downloadgnunet-17c88acd603c4f8ee1805c0db851cc9ce112f75f.tar.gz
gnunet-17c88acd603c4f8ee1805c0db851cc9ce112f75f.zip
actually add test case, and added proper stdin support to os_start_process function...
Diffstat (limited to 'src/util/os_priority.c')
-rw-r--r--src/util/os_priority.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 26c76483c..4c9a449b1 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -127,7 +127,6 @@ pid_t
127GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...) 127GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...)
128{ 128{
129 /* FIXME: Make this work on windows!!! */ 129 /* FIXME: Make this work on windows!!! */
130 /* FIXME: Make this work with stdin as well as stdout! */
131 va_list ap; 130 va_list ap;
132 131
133#ifndef MINGW 132#ifndef MINGW
@@ -135,7 +134,9 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNE
135 char **argv; 134 char **argv;
136 int argc; 135 int argc;
137 int fd_stdout_write; 136 int fd_stdout_write;
137 int fd_stdout_read;
138 int fd_stdin_read; 138 int fd_stdin_read;
139 int fd_stdin_write;
139 140
140 argc = 0; 141 argc = 0;
141 va_start (ap, filename); 142 va_start (ap, filename);
@@ -149,9 +150,15 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNE
149 argc++; 150 argc++;
150 va_end (ap); 151 va_end (ap);
151 if (pipe_stdout != NULL) 152 if (pipe_stdout != NULL)
152 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE), &fd_stdout_write, sizeof (int)); 153 {
154 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE), &fd_stdout_write, sizeof (int));
155 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_READ), &fd_stdout_read, sizeof (int));
156 }
153 if (pipe_stdin != NULL) 157 if (pipe_stdin != NULL)
154 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_READ), &fd_stdin_read, sizeof (int)); 158 {
159 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdin, GNUNET_DISK_PIPE_END_READ), &fd_stdin_read, sizeof (int));
160 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdin, GNUNET_DISK_PIPE_END_WRITE), &fd_stdin_write, sizeof (int));
161 }
155 162
156#if HAVE_WORKING_VFORK 163#if HAVE_WORKING_VFORK
157 ret = vfork (); 164 ret = vfork ();
@@ -166,6 +173,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNE
166 } 173 }
167 else 174 else
168 { 175 {
176
169#if HAVE_WORKING_VFORK 177#if HAVE_WORKING_VFORK
170 /* let's hope vfork actually works; for some extreme cases (including 178 /* let's hope vfork actually works; for some extreme cases (including
171 a testcase) we need 'execvp' to have run before we return, since 179 a testcase) we need 'execvp' to have run before we return, since
@@ -175,11 +183,11 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNE
175#else 183#else
176 /* let's give the child process a chance to run execvp, 1s should 184 /* let's give the child process a chance to run execvp, 1s should
177 be plenty in practice */ 185 be plenty in practice */
178 sleep (1);
179 if (pipe_stdout != NULL) 186 if (pipe_stdout != NULL)
180 GNUNET_DISK_pipe_close_end(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); 187 GNUNET_DISK_pipe_close_end(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
181 if (pipe_stdin != NULL) 188 if (pipe_stdin != NULL)
182 GNUNET_DISK_pipe_close_end(pipe_stdin, GNUNET_DISK_PIPE_END_READ); 189 GNUNET_DISK_pipe_close_end(pipe_stdin, GNUNET_DISK_PIPE_END_READ);
190 sleep (1);
183#endif 191#endif
184 } 192 }
185 GNUNET_free (argv); 193 GNUNET_free (argv);
@@ -190,12 +198,15 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNE
190 { 198 {
191 dup2(fd_stdout_write, 1); 199 dup2(fd_stdout_write, 1);
192 close (fd_stdout_write); 200 close (fd_stdout_write);
201 close (fd_stdout_read);
193 } 202 }
194 203
195 if (pipe_stdout != NULL) 204 if (pipe_stdin != NULL)
196 { 205 {
206
197 dup2(fd_stdin_read, 0); 207 dup2(fd_stdin_read, 0);
198 close (fd_stdin_read); 208 close (fd_stdin_read);
209 close (fd_stdin_write);
199 } 210 }
200 211
201 execvp (filename, argv); 212 execvp (filename, argv);