From bbe388b5db35be6ffece8ebd42f11372af016763 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 7 Jun 2010 13:33:02 +0000 Subject: Add unfinished gpgtar. Collected changes and ports of bug fixes from stable. --- common/exechelp-w32.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'common/exechelp-w32.c') diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c index ed026e2ba..4616bec33 100644 --- a/common/exechelp-w32.c +++ b/common/exechelp-w32.c @@ -382,17 +382,30 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], int cr_flags; char *cmdline; int fd, fdout, rp[2]; + HANDLE nullhd[]; + int i; (void)preexec; /* Setup return values. */ *statusfile = NULL; *pid = (pid_t)(-1); - es_fflush (infile); - es_rewind (infile); - fd = _get_osfhandle (es_fileno (infile)); - fdout = _get_osfhandle (es_fileno (outfile)); - if (fd == -1 || fdout == -1) + + if (infile) + { + es_fflush (infile); + es_rewind (infile); + fd = _get_osfhandle (es_fileno (infile)); + } + else + fd = -1; + + if (outfile) + fdout = _get_osfhandle (es_fileno (outfile)); + else + fdout = -1; + + if ( (infile && fd == -1) || (outfile && fdout == -1)) log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); /* Prepare security attributes. */ @@ -414,14 +427,17 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], return err; } + nullhd[0] = fd == -1? w32_open_null (0) : INVALID_HANDLE_VALUE; + nullhd[1] = outfd == -1? w32_open_null (1) : INVALID_HANDLE_VALUE; + /* Start the process. Note that we can't run the PREEXEC function because this would change our own environment. */ memset (&si, 0, sizeof si); si.cb = sizeof (si); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = DEBUG_W32_SPAWN? SW_SHOW : SW_MINIMIZE; - si.hStdInput = fd_to_handle (fd); - si.hStdOutput = fd_to_handle (fdout); + si.hStdInput = fd == -1? nullhd[0] : fd_to_handle (fd); + si.hStdOutput = outfd == -1? nullhd[1] : fd_to_handle (fdout); si.hStdError = fd_to_handle (rp[1]); cr_flags = (CREATE_DEFAULT_ERROR_MODE @@ -450,6 +466,11 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], xfree (cmdline); cmdline = NULL; + /* Close the inherited handles to /dev/null. */ + for (i=0; i < DIM (nullhd); i++) + if (nullhd[i] != INVALID_HANDLE_VALUE) + CloseHandle (nullhd[i]); + /* Close the other end of the pipe. */ CloseHandle (fd_to_handle (rp[1])); -- cgit v1.2.3