1 /* source: xio-system.c */
2 /* Copyright Gerhard Rieger 2001-2008 */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* this file contains the source for opening addresses of system type */
7 #include "xiosysincludes.h"
10 #include "xio-progcall.h"
11 #include "xio-system.h"
16 static int xioopen_system(int arg
, const char *argv
[], struct opt
*opts
,
17 int xioflags
, /* XIO_RDONLY etc. */
20 int dummy1
, int dummy2
, int dummy3
23 const struct addrdesc addr_system
= { "system", 3, xioopen_system
, GROUP_FD
|GROUP_FORK
|GROUP_EXEC
|GROUP_SOCKET
|GROUP_SOCK_UNIX
|GROUP_TERMIOS
|GROUP_FIFO
|GROUP_PTY
|GROUP_PARENT
, 1, 0, 0 HELP(":<shell-command>") };
26 static int xioopen_system(int argc
, const char *argv
[], struct opt
*opts
,
27 int xioflags
, /* XIO_RDONLY etc. */
30 int dummy1
, int dummy2
, int dummy3
36 const char *string
= argv
[1];
38 status
= _xioopen_foxec(xioflags
, &fd
->stream
, groups
, &opts
, &duptostderr
);
39 if (status
< 0) return status
;
40 if (status
== 0) { /* child */
43 if (setopt_path(opts
, &path
) < 0) {
44 /* this could be dangerous, so let us abort this child... */
48 if ((numleft
= leftopts(opts
)) > 0) {
49 Error1("%d option(s) could not be used", numleft
);
54 /* only now redirect stderr */
55 if (duptostderr
>= 0) {
59 Info1("executing shell command \"%s\"", string
);
60 result
= System(string
);
62 Warn2("system(\"%s\") returned with status %d", string
, result
);
63 Warn1("system(): %s", strerror(errno
));
65 Exit(0); /* this child process */
72 #endif /* WITH_SYSTEM */