1 #include <reproc/run.h>
2
3 #include <reproc/drain.h>
4
5 #include "error.h"
6
reproc_run(const char * const * argv,reproc_options options)7 int reproc_run(const char *const *argv, reproc_options options)
8 {
9 if (!options.redirect.discard && !options.redirect.file &&
10 !options.redirect.path) {
11 options.redirect.parent = true;
12 }
13
14 return reproc_run_ex(argv, options, REPROC_SINK_NULL, REPROC_SINK_NULL);
15 }
16
reproc_run_ex(const char * const * argv,reproc_options options,reproc_sink out,reproc_sink err)17 int reproc_run_ex(const char *const *argv,
18 reproc_options options, // lgtm [cpp/large-parameter]
19 reproc_sink out,
20 reproc_sink err)
21 {
22 reproc_t *process = NULL;
23 int r = REPROC_ENOMEM;
24
25 // There's no way for `reproc_run_ex` to inform the caller whether we're in
26 // the forked process or the parent process so let's not allow forking when
27 // using `reproc_run_ex`.
28 ASSERT_EINVAL(!options.fork);
29
30 process = reproc_new();
31 if (process == NULL) {
32 goto finish;
33 }
34
35 r = reproc_start(process, argv, options);
36 if (r < 0) {
37 goto finish;
38 }
39
40 r = reproc_drain(process, out, err);
41 if (r < 0) {
42 goto finish;
43 }
44
45 r = reproc_stop(process, options.stop);
46 if (r < 0) {
47 goto finish;
48 }
49
50 finish:
51 reproc_destroy(process);
52
53 return r;
54 }
55