2004-12-06 19:28:56 +01:00
|
|
|
/* exechelp.h - Definitions for the fork and exec helpers
|
2009-03-19 08:09:31 +01:00
|
|
|
* Copyright (C) 2004, 2009 Free Software Foundation, Inc.
|
2004-12-06 19:28:56 +01:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 21:49:40 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-12-06 19:28:56 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-04 21:49:40 +02:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2004-12-06 19:28:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GNUPG_COMMON_EXECHELP_H
|
|
|
|
#define GNUPG_COMMON_EXECHELP_H
|
|
|
|
|
2009-03-19 08:09:31 +01:00
|
|
|
/* Return the maximum number of currently allowed file descriptors.
|
|
|
|
Only useful on POSIX systems. */
|
|
|
|
int get_max_fds (void);
|
|
|
|
|
|
|
|
|
|
|
|
/* Close all file descriptors starting with descriptor FIRST. If
|
|
|
|
EXCEPT is not NULL, it is expected to be a list of file descriptors
|
|
|
|
which are not to close. This list shall be sorted in ascending
|
|
|
|
order with its end marked by -1. */
|
|
|
|
void close_all_fds (int first, int *except);
|
|
|
|
|
|
|
|
|
|
|
|
/* Returns an array with all currently open file descriptors. The end
|
|
|
|
of the array is marked by -1. The caller needs to release this
|
|
|
|
array using the *standard free* and not with xfree. This allow the
|
|
|
|
use of this fucntion right at startup even before libgcrypt has
|
|
|
|
been initialized. Returns NULL on error and sets ERRNO accordingly. */
|
|
|
|
int *get_all_open_fds (void);
|
|
|
|
|
2004-12-06 19:28:56 +01:00
|
|
|
|
2007-08-29 18:59:20 +02:00
|
|
|
/* Portable function to create a pipe. Under Windows the write end is
|
|
|
|
inheritable. */
|
|
|
|
gpg_error_t gnupg_create_inbound_pipe (int filedes[2]);
|
|
|
|
|
2004-12-06 19:28:56 +01:00
|
|
|
|
|
|
|
/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to
|
|
|
|
stdin, write the output to OUTFILE, return a new stream in
|
|
|
|
STATUSFILE for stderr and the pid of the process in PID. The
|
|
|
|
arguments for the process are expected in the NULL terminated array
|
2008-01-27 15:43:52 +01:00
|
|
|
ARGV. The program name itself should not be included there. If
|
2004-12-06 19:28:56 +01:00
|
|
|
PREEXEC is not NULL, that function will be called right before the
|
2008-01-27 15:43:52 +01:00
|
|
|
exec. FLAGS is currently only useful for W32, see the source for
|
|
|
|
details. Calling gnupg_wait_process is required. Returns 0 on
|
2007-08-27 20:10:27 +02:00
|
|
|
success or an error code. */
|
2004-12-06 19:28:56 +01:00
|
|
|
gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|
|
|
FILE *infile, FILE *outfile,
|
2008-01-27 15:43:52 +01:00
|
|
|
void (*preexec)(void), unsigned int flags,
|
2004-12-06 19:28:56 +01:00
|
|
|
FILE **statusfile, pid_t *pid);
|
|
|
|
|
2007-08-27 20:10:27 +02:00
|
|
|
|
|
|
|
/* Simplified version of gnupg_spawn_process. This function forks and
|
|
|
|
then execs PGMNAME, while connecting INFD to stdin, OUTFD to stdout
|
|
|
|
and ERRFD to stderr (any of them may be -1 to connect them to
|
|
|
|
/dev/null). The arguments for the process are expected in the NULL
|
|
|
|
terminated array ARGV. The program name itself should not be
|
|
|
|
included there. Calling gnupg_wait_process is required. Returns 0
|
|
|
|
on success or an error code. */
|
|
|
|
gpg_error_t gnupg_spawn_process_fd (const char *pgmname,
|
|
|
|
const char *argv[],
|
|
|
|
int infd, int outfd, int errfd,
|
|
|
|
pid_t *pid);
|
|
|
|
|
|
|
|
|
2004-12-06 19:28:56 +01:00
|
|
|
/* Wait for the process identified by PID to terminate. PGMNAME should
|
2007-08-27 20:10:27 +02:00
|
|
|
be the same as supplied to the spawn fucntion and is only used for
|
|
|
|
diagnostics. Returns 0 if the process succeded, GPG_ERR_GENERAL
|
2007-08-29 11:51:37 +02:00
|
|
|
for any failures of the spawned program or other error codes. If
|
|
|
|
EXITCODE is not NULL the exit code of the process is stored at this
|
|
|
|
address or -1 if it could not be retrieved. */
|
|
|
|
gpg_error_t gnupg_wait_process (const char *pgmname, pid_t pid, int *exitcode);
|
2004-12-06 19:28:56 +01:00
|
|
|
|
|
|
|
|
2006-09-07 17:13:33 +02:00
|
|
|
/* Spawn a new process and immediatley detach from it. The name of
|
|
|
|
the program to exec is PGMNAME and its arguments are in ARGV (the
|
|
|
|
programname is automatically passed as first argument).
|
|
|
|
Environment strings in ENVP are set. An error is returned if
|
|
|
|
pgmname is not executable; to make this work it is necessary to
|
|
|
|
provide an absolute file name. */
|
|
|
|
gpg_error_t gnupg_spawn_process_detached (const char *pgmname,
|
|
|
|
const char *argv[],
|
|
|
|
const char *envp[] );
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-12-06 19:28:56 +01:00
|
|
|
#endif /*GNUPG_COMMON_EXECHELP_H*/
|