14
14
* GNU General Public License for more details.
16
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
21
20
#ifndef GNUPG_COMMON_EXECHELP_H
22
21
#define GNUPG_COMMON_EXECHELP_H
24
/* Portable function to create a pipe. Under Windows the write end is
26
gpg_error_t gnupg_create_inbound_pipe (int filedes[2]);
26
29
/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to
27
30
stdin, write the output to OUTFILE, return a new stream in
28
31
STATUSFILE for stderr and the pid of the process in PID. The
29
32
arguments for the process are expected in the NULL terminated array
30
ARGV. The program name itself should not be included there. if
33
ARGV. The program name itself should not be included there. If
31
34
PREEXEC is not NULL, that function will be called right before the
32
exec. Returns 0 on success or an error code. */
35
exec. FLAGS is currently only useful for W32, see the source for
36
details. Calling gnupg_wait_process is required. Returns 0 on
37
success or an error code. */
33
38
gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[],
34
39
FILE *infile, FILE *outfile,
35
void (*preexec)(void),
40
void (*preexec)(void), unsigned int flags,
36
41
FILE **statusfile, pid_t *pid);
44
/* Simplified version of gnupg_spawn_process. This function forks and
45
then execs PGMNAME, while connecting INFD to stdin, OUTFD to stdout
46
and ERRFD to stderr (any of them may be -1 to connect them to
47
/dev/null). The arguments for the process are expected in the NULL
48
terminated array ARGV. The program name itself should not be
49
included there. Calling gnupg_wait_process is required. Returns 0
50
on success or an error code. */
51
gpg_error_t gnupg_spawn_process_fd (const char *pgmname,
53
int infd, int outfd, int errfd,
38
57
/* Wait for the process identified by PID to terminate. PGMNAME should
39
be the same as suplieed to the spawn fucntion and is only used for
40
diagnostics. Returns 0 if the process succeded, GPG_ERR_GENERAL for
41
any failures of the spawned program or other error codes.*/
42
gpg_error_t gnupg_wait_process (const char *pgmname, pid_t pid);
58
be the same as supplied to the spawn fucntion and is only used for
59
diagnostics. Returns 0 if the process succeded, GPG_ERR_GENERAL
60
for any failures of the spawned program or other error codes. If
61
EXITCODE is not NULL the exit code of the process is stored at this
62
address or -1 if it could not be retrieved. */
63
gpg_error_t gnupg_wait_process (const char *pgmname, pid_t pid, int *exitcode);
66
/* Spawn a new process and immediatley detach from it. The name of
67
the program to exec is PGMNAME and its arguments are in ARGV (the
68
programname is automatically passed as first argument).
69
Environment strings in ENVP are set. An error is returned if
70
pgmname is not executable; to make this work it is necessary to
71
provide an absolute file name. */
72
gpg_error_t gnupg_spawn_process_detached (const char *pgmname,
45
78
#endif /*GNUPG_COMMON_EXECHELP_H*/