You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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 */
  4. /* this file contains the source for opening addresses of system type */
  5. #include "xiosysincludes.h"
  6. #include "xioopen.h"
  7. #include "xio-progcall.h"
  8. #include "xio-system.h"
  9. #if WITH_SYSTEM
  10. static int xioopen_system(int arg, const char *argv[], struct opt *opts,
  11. int xioflags, /* XIO_RDONLY etc. */
  12. xiofile_t *fd,
  13. unsigned groups,
  14. int dummy1, int dummy2, int dummy3
  15. );
  16. 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>") };
  17. static int xioopen_system(int argc, const char *argv[], struct opt *opts,
  18. int xioflags, /* XIO_RDONLY etc. */
  19. xiofile_t *fd,
  20. unsigned groups,
  21. int dummy1, int dummy2, int dummy3
  22. ) {
  23. int status;
  24. char *path = NULL;
  25. int duptostderr;
  26. int result;
  27. const char *string = argv[1];
  28. status = _xioopen_foxec(xioflags, &fd->stream, groups, &opts, &duptostderr);
  29. if (status < 0) return status;
  30. if (status == 0) { /* child */
  31. int numleft;
  32. /* do not shutdown connections that belong our parent */
  33. sock[0] = NULL;
  34. sock[1] = NULL;
  35. if (setopt_path(opts, &path) < 0) {
  36. /* this could be dangerous, so let us abort this child... */
  37. Exit(1);
  38. }
  39. if ((numleft = leftopts(opts)) > 0) {
  40. Error1("%d option(s) could not be used", numleft);
  41. showleft(opts);
  42. return STAT_NORETRY;
  43. }
  44. /* only now redirect stderr */
  45. if (duptostderr >= 0) {
  46. diag_dup();
  47. Dup2(duptostderr, 2);
  48. }
  49. Info1("executing shell command \"%s\"", string);
  50. errno=0;
  51. result = System(string);
  52. if (result != 0) {
  53. Warn2("system(\"%s\") returned with status %d", string, result);
  54. if (errno != 0)
  55. Warn1("system(): %s", strerror(errno));
  56. }
  57. Exit(result>>8); /* this child process */
  58. }
  59. /* parent */
  60. return 0;
  61. }
  62. #endif /* WITH_SYSTEM */