Failed to compile on OmniOS due to TCP_INFO
[socat.git] / xio-system.c
blobd232ec3aecaab7d34ca7f5873c84a11af021cedd
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"
8 #include "xioopen.h"
10 #include "xio-progcall.h"
11 #include "xio-system.h"
14 #if WITH_SYSTEM
16 static int xioopen_system(int arg, const char *argv[], struct opt *opts,
17 int xioflags, /* XIO_RDONLY etc. */
18 xiofile_t *fd,
19 unsigned groups,
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. */
28 xiofile_t *fd,
29 unsigned groups,
30 int dummy1, int dummy2, int dummy3
31 ) {
32 int status;
33 char *path = NULL;
34 int duptostderr;
35 int result;
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 */
41 int numleft;
43 /* do not shutdown connections that belong our parent */
44 sock[0] = NULL;
45 sock[1] = NULL;
47 if (setopt_path(opts, &path) < 0) {
48 /* this could be dangerous, so let us abort this child... */
49 Exit(1);
52 if ((numleft = leftopts(opts)) > 0) {
53 Error1("%d option(s) could not be used", numleft);
54 showleft(opts);
55 return STAT_NORETRY;
58 /* only now redirect stderr */
59 if (duptostderr >= 0) {
60 diag_dup();
61 Dup2(duptostderr, 2);
63 Info1("executing shell command \"%s\"", string);
64 errno=0;
65 result = System(string);
66 if (result != 0) {
67 Warn2("system(\"%s\") returned with status %d", string, result);
68 if (errno != 0)
69 Warn1("system(): %s", strerror(errno));
71 Exit(result>>8); /* this child process */
74 /* parent */
75 return 0;
78 #endif /* WITH_SYSTEM */