25
25
#include <string.h>
26
26
#include <sys/wait.h>
27
27
28
+ #define EXECS_SOVERSION 1
29
+
28
30
extern char * * environ ;
29
31
30
32
/* This header file declares all the functions defined in
31
- the libexecs and libeexecs libraries.
32
- libeexecs is a minimal subset of the libexecs library designed
33
- for embedded systems with strict memory requirements.
33
+ the libexecs and libeexecs libraries.
34
+ libeexecs is a minimal subset of the libexecs library designed
35
+ for embedded systems with strict memory requirements.
34
36
It implements only the execs* functions. Programs using libexecs
35
37
can also use the esystem (a.k.a. system_eexecsp) inline function */
36
38
@@ -45,27 +47,26 @@ extern void *execs_fork_security_arg;
45
47
/* execs is like execv: argv is computed by parsing args */
46
48
/* execsp is like execvp: argv is computed by parsing args,
47
49
argv[0] is the executable file to be searched for along $PATH */
48
- /* execse and execspe permit the specification of the environment
50
+ /* execse and execspe permit the specification of the environment
49
51
(as in execve or execvpe) */
50
52
/* execs, execse, execsp and execspe do not require dynamic allocation *but*
51
53
require an extra copy of args on the stack */
52
- /* in all eexecs* functions, the string args is modified
54
+ /* in all eexecs* functions, the string args is modified
53
55
(no extra copies on the stack, args is parsed on itself): */
54
- int execs_common (const char * path , const char * args , char * const envp [], char * buf );
56
+ #define EXECS_NOSEQ 0x1
57
+ #define EXECS_NOVAR 0x2
55
58
56
- static inline int execse (const char * path , const char * args , char * const envp []) {
57
- char buf [strlen (args )+ 1 ];
58
- return execs_common (path , args , envp , buf );
59
- }
59
+ int _execs_common (const char * path , const char * args , char * const envp [], char * buf , int flags );
60
60
61
- #define execs (path , args ) execse((path),(args),environ)
62
- #define execsp (args ) execse(NULL,(args),environ)
63
- #define execspe (args ,env ) execse(NULL,(args),(env))
61
+ #define execs (path , args ) _execs_common((path),(args),environ,NULL,EXECS_NOSEQ)
62
+ #define execse (path , args , env ) _execs_common((path),(args),(env),NULL,EXECS_NOSEQ)
63
+ #define execsp (args ) _execs_common(NULL,(args),environ,NULL,EXECS_NOSEQ)
64
+ #define execspe (args ,env ) _execs_common(NULL,(args),(env),NULL,EXECS_NOSEQ)
64
65
65
- #define eexecs (path , args ) execs_common ((path),(args),environ,(args))
66
- #define eexecse (path , args , env ) execs_common ((path),(args),(env),(args))
67
- #define eexecsp (args ) execs_common (NULL,(args),environ,(args))
68
- #define eexecspe (args ,env ) execs_common (NULL,(args),(env),(args))
66
+ #define eexecs (path , args ) _execs_common ((path),(args),environ,(args),EXECS_NOSEQ )
67
+ #define eexecse (path , args , env ) _execs_common ((path),(args),(env),(args),EXECS_NOSEQ )
68
+ #define eexecsp (args ) _execs_common (NULL,(args),environ,(args),EXECS_NOSEQ )
69
+ #define eexecspe (args ,env ) _execs_common (NULL,(args),(env),(args),EXECS_NOSEQ )
69
70
70
71
static inline int system_eexecsp (const char * command ) {
71
72
int status ;
@@ -75,7 +76,7 @@ static inline int system_eexecsp(const char *command) {
75
76
return -1 ;
76
77
case 0 :
77
78
if (__builtin_expect (execs_fork_security == NULL || execs_fork_security (execs_fork_security_arg ) == 0 , 1 ))
78
- execs_common (NULL , (char * ) command , environ , (char * ) command );
79
+ _execs_common (NULL , (char * ) command , environ , (char * ) command , 0 );
79
80
_exit (127 );
80
81
default :
81
82
waitpid (pid ,& status ,0 );
@@ -87,52 +88,60 @@ static inline int system_eexecsp(const char *command) {
87
88
88
89
/******** library functions defined in libexecs only (not in libeexec) ********/
89
90
90
- /* system_nosh is an "almost" drop in replacement for system(3).
91
- it does not start a shell but it parses the arguments and
92
- runs the command */
93
- /* system_execs is similar to system_nosh but instead of searching the
94
- executable file along the directories listed in $PATH it starts
95
- the program whose path has been passed as its first arg. */
96
- int system_execsr (const char * path , const char * command , int redir [3 ]);
91
+ int _system_common (const char * path , const char * command , int redir [3 ], int flags );
97
92
98
- #define system_nosh (cmd ) system_execsr(NULL,(cmd),NULL)
93
+ /* system_safe requires the absolute path of the command */
94
+ /* system_execs executes the program whose path has been passed as its first arg. */
95
+ #define system_safe (cmd ) _system_common("",(cmd),NULL,EXECS_NOSEQ | EXECS_NOVAR)
99
96
100
- #define system_execsrp (cmd ,redir ) system_execsr(NULL,(cmd),(redir))
101
- #define system_execsra (cmd ,redir ) system_execsr("",(cmd),(redir))
102
- #define system_execs (path ,cmd ) system_execsr((path),(cmd),NULL)
103
- #define system_execsp (cmd ) system_execsr(NULL,(cmd),NULL)
104
- #define system_execsa (cmd ) system_execsr("",(cmd),NULL)
97
+ #define system_execs (path ,cmd ) _system_common((path),(cmd),NULL,EXECS_NOSEQ)
98
+ #define system_execsp (cmd ) _system_common(NULL,(cmd),NULL,EXECS_NOSEQ)
99
+ #define system_execsa (cmd ) _system_common("",(cmd),NULL,EXECS_NOSEQ)
100
+ #define system_execsr (path ,command ,redir ) _system_common((path),(cmd),(redir),EXECS_NOSEQ)
101
+ #define system_execsrp (cmd ,redir ) _system_common(NULL,(cmd),(redir),EXECS_NOSEQ)
102
+ #define system_execsra (cmd ,redir ) _system_common("",(cmd),(redir),EXECS_NOSEQ)
105
103
106
- /* popen_nosh is an "almost" drop in replacement for popen(3),
107
- and pclose_nosh is its counterpart for pclose(3). */
104
+ /* system_nosh is an "almost" drop in replacement for system(3).
105
+ it does not start a shell but it parses the arguments and
106
+ runs the command */
107
+ /* system_execsq* support colon separated sequences of commands */
108
+ #define system_nosh (cmd ) _system_common(NULL,(cmd),NULL,0)
109
+ #define system_execsqp (cmd ) _system_common(NULL,(cmd),NULL,0)
110
+ #define system_execsqa (cmd ) _system_common("",(cmd),NULL,0)
111
+ #define system_execsqrp (cmd ,redir ) _system_common(NULL,(cmd),(redir),0)
112
+ #define system_execsqra (cmd ,redir ) _system_common("",(cmd),(redir),0)
113
+
114
+ FILE * _popen_common (const char * path , const char * command , const char * type , int flags );
108
115
/* popen_execs/pclose_execs do not use $PATH to search the executable file*/
109
- FILE * popen_execs (const char * path , const char * command , const char * type );
110
116
int pclose_execs (FILE * stream );
111
117
112
- #define popen_nosh (cmd , type ) popen_execs(NULL, (cmd), (type))
113
- #define pclose_nosh (stream ) pclose_execs(stream)
118
+ /* popen_nosh is an "almost" drop in replacement for popen(3),
119
+ and pclose_nosh is its counterpart for pclose(3). */
120
+ #define popen_nosh (cmd , type ) _popen_common(NULL, (cmd), (type))
121
+ #define pclose_nosh (stream ) _popen_common(stream)
114
122
115
- #define popen_execsp (cmd , type ) popen_execs(NULL, (cmd), (type))
123
+ #define popen_execs (path , cmd , type ) _popen_common(path, (cmd), (type), EXECS_NOSEQ)
124
+ #define popen_execsp (cmd , type ) _popen_common(NULL, (cmd), (type), EXECS_NOSEQ)
116
125
#define pclose_execsp (stream ) pclose_execs(stream)
117
126
118
127
/* run a command in coprocessing mode */
119
- pid_t coprocess_common (const char * path , const char * command ,
120
- char * const argv [], char * const envp [], int pipefd [2 ]);
128
+ pid_t _coprocess_common (const char * path , const char * command ,
129
+ char * const argv [], char * const envp [], int pipefd [2 ], int flags );
121
130
122
- #define coprocv (path , argv , pfd ) coprocess_common ((path),NULL,(argv), environ, pfd)
123
- #define coprocve (path , argv , env , pfd ) coprocess_common ((path),NULL,(argv), (env), pfd)
124
- #define coprocvp (file , argv , pfd ) coprocess_common (NULL,(file),(argv), environ, pfd)
125
- #define coprocvpe (file , argv , env , pfd ) coprocess_common (NULL,(file),(argv), (env), pfd)
131
+ #define coprocv (path , argv , pfd ) _coprocess_common ((path),NULL,(argv), environ, pfd)
132
+ #define coprocve (path , argv , env , pfd ) _coprocess_common ((path),NULL,(argv), (env), pfd)
133
+ #define coprocvp (file , argv , pfd ) _coprocess_common (NULL,(file),(argv), environ, pfd)
134
+ #define coprocvpe (file , argv , env , pfd ) _coprocess_common (NULL,(file),(argv), (env), pfd)
126
135
127
- #define coprocs (path , cmd , pfd ) coprocess_common ((path),(cmd),NULL, environ, pfd)
128
- #define coprocse (path , cmd , env , pfd ) coprocess_common ((path),(cmd),NULL, (env), pfd)
129
- #define coprocsp (cmd , pfd ) coprocess_common (NULL,(cmd),NULL, environ, pfd)
130
- #define coprocspe (cmd , env , pfd ) coprocess_common (NULL,(cmd),NULL, (env), pfd)
136
+ #define coprocs (path , cmd , pfd ) _coprocess_common ((path),(cmd),NULL, environ, pfd)
137
+ #define coprocse (path , cmd , env , pfd ) _coprocess_common ((path),(cmd),NULL, (env), pfd)
138
+ #define coprocsp (cmd , pfd ) _coprocess_common (NULL,(cmd),NULL, environ, pfd)
139
+ #define coprocspe (cmd , env , pfd ) _coprocess_common (NULL,(cmd),NULL, (env), pfd)
131
140
132
141
/* Low level argc management functions */
133
142
134
- /* s2argv parses args.
135
- It allocates, initializes and returns an argv array, ready for execv.
143
+ /* s2argv parses args.
144
+ It allocates, initializes and returns an argv array, ready for execv.
136
145
s2argv is able to parse several commands separated by semicolons (;).
137
146
The return value is the sequence of all the corresponding argv
138
147
(each one has a NULL element as its terminator) and one further
@@ -145,7 +154,7 @@ char **s2argv(const char *args);
145
154
/* s2argv_free deallocates an argv returned by s2argv */
146
155
void s2argv_free (char * * argv );
147
156
148
- /* number of elements of argv */
157
+ /* the sum of s2argc for all commands, including the NULLs */
149
158
size_t s2argvlen (char * * argv );
150
159
151
160
/* argc of the (first) command */
@@ -155,16 +164,13 @@ size_t s2argc(char **argv);
155
164
/* var definition function (e.g. s2argv_getvar=getenv)*/
156
165
typedef char * (* s2argv_getvar_t ) (const char * name );
157
166
extern s2argv_getvar_t s2argv_getvar ;
158
- /* getvar_null is the deafult value for s2argv_getvar,
159
- it always returns an empty string for any variable name */
160
- char * getvar_null (const char * name );
161
-
162
167
163
168
/* multi argv. Args can contain several commands semicolon (;) separated.
164
169
This function parses args and calls f for each command/argv in args.
165
170
If f returns 0 s2multiargv calls f for the following argv, otherwise
166
- returns the non-zero value.
171
+ returns the non-zero value.
167
172
*/
168
- int s2multiargv (const char * args , int (* f )(char * * argv , void * opaque ), void * opaque );
173
+ int s2multiargv (const char * args ,
174
+ int (* f )(char * * argv , void * opaque ), void * opaque , int flags );
169
175
170
176
#endif
0 commit comments