aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/subcmd/run-command.h
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@redhat.com>2015-12-15 10:39:39 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-12-17 12:27:14 -0500
commit4b6ab94eabe4f55371cff4569750bb3996c55db6 (patch)
treedb5b95ed4647e3455bb1b1d4bb24137708a97829 /tools/lib/subcmd/run-command.h
parent2f4ce5ec1d447beb42143a9653716a2ab025161e (diff)
perf subcmd: Create subcmd library
Move the subcommand-related files from perf to a new library named libsubcmd.a. Since we're moving files anyway, go ahead and rename 'exec_cmd.*' to 'exec-cmd.*' to be consistent with the naming of all the other files. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/c0a838d4c878ab17fee50998811612b2281355c1.1450193761.git.jpoimboe@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/subcmd/run-command.h')
-rw-r--r--tools/lib/subcmd/run-command.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/tools/lib/subcmd/run-command.h b/tools/lib/subcmd/run-command.h
new file mode 100644
index 000000000000..4a55393a6547
--- /dev/null
+++ b/tools/lib/subcmd/run-command.h
@@ -0,0 +1,60 @@
1#ifndef __PERF_RUN_COMMAND_H
2#define __PERF_RUN_COMMAND_H
3
4#include <unistd.h>
5
6enum {
7 ERR_RUN_COMMAND_FORK = 10000,
8 ERR_RUN_COMMAND_EXEC,
9 ERR_RUN_COMMAND_PIPE,
10 ERR_RUN_COMMAND_WAITPID,
11 ERR_RUN_COMMAND_WAITPID_WRONG_PID,
12 ERR_RUN_COMMAND_WAITPID_SIGNAL,
13 ERR_RUN_COMMAND_WAITPID_NOEXIT,
14};
15#define IS_RUN_COMMAND_ERR(x) (-(x) >= ERR_RUN_COMMAND_FORK)
16
17struct child_process {
18 const char **argv;
19 pid_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 stdin
27 * .out, .err: returns the readable pipe end; parent reads from
28 * it, the writable pipe end becomes child's stdout/stderr
29 * The caller of start_command() must close the returned FDs
30 * 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 stdin
33 * .out: a writable FD, becomes child's stdout/stderr
34 * .err > 0 not supported
35 * The specified FD is closed by start_command(), even in case
36 * of errors!
37 */
38 int in;
39 int out;
40 int err;
41 const char *dir;
42 const char *const *env;
43 unsigned no_stdin:1;
44 unsigned no_stdout:1;
45 unsigned no_stderr:1;
46 unsigned exec_cmd:1; /* if this is to be external sub-command */
47 unsigned stdout_to_stderr:1;
48 void (*preexec_cb)(void);
49};
50
51int start_command(struct child_process *);
52int finish_command(struct child_process *);
53int run_command(struct child_process *);
54
55#define RUN_COMMAND_NO_STDIN 1
56#define RUN_EXEC_CMD 2 /*If this is to be external sub-command */
57#define RUN_COMMAND_STDOUT_TO_STDERR 4
58int run_command_v_opt(const char **argv, int opt);
59
60#endif /* __PERF_RUN_COMMAND_H */