home *** CD-ROM | disk | FTP | other *** search
- /*
- * Spawn a 'native' shell. 'Native' means the shell found in the SHELL
- * environmental variable.
- */
-
- #include <stdio.h>
- #include <signal.h>
- #include <curses.h>
-
- void
- native_shell()
- {
- WINDOW *sh_win, *newwin();
- int (*istat)(), (*qstat)(), status, pid, w;
- char *shell, *shellpath, *getenv(), *strrchr();
- unsigned int sleep();
- void _exit();
- /* a full window */
- sh_win = newwin(LINES, COLS, 0, 0);
-
- clear_absolute(sh_win);
- waddstr(sh_win, "Pcomm <=> Unix gateway, use ^D or 'exit' to return\n");
- wrefresh(sh_win);
- /* out of curses mode */
- resetterm();
-
- shellpath = getenv("SHELL");
- if (shellpath == NULL || *shellpath == NULL)
- shellpath = "/bin/sh";
-
- shell = strrchr(shellpath, '/') + 1;
-
- if (!(pid = fork())) {
- #ifdef SGID
- setgid(getgid());
- #endif /* SGID */
- execl(shellpath, shell, "-i", 0);
- _exit(1);
- }
- istat = signal(SIGINT, SIG_IGN);
- qstat = signal(SIGQUIT, SIG_IGN);
-
- while ((w = wait(&status)) != pid && w != -1)
- ;
-
- signal(SIGINT, istat);
- signal(SIGQUIT, qstat);
- /* back to curses mode */
- fixterm();
- sleep(1);
-
- clear_absolute(stdscr);
- delwin(sh_win);
- return;
- }
-
- /*
- * Clear the screen absolutely! It's incrediblely hard to get curses() to
- * clear the screen when it thinks its already clear.
- */
-
- int
- clear_absolute(win)
- WINDOW *win;
- {
- clearok(curscr, 1);
- wrefresh(win);
- clearok(curscr, 0);
- return(0);
- }
-