add listen-timeout to function as an accept timeout
[socat/sam.git] / xio-system.c
blob39a519370c1dfb1646109e05353998b6fcfdc0c1
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"
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 if (setopt_path(opts, &path) < 0) {
44 /* this could be dangerous, so let us abort this child... */
45 Exit(1);
48 if ((numleft = leftopts(opts)) > 0) {
49 Error1("%d option(s) could not be used", numleft);
50 showleft(opts);
51 return STAT_NORETRY;
54 /* only now redirect stderr */
55 if (duptostderr >= 0) {
56 diag_dup();
57 Dup2(duptostderr, 2);
59 Info1("executing shell command \"%s\"", string);
60 result = System(string);
61 if (result != 0) {
62 Warn2("system(\"%s\") returned with status %d", string, result);
63 Warn1("system(): %s", strerror(errno));
65 Exit(0); /* this child process */
68 /* parent */
69 return 0;
72 #endif /* WITH_SYSTEM */