9fc046
slbt_spawn(): initial implementation.
@@ -5,5 +5,6 @@ API_HEADERS = \
|
|
5
5
|
INTERNAL_HEADERS = \
|
6
6
|
$(PROJECT_DIR)/src/internal/argv/argv.h \
|
7
7
|
$(PROJECT_DIR)/src/internal/$(PACKAGE)_driver_impl.h \
|
8
|
+
$(PROJECT_DIR)/src/internal/$(PACKAGE)_spawn_impl.h \
|
8
9
|
|
9
10
|
ALL_HEADERS = $(API_HEADERS) $(INTERNAL_HEADERS)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/*******************************************************************/
|
2
|
+
/* slibtool: a skinny libtool implementation, written in C */
|
3
|
+
/* Copyright (C) 2016 Z. Gilboa */
|
4
|
+
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
|
5
|
+
/*******************************************************************/
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
extern char ** environ;
|
24
|
+
|
25
|
+
static inline int slbt_spawn(
|
26
|
+
struct slbt_exec_ctx * ectx,
|
27
|
+
bool fwait)
|
28
|
+
{
|
29
|
+
pid_t pid;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
if (posix_spawnp(
|
35
|
+
&pid,
|
36
|
+
ectx->program,
|
37
|
+
0,0,
|
38
|
+
ectx->argv,
|
39
|
+
ectx->envp ? ectx->envp : environ))
|
40
|
+
pid = -1;
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
pid = fork();
|
46
|
+
|
47
|
+
pid = vfork();
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
if (pid < 0)
|
53
|
+
return -1;
|
54
|
+
|
55
|
+
if (pid == 0)
|
56
|
+
return execvp(
|
57
|
+
ectx->program,
|
58
|
+
ectx->argv);
|
59
|
+
|
60
|
+
ectx->pid = pid;
|
61
|
+
|
62
|
+
if (fwait)
|
63
|
+
return waitpid(
|
64
|
+
pid,
|
65
|
+
&ectx->exitcode,
|
66
|
+
0);
|
67
|
+
|
68
|
+
return 0;
|
69
|
+
}
|