version 1 showing authors affecting page license.
.
Rev |
Author |
# |
Line |
1 |
perry |
1 |
SYSTEM |
|
|
2 |
!!!SYSTEM |
|
|
3 |
NAME |
|
|
4 |
SYNOPSIS |
|
|
5 |
DESCRIPTION |
|
|
6 |
RETURN VALUE |
|
|
7 |
CONFORMING TO |
|
|
8 |
BUGS |
|
|
9 |
SEE ALSO |
|
|
10 |
---- |
|
|
11 |
!!NAME |
|
|
12 |
|
|
|
13 |
|
|
|
14 |
system - execute a shell command |
|
|
15 |
!!SYNOPSIS |
|
|
16 |
|
|
|
17 |
|
|
|
18 |
__#include |
|
|
19 |
__ ''string''__); |
|
|
20 |
__ |
|
|
21 |
!!DESCRIPTION |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
__system()__ executes a command specified in |
|
|
25 |
''string'' by calling __/bin/sh -c__ ''string'', |
|
|
26 |
and returns after the command has been completed. During |
|
|
27 |
execution of the command, __SIGCHLD__ will be blocked, |
|
|
28 |
and __SIGINT__ and __SIGQUIT__ will be |
|
|
29 |
ignored. |
|
|
30 |
!!RETURN VALUE |
|
|
31 |
|
|
|
32 |
|
|
|
33 |
The value returned is -1 on error (e.g. fork failed), and |
|
|
34 |
the return status of the command otherwise. This latter |
|
|
35 |
return status is in the format specified in wait(2). |
|
|
36 |
Thus, the exit code of the command will be |
|
|
37 |
''WEXITSTATUS(status)''. In case __/bin/sh__ could not |
|
|
38 |
be executed, the exit status will be that of a command that |
|
|
39 |
does ''exit(127)''. |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
If the value of ''string'' is __NULL__, |
|
|
43 |
__system()__ returns nonzero if the shell is available, |
|
|
44 |
and zero if not. |
|
|
45 |
|
|
|
46 |
|
|
|
47 |
__system()__ does not affect the wait status of any other |
|
|
48 |
children. |
|
|
49 |
!!CONFORMING TO |
|
|
50 |
|
|
|
51 |
|
|
|
52 |
ANSI C, POSIX.2, BSD 4.3 |
|
|
53 |
!!BUGS |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
It is extremely unfortunate that the libc version of |
|
|
57 |
__system()__ ignores interrupts. This makes programs that |
|
|
58 |
call it from a loop uninterruptable. This means that for |
|
|
59 |
such purposes one should not use __system()__ but a |
|
|
60 |
private version like (warning: untested code!) |
|
|
61 |
|
|
|
62 |
|
|
|
63 |
int my_system (const char *command) { |
|
|
64 |
int pid, status; |
|
|
65 |
if (command == 0) |
|
|
66 |
return 1; |
|
|
67 |
pid = fork(); |
|
|
68 |
if (pid == -1) |
|
|
69 |
return -1; |
|
|
70 |
if (pid == 0) { |
|
|
71 |
char *argv[[4]; |
|
|
72 |
argv[[0] = |
|
|
73 |
Do not use __system()__ from a program with suid or sgid privileges, because strange values for some environment variables might be used to subvert system integrity. Use the exec(3) family of functions instead, but not execlp(3) or execvp(3). __system()__ will not, in fact, work properly from programs with suid or sgid privileges on systems on which __/bin/sh__ is __bash__ version 2, since bash 2 drops privileges on startup. (Debian uses a modified bash which does not do this when invoked as __sh__.) |
|
|
74 |
|
|
|
75 |
|
|
|
76 |
The check for the availability of __/bin/sh__ is not |
|
|
77 |
actually performed; it is always assumed to be available. |
|
|
78 |
ISO C specifies the check, but POSIX.2 specifies that the |
|
|
79 |
return shall always be non-zero, since a system without the |
|
|
80 |
shell is not conforming, and it is this that is |
|
|
81 |
implemented. |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
It is possible for the shell command to return 127, so that |
|
|
85 |
code is not a sure indication that the __execve()__ call |
|
|
86 |
failed; check ''errno'' to make sure. |
|
|
87 |
!!SEE ALSO |
|
|
88 |
|
|
|
89 |
|
|
|
90 |
sh(1), signal(2), exec(3) |
|
|
91 |
---- |