Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __SUBCMD_RUN_COMMAND_H
0003 #define __SUBCMD_RUN_COMMAND_H
0004 
0005 #include <unistd.h>
0006 
0007 enum {
0008     ERR_RUN_COMMAND_FORK = 10000,
0009     ERR_RUN_COMMAND_EXEC,
0010     ERR_RUN_COMMAND_PIPE,
0011     ERR_RUN_COMMAND_WAITPID,
0012     ERR_RUN_COMMAND_WAITPID_WRONG_PID,
0013     ERR_RUN_COMMAND_WAITPID_SIGNAL,
0014     ERR_RUN_COMMAND_WAITPID_NOEXIT,
0015 };
0016 #define IS_RUN_COMMAND_ERR(x) (-(x) >= ERR_RUN_COMMAND_FORK)
0017 
0018 struct child_process {
0019     const char **argv;
0020     pid_t pid;
0021     /*
0022      * Using .in, .out, .err:
0023      * - Specify 0 for no redirections (child inherits stdin, stdout,
0024      *   stderr from parent).
0025      * - Specify -1 to have a pipe allocated as follows:
0026      *     .in: returns the writable pipe end; parent writes to it,
0027      *          the readable pipe end becomes child's stdin
0028      *     .out, .err: returns the readable pipe end; parent reads from
0029      *          it, the writable pipe end becomes child's stdout/stderr
0030      *   The caller of start_command() must close the returned FDs
0031      *   after it has completed reading from/writing to it!
0032      * - Specify > 0 to set a channel to a particular FD as follows:
0033      *     .in: a readable FD, becomes child's stdin
0034      *     .out: a writable FD, becomes child's stdout/stderr
0035      *     .err > 0 not supported
0036      *   The specified FD is closed by start_command(), even in case
0037      *   of errors!
0038      */
0039     int in;
0040     int out;
0041     int err;
0042     const char *dir;
0043     const char *const *env;
0044     unsigned no_stdin:1;
0045     unsigned no_stdout:1;
0046     unsigned no_stderr:1;
0047     unsigned exec_cmd:1; /* if this is to be external sub-command */
0048     unsigned stdout_to_stderr:1;
0049     void (*preexec_cb)(void);
0050 };
0051 
0052 int start_command(struct child_process *);
0053 int finish_command(struct child_process *);
0054 int run_command(struct child_process *);
0055 
0056 #define RUN_COMMAND_NO_STDIN 1
0057 #define RUN_EXEC_CMD         2  /*If this is to be external sub-command */
0058 #define RUN_COMMAND_STDOUT_TO_STDERR 4
0059 int run_command_v_opt(const char **argv, int opt);
0060 
0061 #endif /* __SUBCMD_RUN_COMMAND_H */