2008-01-28 21:37:16 +00:00
|
|
|
/* source: xio-system.c */
|
2008-01-29 21:11:28 +00:00
|
|
|
/* Copyright Gerhard Rieger 2001-2008 */
|
2008-01-27 12:00:08 +00:00
|
|
|
/* Published under the GNU General Public License V.2, see file COPYING */
|
|
|
|
|
|
|
|
/* this file contains the source for opening addresses of system type */
|
|
|
|
|
|
|
|
#include "xiosysincludes.h"
|
|
|
|
#include "xioopen.h"
|
|
|
|
|
|
|
|
#include "xio-progcall.h"
|
|
|
|
#include "xio-system.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if WITH_SYSTEM
|
|
|
|
|
|
|
|
static int xioopen_system(int arg, const char *argv[], struct opt *opts,
|
|
|
|
int xioflags, /* XIO_RDONLY etc. */
|
|
|
|
xiofile_t *fd,
|
|
|
|
unsigned groups,
|
|
|
|
int dummy1, int dummy2, int dummy3
|
|
|
|
);
|
|
|
|
|
2008-02-17 13:59:16 +00:00
|
|
|
static const struct xioaddr_endpoint_desc xioendpoint_system1 = { XIOADDR_SYS, "system", 1, XIOBIT_ALL, GROUP_FD|GROUP_FORK|GROUP_EXEC|GROUP_SOCKET|GROUP_SOCK_UNIX|GROUP_TERMIOS|GROUP_FIFO|GROUP_PTY|GROUP_PARENT, XIOSHUT_UNSPEC, XIOCLOSE_UNSPEC, xioopen_system, 1, 0, 0 HELP(":<shell-command>") };
|
2008-01-27 12:00:08 +00:00
|
|
|
|
2008-02-17 13:59:16 +00:00
|
|
|
const union xioaddr_desc *xioaddrs_system[] = {
|
|
|
|
(union xioaddr_desc *)&xioendpoint_system1,
|
|
|
|
NULL
|
|
|
|
};
|
2008-01-27 12:00:08 +00:00
|
|
|
|
|
|
|
static int xioopen_system(int argc, const char *argv[], struct opt *opts,
|
|
|
|
int xioflags, /* XIO_RDONLY etc. */
|
|
|
|
xiofile_t *fd,
|
|
|
|
unsigned groups,
|
|
|
|
int dummy1, int dummy2, int dummy3
|
|
|
|
) {
|
|
|
|
int status;
|
|
|
|
char *path = NULL;
|
2008-06-07 08:14:56 +00:00
|
|
|
int duptostderr;
|
2008-01-27 12:00:08 +00:00
|
|
|
int result;
|
|
|
|
const char *string = argv[1];
|
|
|
|
|
2008-10-22 00:33:23 +00:00
|
|
|
status = _xioopen_foxec_end(xioflags, &fd->stream, groups, &opts, &duptostderr);
|
2008-01-27 12:00:08 +00:00
|
|
|
if (status < 0) return status;
|
|
|
|
if (status == 0) { /* child */
|
|
|
|
int numleft;
|
|
|
|
|
|
|
|
if (setopt_path(opts, &path) < 0) {
|
|
|
|
/* this could be dangerous, so let us abort this child... */
|
|
|
|
Exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((numleft = leftopts(opts)) > 0) {
|
|
|
|
Error1("%d option(s) could not be used", numleft);
|
|
|
|
showleft(opts);
|
|
|
|
return STAT_NORETRY;
|
|
|
|
}
|
|
|
|
|
2008-06-07 08:14:56 +00:00
|
|
|
/* only now redirect stderr */
|
|
|
|
if (duptostderr >= 0) {
|
|
|
|
diag_dup();
|
|
|
|
Dup2(duptostderr, 2);
|
|
|
|
}
|
2008-01-27 12:00:08 +00:00
|
|
|
Info1("executing shell command \"%s\"", string);
|
|
|
|
result = System(string);
|
|
|
|
if (result != 0) {
|
|
|
|
Warn2("system(\"%s\") returned with status %d", string, result);
|
2008-01-29 21:11:28 +00:00
|
|
|
Warn1("system(): %s", strerror(errno));
|
2008-01-27 12:00:08 +00:00
|
|
|
}
|
|
|
|
Exit(0); /* this child process */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parent */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_SYSTEM */
|