source: trunk/patches/ptmx.patch @ 5

Last change on this file since 5 was 5, checked in by bas, 17 years ago

First import for the OSS torque_2_deb project

File size: 1.8 KB
  • src/resmom/linux/mom_start.c

    old new  
    7878*/
    7979#include <pbs_config.h>   /* the master config generated by configure */
    8080
     81#include <stdlib.h> /* for unix98 pty api in open_master */
    8182#include <string.h>
    8283#include <unistd.h>
    8384#include <pwd.h>
     
    356357 * piece of code depends on multiplexor /dev/ptc
    357358 */
    358359
    359 #define PTY_SIZE 12
    360360
    361361int open_master(
    362362
    363363  char **rtn_name)      /* RETURN name of slave pts */
    364364
    365365  {
    366   char         *pc1;
    367   char         *pc2;
    368366  int           ptc;    /* master file descriptor */
    369   static char   ptcchar1[] = "pqrs";
    370   static char   ptcchar2[] = "0123456789abcdef";
    371   static char   pty_name[PTY_SIZE+1];   /* "/dev/[pt]tyXY" */
    372367
    373   strncpy(pty_name, "/dev/ptyXY", PTY_SIZE);
    374 
    375   for (pc1 = ptcchar1;*pc1 != '\0';++pc1)
     368  if ((ptc = open("/dev/ptmx",O_RDWR|O_NOCTTY)) >= 0)
    376369    {
    377     pty_name[8] = *pc1;
    378 
    379     for (pc2 = ptcchar2;*pc2 != '\0';++pc2)
    380       {
    381       pty_name[9] = *pc2;
    382 
    383       if ((ptc = open(pty_name,O_RDWR|O_NOCTTY,0)) >= 0)
    384         {
    385         /* got a master, fix name to matching slave */
    386 
    387         pty_name[5] = 't';     
    388 
    389         *rtn_name = pty_name;
    390 
     370    /* got a master, fix name to matching slave */
     371       if (grantpt(ptc)<0 || unlockpt(ptc)<0)
     372         {
     373           close(ptc);
     374           return(-1);
     375         }
     376       *rtn_name = (char *) ptsname(ptc); /* never to be freed */
     377       if (*rtn_name == NULL)
     378          {
     379            close(ptc);
     380            return(-1);
     381          }
    391382        return(ptc);
    392         }
    393       else if (errno == ENOENT)
    394         {
    395         return(-1);     /* tried all entries, give up */
    396         }
    397       }
    398     }
    399 
    400   return(-1);   /* tried all entries, give up */
     383     }
     384  return(-1);   /* give up */
    401385  }  /* END open_master() */
    402386
Note: See TracBrowser for help on using the repository browser.