test_service \
test_strings \
test_time \
- perf_crypto_hash
+ perf_crypto_hash \
+ test_os_start_process
TESTS = $(check_SCRIPTS) $(check_PROGRAMS)
$(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 = \
}
+/**
+ * Closes an interprocess channel
+ *
+ * @param p pipe to close
+ * @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
*
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);
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_os_lib.h"
+#include "disk.h"
/**
* Set process priority
return GNUNET_OK;
}
-
/**
* Start a process.
*
* @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 ();
/* 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);
return proc.dwProcessId;
#endif
-}
+}