[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r10322 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r10322 - gnunet/src/util |
Date: |
Tue, 16 Feb 2010 13:10:29 +0100 |
Author: nevans
Date: 2010-02-16 13:10:29 +0100 (Tue, 16 Feb 2010)
New Revision: 10322
Modified:
gnunet/src/util/Makefile.am
gnunet/src/util/disk.c
gnunet/src/util/os_priority.c
Log:
start process change to allow stdout to be sent from child process
Modified: gnunet/src/util/Makefile.am
===================================================================
--- gnunet/src/util/Makefile.am 2010-02-16 09:31:45 UTC (rev 10321)
+++ gnunet/src/util/Makefile.am 2010-02-16 12:10:29 UTC (rev 10322)
@@ -142,7 +142,8 @@
test_service \
test_strings \
test_time \
- perf_crypto_hash
+ perf_crypto_hash \
+ test_os_start_process
TESTS = $(check_SCRIPTS) $(check_PROGRAMS)
@@ -153,6 +154,11 @@
$(top_builddir)/src/util/libgnunetutil.la
+test_os_start_process_SOURCES = \
+ test_os_start_process.c
+test_os_start_process_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la
+
test_client_SOURCES = \
test_client.c
test_client_LDADD = \
Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c 2010-02-16 09:31:45 UTC (rev 10321)
+++ gnunet/src/util/disk.c 2010-02-16 12:10:29 UTC (rev 10322)
@@ -1678,6 +1678,62 @@
* @return GNUNET_OK on success, GNUNET_SYSERR otherwise
*/
int
+GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, enum
GNUNET_DISK_PipeEnd end)
+{
+ int ret = GNUNET_OK;
+ int save;
+
+ /* FIXME: What can we safely set HANDLE to once we've closed an end, NULL? */
+#ifdef MINGW
+ if (end == GNUNET_DISK_PIPE_END_READ)
+ {
+ if (!CloseHandle (p->fd[0]->h))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ ret = GNUNET_SYSERR;
+ }
+ }
+ else if (end == GNUNET_DISK_PIPE_END_WRITE)
+ {
+ if (!CloseHandle (p->fd[1]->h))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ ret = GNUNET_SYSERR;
+ }
+ }
+ save = errno;
+#else
+ save = 0;
+ if (end == GNUNET_DISK_PIPE_END_READ)
+ {
+ if (0 != close (p->fd[0]->fd))
+ {
+ ret = GNUNET_SYSERR;
+ save = errno;
+ }
+ p->fd[0]->fd = -1;
+ }
+ else if (end == GNUNET_DISK_PIPE_END_WRITE)
+ {
+ if (0 != close (p->fd[1]->fd))
+ {
+ ret = GNUNET_SYSERR;
+ save = errno;
+ }
+ p->fd[1]->fd = -1;
+ }
+#endif
+ errno = save;
+ return ret;
+}
+
+/**
+ * Closes an interprocess channel
+ *
+ * @param p pipe to close
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+int
GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
{
int ret = GNUNET_OK;
@@ -1697,15 +1753,22 @@
save = errno;
#else
save = 0;
- if (0 != close (p->fd[0]->fd))
+ if (p->fd[0]->fd != -1)
{
- ret = GNUNET_SYSERR;
- save = errno;
+ if (0 != close (p->fd[0]->fd))
+ {
+ ret = GNUNET_SYSERR;
+ save = errno;
+ }
}
- if (0 != close (p->fd[1]->fd))
+
+ if (p->fd[1]->fd != -1)
{
- ret = GNUNET_SYSERR;
- save = errno;
+ if (0 != close (p->fd[1]->fd))
+ {
+ ret = GNUNET_SYSERR;
+ save = errno;
+ }
}
#endif
GNUNET_free (p);
Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c 2010-02-16 09:31:45 UTC (rev 10321)
+++ gnunet/src/util/os_priority.c 2010-02-16 12:10:29 UTC (rev 10322)
@@ -27,6 +27,7 @@
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_os_lib.h"
+#include "disk.h"
/**
* Set process priority
@@ -115,7 +116,6 @@
return GNUNET_OK;
}
-
/**
* Start a process.
*
@@ -124,15 +124,32 @@
* @return process ID of the new process, -1 on error
*/
pid_t
-GNUNET_OS_start_process (const char *filename, ...)
+GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct
GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...)
{
+ /* FIXME: Make this work on windows!!! */
va_list ap;
#ifndef MINGW
pid_t ret;
char **argv;
int argc;
+ int fd_stdout_write;
+ int fd_stdin_read;
+ argc = 0;
+ va_start (ap, filename);
+ while (NULL != va_arg (ap, char *))
+ argc++;
+ va_end (ap);
+ argv = GNUNET_malloc (sizeof (char *) * (argc + 1));
+ argc = 0;
+ va_start (ap, filename);
+ while (NULL != (argv[argc] = va_arg (ap, char *)))
+ argc++;
+ va_end (ap);
+ if (pipe_stdout != NULL)
+ GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout,
GNUNET_DISK_PIPE_END_WRITE), &fd_stdout_write, sizeof (int));
+
#if HAVE_WORKING_VFORK
ret = vfork ();
#else
@@ -156,21 +173,19 @@
/* let's give the child process a chance to run execvp, 1s should
be plenty in practice */
sleep (1);
+ if (pipe_stdout != NULL)
+ GNUNET_DISK_pipe_close_end(pipe_stdout,
GNUNET_DISK_PIPE_END_WRITE);
#endif
}
+ GNUNET_free (argv);
return ret;
}
- argc = 0;
- va_start (ap, filename);
- while (NULL != va_arg (ap, char *))
- argc++;
- va_end (ap);
- argv = GNUNET_malloc (sizeof (char *) * (argc + 1));
- argc = 0;
- va_start (ap, filename);
- while (NULL != (argv[argc] = va_arg (ap, char *)))
- argc++;
- va_end (ap);
+ if (pipe_stdout != NULL)
+ {
+ dup2(fd_stdout_write, 1);
+ close (fd_stdout_write);
+ }
+
execvp (filename, argv);
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
_exit (1);
@@ -221,11 +236,11 @@
return proc.dwProcessId;
#endif
+
}
-
/**
* Start a process.
*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r10322 - gnunet/src/util,
gnunet <=