Annotation of embedaddon/strongswan/src/libstrongswan/utils/process.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2014 Martin Willi
                      3:  * Copyright (C) 2014 revosec AG
                      4:  *
                      5:  * This program is free software; you can redistribute it and/or modify it
                      6:  * under the terms of the GNU General Public License as published by the
                      7:  * Free Software Foundation; either version 2 of the License, or (at your
                      8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                      9:  *
                     10:  * This program is distributed in the hope that it will be useful, but
                     11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     13:  * for more details.
                     14:  */
                     15: 
                     16: /**
                     17:  * @defgroup process process
                     18:  * @{ @ingroup utils
                     19:  */
                     20: 
                     21: #ifndef PROCESS_H_
                     22: #define PROCESS_H_
                     23: 
                     24: #include <utils/utils.h>
                     25: 
                     26: typedef struct process_t process_t;
                     27: 
                     28: /**
                     29:  * Child process spawning abstraction
                     30:  */
                     31: struct process_t {
                     32: 
                     33:        /**
                     34:         * Wait for a started process to terminate.
                     35:         *
                     36:         * The process object gets destroyed by this call, regardless of the
                     37:         * return value.
                     38:         *
                     39:         * The returned code is the exit code, not the status returned by waitpid().
                     40:         * If the program could not be executed or has terminated abnormally
                     41:         * (by signals etc.), FALSE is returned.
                     42:         *
                     43:         * @param code  process exit code, set only if TRUE returned
                     44:         * @return              TRUE if program exited normally through exit()
                     45:         */
                     46:        bool (*wait)(process_t *this, int *code);
                     47: };
                     48: 
                     49: /**
                     50:  * Spawn a child process with redirected I/O.
                     51:  *
                     52:  * Forks the current process, optionally redirects stdin/out/err to the current
                     53:  * process, and executes the provided program with arguments.
                     54:  *
                     55:  * The process to execute is specified as argv[0], followed by the process
                     56:  * arguments, followed by NULL. envp[] has a NULL terminated list of arguments
                     57:  * to invoke the process with.
                     58:  *
                     59:  * If any of in/out/err is given, stdin/out/err from the child process get
                     60:  * connected over pipe()s to the caller. If close_all is TRUE, all other
                     61:  * open file descriptors get closed, regardless of any CLOEXEC setting.
                     62:  *
                     63:  * A caller must close all of the returned file descriptors to avoid file
                     64:  * descriptor leaks.
                     65:  *
                     66:  * A non-NULL return value does not guarantee that the process has been
                     67:  * invoked successfully.
                     68:  *
                     69:  * @param argv         NULL terminated process arguments, with argv[0] as program
                     70:  * @param envp         NULL terminated list of environment variables
                     71:  * @param in           pipe fd returned for redirecting data to child stdin
                     72:  * @param out          pipe fd returned to redirect child stdout data to
                     73:  * @param err          pipe fd returned to redirect child stderr data to
                     74:  * @param close_all    close all open file descriptors above 2 before execve()
                     75:  * @return                     process, NULL on failure
                     76:  */
                     77: process_t* process_start(char *const argv[], char *const envp[],
                     78:                                                 int *in, int *out, int *err, bool close_all);
                     79: 
                     80: /**
                     81:  * Spawn a command in a shell child process.
                     82:  *
                     83:  * Same as process_start(), but passes a single command to a shell, such as
                     84:  * "sh -c". See process_start() for I/O redirection notes.
                     85:  *
                     86:  * @param envp         NULL terminated list of environment variables
                     87:  * @param in           pipe fd returned for redirecting data to child stdin
                     88:  * @param out          pipe fd returned to redirect child stdout data to
                     89:  * @param err          pipe fd returned to redirect child stderr data to
                     90:  * @param fmt          printf format string for command
                     91:  * @param ...          arguments for fmt
                     92:  * @return                     process, NULL on failure
                     93:  */
                     94: process_t* process_start_shell(char *const envp[], int *in, int *out, int *err,
                     95:                                                           char *fmt, ...);
                     96: 
                     97: #endif /** PROCESS_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>