]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/system.3
triggered by http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=283179
[thirdparty/man-pages.git] / man3 / system.3
CommitLineData
fea681da
MK
1.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2.\"
3.\" Permission is granted to make and distribute verbatim copies of this
4.\" manual provided the copyright notice and this permission notice are
5.\" preserved on all copies.
6.\"
7.\" Permission is granted to copy and distribute modified versions of this
8.\" manual under the conditions for verbatim copying, provided that the
9.\" entire resulting derived work is distributed under the terms of a
10.\" permission notice identical to this one.
11.\"
12.\" Since the Linux kernel and libraries are constantly changing, this
13.\" manual page may be incorrect or out-of-date. The author(s) assume no
14.\" responsibility for errors or omissions, or for damages resulting from
15.\" the use of the information contained herein. The author(s) may not
16.\" have taken the same level of care in the production of this manual,
17.\" which is licensed free of charge, as they might when working
18.\" professionally.
19.\"
20.\" Formatted or processed versions of this manual, if unaccompanied by
21.\" the source, must acknowledge the copyright and authors of this work.
22.\" License.
23.\" Modified Sat Jul 24 17:51:15 1993 by Rik Faith (faith@cs.unc.edu)
24.\" Modified 11 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk)
25.\" Modified 14 May 2001, 23 Sep 2001 by aeb
26.\"
27.TH SYSTEM 3 2001-09-23 "" "Linux Programmer's Manual"
28.SH NAME
29system \- execute a shell command
30.SH SYNOPSIS
31.nf
32.B #include <stdlib.h>
33.sp
34.BI "int system(const char *" "string" );
35.fi
36.SH DESCRIPTION
37.B system()
38executes a command specified in
39.I string
40by calling
41.BR "/bin/sh -c"
42.IR string ,
43and returns after the command has been completed.
44During execution of the command,
45.B SIGCHLD
46will be blocked, and
47.B SIGINT
48and
49.B SIGQUIT
50will be ignored.
51.SH "RETURN VALUE"
52The value returned is \-1 on error (e.g. fork failed),
53and the return status of the command otherwise.
54This latter return status is in the format
55specified in
56.BR wait (2).
57Thus, the exit code of the command will be
58.IR WEXITSTATUS(status) .
59In case
60.B "/bin/sh"
61could not be executed, the exit status will be that of
62a command that does
63.IR exit(127) .
64.PP
65If the value of
66.I string
67is
68.BR NULL ,
69.B system()
70returns nonzero if the shell is available, and zero if not.
71.PP
72.B system()
73does not affect the wait status of any other children.
74.SH "CONFORMING TO"
75ANSI C, POSIX.2, BSD 4.3
76.SH NOTES
77.PP
78As mentioned,
79.B system()
80ignores SIGINT and SIGQUIT. This may make programs that call it
81from a loop uninterruptable, unless they take care themselves
82to check the exit status of the child. E.g.
83.br
84.nf
85
86 while(something) {
87 int ret = system("foo");
88
89 if (WIFSIGNALED(ret) &&
90 (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
91 break;
92 }
93.fi
94.PP
95Do not use
96.B system()
97from a program with suid or sgid privileges, because strange values for
98some environment variables might be used to subvert system integrity.
99Use the
100.BR exec (3)
101family of functions instead, but not
102.BR execlp (3)
103or
104.BR execvp (3).
105.B system()
106will not, in fact, work properly from programs with suid or sgid
107privileges on systems on which
108.B /bin/sh
109is bash version 2, since bash 2 drops privileges on startup.
110(Debian uses a modified bash which does not do this when invoked as
111.BR sh .)
112.PP
113The check for the availability of
114.B /bin/sh
115is not actually performed; it is always assumed to be available. ISO
116C specifies the check, but POSIX.2 specifies that the return shall
117always be non-zero, since a system without the shell is not
118conforming, and it is this that is implemented.
119.PP
120It is possible for the shell command to return 127, so that code is not
121a sure indication that the
122.B execve()
123call failed.
124.SH "SEE ALSO"
125.BR sh (1),
126.BR signal (2),
127.BR wait (2),
128.BR exec (3)