1 /* source: xio-system.c */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
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
, int xioflags
, xiofile_t
*xfd
, const struct addrdesc
*addrdesc
);
18 const struct addrdesc xioaddr_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>") };
21 static int xioopen_system(
25 int xioflags
, /* XIO_RDONLY etc. */
27 const struct addrdesc
*addrdesc
)
29 struct single
*sfd
= &xfd
->stream
;
34 const char *string
= argv
[1];
37 xio_syntax(argv
[0], 1, argc
-1, addrdesc
->syntax
);
42 _xioopen_foxec(xioflags
, sfd
, addrdesc
->groups
, &opts
, &duptostderr
);
45 if (status
== 0) { /* child */
48 /* do not shutdown connections that belong our parent */
52 if (setopt_path(opts
, &path
) < 0) {
53 /* this could be dangerous, so let us abort this child... */
57 if ((numleft
= leftopts(opts
)) > 0) {
59 Error1("INTERNAL: %d option(s) remained unused", numleft
);
63 /* only now redirect stderr */
64 if (duptostderr
>= 0) {
68 Info1("executing shell command \"%s\"", string
);
70 result
= System(string
);
72 Warn2("system(\"%s\") returned with status %d", string
, result
);
74 Warn1("system(): %s", strerror(errno
));
76 Exit(result
>>8); /* this child process */
80 _xio_openlate(sfd
, opts
);
84 #endif /* WITH_SYSTEM */