home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / monitor / shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  1.1 KB  |  60 lines

  1. # include    "monitor.h"
  2. # include    <ingres.h>
  3. # include    <aux.h>
  4. # include    <opsys.h>
  5.  
  6.  
  7. /*
  8. **  SHELL -- call unix shell
  9. **
  10. **    The UNIX shell is called.  Shell() first tries to call an
  11. **    alternate shell defined by the macro {shell}, and if it fails
  12. **    calls /bin/sh.
  13. **
  14. **    If an argument is supplied, it is a shell file which is
  15. **    supplied to the shell.
  16. **
  17. **    Trace Flags:
  18. **        34
  19. */
  20.  
  21. shell()
  22. {
  23.     register int    i;
  24.     register char    *p;
  25.     register char    *shellfile;
  26.     extern char    *getfilenm();
  27.     extern char    *macro();
  28.  
  29.     shellfile = getfilenm();
  30.     if (*shellfile == 0)
  31.         shellfile = 0;
  32.  
  33.     fclose(Qryiop);
  34.     if ((Xwaitpid = fork()) == -1)
  35.         syserr("shell: fork");
  36.     if (Xwaitpid == 0)
  37.     {
  38.         setuid(getuid());
  39.         setgid(getgid());
  40.         for (i = 3; i < NOFILE; i++)
  41.             close(i);
  42.         p = macro("{shell}");
  43. #        ifdef xMTR3
  44.         tTfp(34, 0, "{shell} = '%o'\n", p);
  45. #        endif
  46.         if (p != 0)
  47.         {
  48.             execl(p, p, shellfile, Qbname, 0);
  49.             printf("Cannot call %s; using /bin/sh\n", p);
  50.         }
  51.         execl("/bin/sh", "sh", shellfile, Qbname, 0);
  52.         syserr("shell: exec");
  53.     }
  54.  
  55.     if (Nodayfile >= 0)
  56.         printf(">>shell\n");
  57.     /* wait for shell to complete */
  58.     xwait();
  59. }
  60.