home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / pcomm2 / part05 / n_shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-14  |  1.2 KB  |  62 lines

  1. /*
  2.  * Spawn a "native" shell.  Native means the shell found in the SHELL
  3.  * environmental variable.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <signal.h>
  8. #include <curses.h>
  9. #include "config.h"
  10.  
  11. void
  12. n_shell()
  13. {
  14.     WINDOW *sh_win, *newwin();
  15.     int (*istat)(), (*qstat)(), status, spid, w;
  16.     char *shell, *shellpath, *getenv(), *strrchr();
  17.     unsigned int sleep();
  18.     void _exit();
  19.                     /* a full window */
  20.     sh_win = newwin(LINES, COLS, 0, 0);
  21.  
  22.     touchwin(sh_win);
  23.     waddstr(sh_win, "Pcomm <=> Unix gateway, use ^D or 'exit' to return\n");
  24.     wrefresh(sh_win);
  25.                     /* out of curses mode */
  26.     resetterm();
  27.  
  28.     shellpath = getenv("SHELL");
  29.     if (shellpath == NULL || *shellpath == NULL)
  30.         shellpath = "/bin/sh";
  31.  
  32.     shell = strrchr(shellpath, '/') + 1;
  33.  
  34.     if (!(spid = fork())) {
  35.         signal(SIGINT, SIG_DFL);
  36.         signal(SIGQUIT, SIG_DFL);
  37. #ifdef SETUGID
  38.         setgid(getgid());
  39.         setuid(getuid());
  40. #endif /* SETUGID */
  41.         execl(shellpath, shell, "-i", (char *) 0);
  42.         _exit(1);
  43.     }
  44.     istat = signal(SIGINT, SIG_IGN);
  45.     qstat = signal(SIGQUIT, SIG_IGN);
  46.  
  47.     while ((w = wait(&status)) != spid && w != -1)
  48.         ;
  49.  
  50.     signal(SIGINT, istat);
  51.     signal(SIGQUIT, qstat);
  52.                     /* back to curses mode */
  53.     sleep(1);
  54.     fixterm();
  55.  
  56.     clearok(curscr, TRUE);
  57.     werase(sh_win);
  58.     wrefresh(sh_win);
  59.     delwin(sh_win);
  60.     return;
  61. }
  62.