run-command.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef __PERF_RUN_COMMAND_H
  2. #define __PERF_RUN_COMMAND_H
  3. enum {
  4. ERR_RUN_COMMAND_FORK = 10000,
  5. ERR_RUN_COMMAND_EXEC,
  6. ERR_RUN_COMMAND_PIPE,
  7. ERR_RUN_COMMAND_WAITPID,
  8. ERR_RUN_COMMAND_WAITPID_WRONG_PID,
  9. ERR_RUN_COMMAND_WAITPID_SIGNAL,
  10. ERR_RUN_COMMAND_WAITPID_NOEXIT,
  11. };
  12. #define IS_RUN_COMMAND_ERR(x) (-(x) >= ERR_RUN_COMMAND_FORK)
  13. struct child_process {
  14. const char **argv;
  15. pid_t pid;
  16. /*
  17. * Using .in, .out, .err:
  18. * - Specify 0 for no redirections (child inherits stdin, stdout,
  19. * stderr from parent).
  20. * - Specify -1 to have a pipe allocated as follows:
  21. * .in: returns the writable pipe end; parent writes to it,
  22. * the readable pipe end becomes child's stdin
  23. * .out, .err: returns the readable pipe end; parent reads from
  24. * it, the writable pipe end becomes child's stdout/stderr
  25. * The caller of start_command() must close the returned FDs
  26. * after it has completed reading from/writing to it!
  27. * - Specify > 0 to set a channel to a particular FD as follows:
  28. * .in: a readable FD, becomes child's stdin
  29. * .out: a writable FD, becomes child's stdout/stderr
  30. * .err > 0 not supported
  31. * The specified FD is closed by start_command(), even in case
  32. * of errors!
  33. */
  34. int in;
  35. int out;
  36. int err;
  37. const char *dir;
  38. const char *const *env;
  39. unsigned no_stdin:1;
  40. unsigned no_stdout:1;
  41. unsigned no_stderr:1;
  42. unsigned perf_cmd:1; /* if this is to be perf sub-command */
  43. unsigned stdout_to_stderr:1;
  44. void (*preexec_cb)(void);
  45. };
  46. int start_command(struct child_process *);
  47. int finish_command(struct child_process *);
  48. int run_command(struct child_process *);
  49. #define RUN_COMMAND_NO_STDIN 1
  50. #define RUN_PERF_CMD 2 /*If this is to be perf sub-command */
  51. #define RUN_COMMAND_STDOUT_TO_STDERR 4
  52. int run_command_v_opt(const char **argv, int opt);
  53. #endif /* __PERF_RUN_COMMAND_H */