/* SPDX-License-Identifier: GPL-2.0 */1#ifndef __SUBCMD_RUN_COMMAND_H2#define __SUBCMD_RUN_COMMAND_H34#include <unistd.h>56enum {7ERR_RUN_COMMAND_FORK = 10000,8ERR_RUN_COMMAND_EXEC,9ERR_RUN_COMMAND_PIPE,10ERR_RUN_COMMAND_WAITPID,11ERR_RUN_COMMAND_WAITPID_WRONG_PID,12ERR_RUN_COMMAND_WAITPID_SIGNAL,13ERR_RUN_COMMAND_WAITPID_NOEXIT,14};15#define IS_RUN_COMMAND_ERR(x) (-(x) >= ERR_RUN_COMMAND_FORK)1617struct child_process {18const char **argv;19pid_t pid;20/*21* Using .in, .out, .err:22* - Specify 0 for no redirections (child inherits stdin, stdout,23* stderr from parent).24* - Specify -1 to have a pipe allocated as follows:25* .in: returns the writable pipe end; parent writes to it,26* the readable pipe end becomes child's stdin27* .out, .err: returns the readable pipe end; parent reads from28* it, the writable pipe end becomes child's stdout/stderr29* The caller of start_command() must close the returned FDs30* after it has completed reading from/writing to it!31* - Specify > 0 to set a channel to a particular FD as follows:32* .in: a readable FD, becomes child's stdin33* .out: a writable FD, becomes child's stdout/stderr34* .err > 0 not supported35* The specified FD is closed by start_command(), even in case36* of errors!37*/38int in;39int out;40int err;41const char *dir;42const char *const *env;43int finish_result;44unsigned no_stdin:1;45unsigned no_stdout:1;46unsigned no_stderr:1;47unsigned exec_cmd:1; /* if this is to be external sub-command */48unsigned stdout_to_stderr:1;49unsigned finished:1;50void (*preexec_cb)(void);51/* If set, call function in child rather than doing an exec. */52int (*no_exec_cmd)(struct child_process *process);53};5455int start_command(struct child_process *);56int check_if_command_finished(struct child_process *);57int finish_command(struct child_process *);58int run_command(struct child_process *);5960#define RUN_COMMAND_NO_STDIN 161#define RUN_EXEC_CMD 2 /*If this is to be external sub-command */62#define RUN_COMMAND_STDOUT_TO_STDERR 463int run_command_v_opt(const char **argv, int opt);6465#endif /* __SUBCMD_RUN_COMMAND_H */666768