Make use of internal iospawn flags more flexible.

* src/priv-io.h (IOSPAWN_FLAG_DETACHED): New. Renumber the others.
* src/w32-io.c (_gpgme_io_spawn): Use DETACHED_PROCESS process only if
IOSPAWN_FLAG_DETACHED is given.
* src/w32-qt-io.cpp (_gpgme_io_spawn): Ditto.
* src/w32-glib-io.c (_gpgme_io_spawn): Ditto.
* src/assuan-support.c (my_spawn): Pass IOSPAWN_FLAG_DETACHED flags.
* src/dirinfo.c (read_gpgconf_dirs): Ditto.
* src/engine-gpg.c (start): Ditto.
* src/engine-gpgconf.c (gpgconf_read, gpgconf_write): Ditto.
* src/version.c (_gpgme_get_program_version): Ditto.
This commit is contained in:
Werner Koch 2014-04-10 11:39:14 +02:00
parent 617d3be629
commit 443f6b76a9
10 changed files with 43 additions and 35 deletions

View File

@ -168,7 +168,8 @@ my_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
fd_items[i].fd = -1;
fd_items[i].dup_to = -1;
err = _gpgme_io_spawn (name, (char*const*)argv, IOSPAWN_FLAG_NOCLOSE,
err = _gpgme_io_spawn (name, (char*const*)argv,
(IOSPAWN_FLAG_NOCLOSE | IOSPAWN_FLAG_DETACHED),
fd_items, atfork, atforkvalue, r_pid);
if (! err)
{

View File

@ -156,7 +156,8 @@ read_gpgconf_dirs (const char *pgmname, int components)
cfd[0].fd = rp[1];
status = _gpgme_io_spawn (pgmname, argv, 0, cfd, NULL, NULL, NULL);
status = _gpgme_io_spawn (pgmname, argv, IOSPAWN_FLAG_DETACHED,
cfd, NULL, NULL, NULL);
if (status < 0)
{
_gpgme_io_close (rp[0]);

View File

@ -1359,7 +1359,7 @@ start (engine_gpg_t gpg)
fd_list[n].dup_to = -1;
status = _gpgme_io_spawn (pgmname, gpg->argv,
IOSPAWN_FLAG_ALLOW_SET_FG,
(IOSPAWN_FLAG_DETACHED |IOSPAWN_FLAG_ALLOW_SET_FG),
fd_list, NULL, NULL, &pid);
{
int saved_err = gpg_error_from_syserror ();

View File

@ -228,7 +228,8 @@ gpgconf_read (void *engine, char *arg1, char *arg2,
cfd[0].fd = rp[1];
status = _gpgme_io_spawn (gpgconf->file_name, argv, 0, cfd, NULL, NULL, NULL);
status = _gpgme_io_spawn (gpgconf->file_name, argv,
IOSPAWN_FLAG_DETACHED, cfd, NULL, NULL, NULL);
if (status < 0)
{
_gpgme_io_close (rp[0]);
@ -697,7 +698,8 @@ gpgconf_write (void *engine, char *arg1, char *arg2, gpgme_data_t conf)
cfd[0].fd = rp[0];
status = _gpgme_io_spawn (gpgconf->file_name, argv, 0, cfd, NULL, NULL, NULL);
status = _gpgme_io_spawn (gpgconf->file_name, argv,
IOSPAWN_FLAG_DETACHED, cfd, NULL, NULL, NULL);
if (status < 0)
{
_gpgme_io_close (rp[0]);

View File

@ -372,8 +372,6 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
int status;
int signo;
(void)flags;
TRACE_BEG1 (DEBUG_SYSIO, "_gpgme_io_spawn", path,
"path=%s", path);
i = 0;

View File

@ -75,11 +75,13 @@ int _gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
void *value);
int _gpgme_io_set_nonblocking (int fd);
/* Under Windows do not allocate a console. */
#define IOSPAWN_FLAG_DETACHED 1
/* A flag to tell the spawn function to allow the child process to set
the foreground window. */
#define IOSPAWN_FLAG_ALLOW_SET_FG 1
#define IOSPAWN_FLAG_ALLOW_SET_FG 2
/* Don't close any child FDs. */
#define IOSPAWN_FLAG_NOCLOSE 2
#define IOSPAWN_FLAG_NOCLOSE 4
/* Spawn the executable PATH with ARGV as arguments. After forking
close all fds except for those in FD_LIST in the child, then

View File

@ -321,7 +321,8 @@ _gpgme_get_program_version (const char *const file_name)
cfd[0].fd = rp[1];
status = _gpgme_io_spawn (file_name, argv, 0, cfd, NULL, NULL, NULL);
status = _gpgme_io_spawn (file_name, argv,
IOSPAWN_FLAG_DETACHED, cfd, NULL, NULL, NULL);
if (status < 0)
{
_gpgme_io_close (rp[0]);

View File

@ -662,7 +662,8 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
si.hStdError = INVALID_HANDLE_VALUE;
cr_flags |= CREATE_SUSPENDED;
cr_flags |= DETACHED_PROCESS;
if ((flags & IOSPAWN_FLAG_DETACHED))
cr_flags |= DETACHED_PROCESS;
if (!CreateProcessA (_gpgme_get_w32spawn_path (),
arg_string,
&sec_attr, /* process security attributes */

View File

@ -1598,7 +1598,8 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
si.hStdError = INVALID_HANDLE_VALUE;
cr_flags |= CREATE_SUSPENDED;
cr_flags |= DETACHED_PROCESS;
if ((flags & IOSPAWN_FLAG_DETACHED))
cr_flags |= DETACHED_PROCESS;
cr_flags |= GetPriorityClass (GetCurrentProcess ());
if (!CreateProcessA (_gpgme_get_w32spawn_path (),
arg_string,

View File

@ -3,17 +3,17 @@
Copyright (C) 2001, 2002, 2004, 2005, 2007 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
@ -107,7 +107,7 @@ find_channel (int fd, int create)
DeviceEntry* entry = new DeviceEntry;
entry->iodev = new KDPipeIODevice
(fd, QIODevice::ReadWrite|QIODevice::Unbuffered);
iodevice_table[fd] = entry;
iodevice_table[fd] = entry;
}
return iodevice_table[fd] ? iodevice_table[fd]->iodev : 0;
}
@ -156,7 +156,7 @@ _gpgme_io_read (int fd, void *buffer, size_t count)
errno = EAGAIN;
return TRACE_SYSRES( -1 );
}
nread = chan->read ((char *) buffer, count);
if (nread < 0)
{
@ -289,8 +289,8 @@ _gpgme_io_close (int fd)
notify_table[fd].value = NULL;
}
/* Then do the close. */
/* Then do the close. */
DeviceEntry* const entry = iodevice_table[fd];
if ( entry ) {
if ( entry->unref() == 0 ) {
@ -303,7 +303,7 @@ _gpgme_io_close (int fd)
_close( fd );
}
return 0;
}
@ -334,7 +334,7 @@ _gpgme_io_set_nonblocking (int fd)
{
DeviceEntry* const entry = iodevice_table[fd];
assert( entry );
entry->blocking = false;
entry->blocking = false;
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_set_nonblocking", fd);
return TRACE_SYSRES (0);
}
@ -347,7 +347,7 @@ build_commandline (char **argv)
int n = 0;
char *buf;
char *p;
/* We have to quote some things because under Windows the program
parses the commandline and does some unquoting. We enclose the
whole argument in double-quotes, and escape literal double-quotes
@ -428,7 +428,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
TRACE_LOG2 ("argv[%2i] = %s", i, argv[i]);
i++;
}
/* We do not inherit any handles by default, and just insert those
handles we want the child to have afterwards. But some handle
values occur on the command line, and we need to move
@ -450,7 +450,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
memset (&sec_attr, 0, sizeof sec_attr);
sec_attr.nLength = sizeof sec_attr;
sec_attr.bInheritHandle = FALSE;
arg_string = build_commandline (args);
free (args);
if (!arg_string)
@ -459,7 +459,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
DeleteFile (tmp_name);
return TRACE_SYSRES (-1);
}
memset (&si, 0, sizeof si);
si.cb = sizeof (si);
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
@ -469,7 +469,8 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
si.hStdError = INVALID_HANDLE_VALUE;
cr_flags |= CREATE_SUSPENDED;
cr_flags |= DETACHED_PROCESS;
if ((flags & IOSPAWN_FLAG_DETACHED))
cr_flags |= DETACHED_PROCESS;
if (!CreateProcessA (_gpgme_get_w32spawn_path (),
arg_string,
&sec_attr, /* process security attributes */
@ -523,7 +524,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
/* Return the child name of this handle. */
fd_list[i].peer_name = (int) hd;
}
/* Write the handle translation information to the temporary
file. */
{
@ -545,7 +546,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
{
/* Strip the newline. */
len = strlen (line) - 1;
/* Format is: Local name, stdin/stdout/stderr, peer name, argv idx. */
snprintf (&line[len], BUFFER_MAX - len, "0x%x %d 0x%x %d \n",
fd_list[i].fd, fd_list[i].dup_to,
@ -567,18 +568,18 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
close (tmp_fd);
/* The temporary file is deleted by the gpgme-w32spawn process
(hopefully). */
TRACE_LOG4 ("CreateProcess ready: hProcess=%p, hThread=%p, "
"dwProcessID=%d, dwThreadId=%d",
pi.hProcess, pi.hThread,
pi.hProcess, pi.hThread,
(int) pi.dwProcessId, (int) pi.dwThreadId);
if (r_pid)
*r_pid = (pid_t)pi.dwProcessId;
if (ResumeThread (pi.hThread) < 0)
TRACE_LOG1 ("ResumeThread failed: ec=%d", (int) GetLastError ());
if (!CloseHandle (pi.hThread))
TRACE_LOG1 ("CloseHandle of thread failed: ec=%d",
(int) GetLastError ());
@ -635,7 +636,7 @@ _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
else
fds[i].signaled = chan->waitForReadyRead( 1000 ) ? 1 : 0;
TRACE_ADD1 (dbg_help, "w0x%x ", fds[i].fd);
if ( fds[i].signaled )
if ( fds[i].signaled )
count++;
}
else if (fds[i].for_write)
@ -644,11 +645,11 @@ _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
assert (chan);
fds[i].signaled = nonblock ? ( chan->writeWouldBlock() ? 0 : 1 ) : 1;
TRACE_ADD1 (dbg_help, "w0x%x ", fds[i].fd);
if ( fds[i].signaled )
if ( fds[i].signaled )
count++;
}
}
TRACE_END (dbg_help, "]");
TRACE_END (dbg_help, "]");
return TRACE_SYSRES (count);
}