aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-27 12:34:57 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-27 12:34:57 +0000
commit4ea2ac4058b988958137a7eac0b0e695c38ab527 (patch)
treeeb6cad805f62559c35b9f4e67a1e6b8e27b9e5ce /src/util
parentfb6f753f6be4fc8fcb662a22bda6f1deb2c6e3bd (diff)
downloadgnunet-4ea2ac4058b988958137a7eac0b0e695c38ab527.tar.gz
gnunet-4ea2ac4058b988958137a7eac0b0e695c38ab527.zip
-do use non-blocking opening of the pipe FD, and try again if it fails
Diffstat (limited to 'src/util')
-rw-r--r--src/util/os_priority.c82
1 files changed, 55 insertions, 27 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 18dc4edaa..15cbe3c98 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -176,12 +176,10 @@ npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
176 * 176 *
177 * @param fn name of an existing named pipe 177 * @param fn name of an existing named pipe
178 * @param flags open flags 178 * @param flags open flags
179 * @param perm access permissions
180 * @return pipe handle on success, NULL on error 179 * @return pipe handle on success, NULL on error
181 */ 180 */
182static struct GNUNET_DISK_FileHandle * 181static struct GNUNET_DISK_FileHandle *
183npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, 182npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags)
184 enum GNUNET_DISK_AccessPermissions perm)
185{ 183{
186 struct GNUNET_DISK_FileHandle *ret; 184 struct GNUNET_DISK_FileHandle *ret;
187 HANDLE h; 185 HANDLE h;
@@ -271,16 +269,46 @@ npipe_setup (char **fn)
271 * 269 *
272 * @param fn name of the file 270 * @param fn name of the file
273 * @param flags flags to use 271 * @param flags flags to use
274 * @param perm permissions to use
275 * @return NULL on error 272 * @return NULL on error
276 */ 273 */
277static struct GNUNET_DISK_FileHandle * 274static struct GNUNET_DISK_FileHandle *
278npipe_open (const char *fn, 275npipe_open (const char *fn,
279 enum GNUNET_DISK_OpenFlags flags, 276 enum GNUNET_DISK_OpenFlags flags)
280 enum GNUNET_DISK_AccessPermissions perm)
281{ 277{
282 flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); 278 struct GNUNET_DISK_FileHandle *ret;
283 return GNUNET_DISK_file_open (fn, flags, perm); 279 int fd;
280 struct timespec req;
281 int i;
282
283 /* 200 * 5ms = 1s at most */
284 for (i=0;i<200;i++)
285 {
286 fd = open (fn, O_NONBLOCK | ((flags == GNUNET_DISK_OPEN_READ) ? O_RDONLY : O_WRONLY));
287 if ( (-1 != fd) || (9 == i) || (flags == GNUNET_DISK_OPEN_READ))
288 break;
289 /* as this is for killing a child process via pipe and it is conceivable that
290 the child process simply didn't finish starting yet, we do some sleeping
291 (which is obviously usually not allowed). We can't select on the FD as
292 'open' fails, and we probably shouldn't just "ignore" the error, so wait
293 and retry a few times is likely the best method; our process API doesn't
294 support continuations, so we need to sleep directly... */
295 req.tv_sec = 0;
296 req.tv_nsec = 5000000; /* 5ms */
297 (void) nanosleep (&req, NULL);
298 }
299 if (-1 == fd)
300 {
301 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
302 (flags == GNUNET_DISK_OPEN_READ)
303 ? _("Failed to open named pipe `%s' for reading: %s\n")
304 : _("Failed to open named pipe `%s' for writing: %s\n"),
305 fn,
306 STRERROR (errno));
307 return NULL;
308 }
309 ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle));
310 ret->fd = fd;
311 return ret;
284} 312}
285#endif 313#endif
286 314
@@ -349,9 +377,7 @@ GNUNET_OS_install_parent_control_handler (void *cls,
349 return; 377 return;
350 } 378 }
351 control_pipe = 379 control_pipe =
352 npipe_open (env_buf, GNUNET_DISK_OPEN_READ, 380 npipe_open (env_buf, GNUNET_DISK_OPEN_READ);
353 GNUNET_DISK_PERM_USER_READ |
354 GNUNET_DISK_PERM_USER_WRITE);
355 if (NULL == control_pipe) 381 if (NULL == control_pipe)
356 { 382 {
357 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf); 383 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
@@ -403,9 +429,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
403 if ( (NULL == proc->control_pipe) && 429 if ( (NULL == proc->control_pipe) &&
404 (NULL != proc->childpipename) ) 430 (NULL != proc->childpipename) )
405 proc->control_pipe = npipe_open (proc->childpipename, 431 proc->control_pipe = npipe_open (proc->childpipename,
406 GNUNET_DISK_OPEN_WRITE, 432 GNUNET_DISK_OPEN_WRITE);
407 GNUNET_DISK_PERM_USER_READ |
408 GNUNET_DISK_PERM_USER_WRITE);
409#endif 433#endif
410 if (NULL == proc->control_pipe) 434 if (NULL == proc->control_pipe)
411 { 435 {
@@ -750,22 +774,26 @@ GNUNET_OS_start_process_vap (int pipe_control,
750 return NULL; 774 return NULL;
751 if (pipe_stdout != NULL) 775 if (pipe_stdout != NULL)
752 { 776 {
753 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 777 GNUNET_assert (GNUNET_OK ==
754 (pipe_stdout, 778 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
755 GNUNET_DISK_PIPE_END_WRITE), 779 (pipe_stdout,
756 &fd_stdout_write, sizeof (int)); 780 GNUNET_DISK_PIPE_END_WRITE),
757 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 781 &fd_stdout_write, sizeof (int)));
758 (pipe_stdout, GNUNET_DISK_PIPE_END_READ), 782 GNUNET_assert (GNUNET_OK ==
759 &fd_stdout_read, sizeof (int)); 783 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
784 (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
785 &fd_stdout_read, sizeof (int)));
760 } 786 }
761 if (pipe_stdin != NULL) 787 if (pipe_stdin != NULL)
762 { 788 {
763 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 789 GNUNET_assert (GNUNET_OK ==
764 (pipe_stdin, GNUNET_DISK_PIPE_END_READ), 790 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
765 &fd_stdin_read, sizeof (int)); 791 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
766 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 792 &fd_stdin_read, sizeof (int)));
767 (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE), 793 GNUNET_assert (GNUNET_OK ==
768 &fd_stdin_write, sizeof (int)); 794 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
795 (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
796 &fd_stdin_write, sizeof (int)));
769 } 797 }
770 798
771 ret = fork (); 799 ret = fork ();