1
0
Files
2022-09-29 17:59:04 +03:00

75 lines
2.2 KiB
Plaintext

'\"macro stdmacro
.if n .pH g3s.system @(#)system 40.15 of 5/22/91
.\" Copyright 1991 UNIX System Laboratories, Inc.
.\" Copyright 1989, 1990 AT&T
.nr X
.if \nX=0 .ds x} system 3S "C Development Set" "\&"
.if \nX=1 .ds x} system 3S "C Development Set"
.if \nX=2 .ds x} system 3S "" "\&"
.if \nX=3 .ds x} system "" "" "\&"
.TH \*(x}
.SH NAME
\f4system\f1 \- issue a shell command
.SH SYNOPSIS
\f4#include <stdlib.h>\f1
.PP
\f4int system (const char \(**string);\f1
.SH DESCRIPTION
\f4system\fP
causes the
.I string\^
to be given to the shell
[see \f4sh\fP(1)]
as input, as if the string had been typed as a command
at a terminal.
The current process waits until the shell has
completed, then returns the exit status of the shell
in the format specified by \f4waitpid\fP(2).
.PP
If \f2string\f1 is a \f4NULL\fP pointer, \f4system\fP checks if \f4/sbin/sh\fP
exists and is executable. If \f4/sbin/sh\fP is available, \f4system\fP
returns non-zero; otherwise it returns zero.
.PP
\f4system\fP fails if one or more of the following are true:
.TP 12
\f4EAGAIN\fP
The system-imposed limit on the total number of processes under execution by
a single user would be exceeded.
.TP 12
\f4EINTR\fP
\f4system\fP was interrupted by a signal.
.TP 12
\f4ENOMEM\fP
The new process requires more memory than is allowed by the system-imposed
maximum \f4MAXMEM\fP.
.SH "SEE ALSO"
\f4exec\fP(2),
\f4waitpid\fP(2),
\f4sh\fP(1).
.SH DIAGNOSTICS
\f4system\fP
forks to create a child process
that in turn execs
\f4/sbin/sh\fP
in order to execute
.IR string .
If the fork or exec fails,
\f4system\fP
returns \-1 and sets
\f4errno\fP.
.SH NOTES
Calling \f4system\fP(3S) in a program that is set user ID to
\f4root\fP is difficult to do without creating unintended
security problems.
For example, since \f4system\fP invokes a copy of \f4sh\fP(1)
to execute the supplied command,
the programmer must be extremely careful not to
allow critical environment variables, such
as \f4\s-1PATH\s+1\fP, which determine the behavior of the shell
to be passed through from the environment of the invoking user
without modification.
It is recommended that \f4system\fP(3S) not be used by set user
ID programs.
.\" @(#)system.3s 6.3 of 10/20/83
.Ee