src/unixfork.c
/* Creates a PTY connection to a shell */
Creates a PTY connection to a shell
Creates a PTY connection to a shell
static int ForkUnixShell(int slot, char *PtySlave, char *termtype, char *shellarg)
{
  int PID, SlaveFD;
  struct termios tio;
  char *argvec[4] = {NULL, NULL, NULL, NULL};
  char *shell = NULL;
  char *userShell = NULL;
  PID = fork();
  if (PID != 0) {
    if (shellarg != shcom) free(shellarg);
    return (PID);
  }
  if (0 > setsid()) 
    perror("setsid");
  SlaveFD = open(PtySlave, O_RDWR);
  if (SlaveFD == -1) {
    perror("Slave Open");
    perror(PtySlave);
    exit(0);
  }
#ifdef OS5
  ioctl(SlaveFD, I_PUSH, "ptem");
  ioctl(SlaveFD, I_PUSH, "ldterm");
#endif 
  tcgetattr(SlaveFD, &tio);
  tio.c_lflag |= ICANON | ECHO | ECHOE | ECHOCTL | ECHOKE;
  tcsetattr(SlaveFD, TCSANOW, &tio);
  (void)dup2(SlaveFD, 0);
  (void)dup2(SlaveFD, 1);
  (void)dup2(SlaveFD, 2);
  (void)close(SlaveFD);
  setenv("LDESHELL", "YES", 1);
  if (termtype[0] != 0) { 
    setenv("TERM", termtype, 1);
  }
  shell = getenv("SHELL");
  for (userShell = getusershell(); userShell != NULL && strcmp(shell, userShell) != 0; userShell = getusershell());
  if (userShell == NULL) {
    perror("$(SHELL) not found in /etc/shells");
    exit(0);
  }
  argvec[0] = strrchr(userShell, '/') + 1;
  if (shellarg[0] != 0) { 
    argvec[1] = "-c";     
    argvec[2] = shellarg;
  }
  execv(userShell, argvec);
  perror("execv");
  exit(0);
}
static int ForkUnixShell ( int slot , char * PtySlave , char * termtype , char * shellarg ) { int PID , SlaveFD ; struct termios tio ; char * argvec [ 4 ] = { NULL , NULL , NULL , NULL } ; char * shell = NULL ; char * userShell = NULL ; PID = fork ( ) ; if ( PID != 0 ) { if ( shellarg != shcom ) free ( shellarg ) ; return ( PID ) ; } if ( 0 > setsid ( ) ) perror ( " " ) ; SlaveFD = open ( PtySlave , O_RDWR ) ; if ( SlaveFD == -1 ) { perror ( " " ) ; perror ( PtySlave ) ; exit ( 0 ) ; } #ifdef OS5 ioctl ( SlaveFD , I_PUSH , " " ) ; ioctl ( SlaveFD , I_PUSH , " " ) ; #endif tcgetattr ( SlaveFD , & tio ) ; tio . c_lflag |= ICANON | ECHO | ECHOE | ECHOCTL | ECHOKE ; tcsetattr ( SlaveFD , TCSANOW , & tio ) ; ( void ) dup2 ( SlaveFD , 0 ) ; ( void ) dup2 ( SlaveFD , 1 ) ; ( void ) dup2 ( SlaveFD , 2 ) ; ( void ) close ( SlaveFD ) ; setenv ( " " , " " , 1 ) ; if ( termtype [ 0 ] != 0 ) { setenv ( " " , termtype , 1 ) ; } shell = getenv ( " " ) ; for ( userShell = getusershell ( ) ; userShell != NULL && strcmp ( shell , userShell ) != 0 ; userShell = getusershell ( ) ) ; if ( userShell == NULL ) { perror ( " " ) ; exit ( 0 ) ; } argvec [ 0 ] = strrchr ( userShell , ' ' ) + 1 ; if ( shellarg [ 0 ] != 0 ) { argvec [ 1 ] = " " ; argvec [ 2 ] = shellarg ; } execv ( userShell , argvec ) ; perror ( " " ) ; exit ( 0 ) ; }
Creates a PTY connection to a shell
Creates a PTY connection to a shell
/* create us a new session for tty purposes */ /* Open the slave side */ /* OS5 */ /* Set up as basic display terminal: canonical erase,
     kill processing, echo, backspace to erase, echo ctrl
     chars as ^x, kill line by backspacing */ /* set the LDESHELL variable so the underlying shell initialization can see it and
     configure the shell appropriately, though this may not be so important any more */ /* set the TERM environment var */ /* Start up shell -- use SHELL environment variable as long as it's in /etc/shells */ /* argvec entries initialized to NULL */ /* setup to run command */ /* read commands from next arg */ /* Should never get here */