UnixOperatingSystem.st
changeset 3538 fcedde036bc3
parent 3536 adad0d12c9a8
child 3539 1655aae9d622
equal deleted inserted replaced
3537:916534e86f0c 3538:fcedde036bc3
  5578      See ExternalStream>>makePipe for a more user-friendly, public interface."
  5578      See ExternalStream>>makePipe for a more user-friendly, public interface."
  5579 
  5579 
  5580     |fdS fdM|    
  5580     |fdS fdM|    
  5581                 
  5581                 
  5582 %{       
  5582 %{       
       
  5583     /*
       
  5584      * Find a pseudo tty to use and open both sides.
       
  5585      *  _fdM receives the master file descriptor while _fdS
       
  5586      *  receives the slave.  The master is opened with O_NDELAY as commonly
       
  5587      *  needed in daemons such as rlogind and telnetd.
       
  5588      */
       
  5589 
  5583 #ifdef IRIX5
  5590 #ifdef IRIX5
  5584     int _fdM, _fdS;
  5591     int _fdM, _fdS;
  5585     char *line;
  5592     char *line;
  5586 
  5593 
  5587     /*
       
  5588      * Find a pseudo tty to use and open both sides.
       
  5589      *  filedes[0] receives the master file descriptor while filedes[1]
       
  5590      *  receives the slave.  The master is opened with O_NDELAY as commonly
       
  5591      *  needed in daemons such as rlogind and telnetd.
       
  5592      */
       
  5593 
       
  5594     line = _getpty(&_fdM, O_RDWR|O_NDELAY, 0600, 0);
  5594     line = _getpty(&_fdM, O_RDWR|O_NDELAY, 0600, 0);
  5595     if ((line != 0) && (_fdM >= 0)) {
  5595     if ((line != 0) && (_fdM >= 0)) {
  5596         printf("opening slave side %s\n", line);
       
  5597         _fdS = open(line, O_RDWR);
  5596         _fdS = open(line, O_RDWR);
  5598         if (_fdS < 0) {
  5597         if (_fdS < 0) {
  5599             (void)close(_fdM);
  5598             (void)close(_fdM);
  5600             _fdS = _fdM = -1;
  5599             _fdS = _fdM = -1;
  5601         }
  5600         }
  5604     }
  5603     }
  5605     if ((_fdM >= 0) && (_fdS >= 0)) {
  5604     if ((_fdM >= 0) && (_fdS >= 0)) {
  5606          fdM = __MKSMALLINT(_fdM);
  5605          fdM = __MKSMALLINT(_fdM);
  5607          fdS = __MKSMALLINT(_fdS);
  5606          fdS = __MKSMALLINT(_fdS);
  5608     }
  5607     }
  5609 #endif
  5608 #endif /* IRIX5 */
       
  5609 
       
  5610 
       
  5611 #ifdef LINUX
       
  5612 #   define PTY_TEMPL    "/dev/ptyXX"
       
  5613 #   define PTY_1_CHARS  "abcdepqrstuvwxyz"
       
  5614 #   define PTY_2_CHARS  "0123456789abcdef"
       
  5615 #endif /* LINUX */
       
  5616 
       
  5617 #ifdef solaris
       
  5618 #   define PTY_TEMPL    "/dev/ptyXX"
       
  5619 #   define PTY_1_CHARS  "pqr"
       
  5620 #   define PTY_2_CHARS  "0123456789abcdef"
       
  5621 #endif /* LINUX */
       
  5622 
       
  5623 #ifdef aix
       
  5624 #   define PTY_TEMPL    "/dev/ptyXX"
       
  5625 #   define PTY_1_CHARS  "pqr"
       
  5626 #   define PTY_2_CHARS  "0123456789abcdef"
       
  5627 #endif /* LINUX */
       
  5628 
       
  5629 #ifdef next3
       
  5630 #   define PTY_TEMPL    "/dev/ptyXX"
       
  5631 #   define PTY_1_CHARS  "pqr"
       
  5632 #   define PTY_2_CHARS  "0123456789abcdef"
       
  5633 #endif /* LINUX */
       
  5634 
       
  5635 #ifdef hpux
       
  5636 #   define PTY_TEMPL    "/dev/ptyXX"
       
  5637 #   define PTY_1_CHARS  "pqrs"
       
  5638 #   define PTY_2_CHARS  "0123456789abcdef"
       
  5639 #endif /* LINUX */
       
  5640 
       
  5641 
       
  5642 #ifdef PTY_TEMPL
       
  5643 #include <grp.h>
       
  5644     static char line[] = PTY_TEMPL;
       
  5645 
       
  5646     register const char *cp1, *cp2;
       
  5647     int _fdM = -1, _fdS = -1, ttygid;
       
  5648     struct group *gr;
       
  5649 
       
  5650     if ((gr = getgrnam("tty")) != NULL)
       
  5651         ttygid = gr->gr_gid;
       
  5652     else
       
  5653         ttygid = -1;
       
  5654 
       
  5655     for (cp1 = PTY_1_CHARS; *cp1; cp1++) {
       
  5656         line[sizeof(line)-1-2] = * cp1;
       
  5657 
       
  5658         for( cp2 = PTY_2_CHARS; *cp2; cp2++ ) {
       
  5659             line[5] = 'p';
       
  5660             line[sizeof(line)-1-1] = *cp2;
       
  5661 
       
  5662             if ((_fdM = open(line, O_RDWR, 0)) == -1) {
       
  5663                 if (errno == ENOENT) {
       
  5664                     _fdM = _fdS = -1;
       
  5665                     goto getOutOfHere; /* out of ptys */
       
  5666                 }
       
  5667             } else {
       
  5668                 line[5] = 't';
       
  5669                 (void) chown( line, getuid(), ttygid );
       
  5670                 (void) chmod( line, S_IRUSR|S_IWUSR|S_IWGRP );
       
  5671 
       
  5672                 if( (_fdS = open(line, O_RDWR, 0)) != -1 ) {
       
  5673                     goto getOutOfHere;
       
  5674                 }
       
  5675                 (void) close( _fdM );
       
  5676             }
       
  5677         }
       
  5678     }
       
  5679   getOutOfHere: ;
       
  5680 
       
  5681     if ((_fdM >= 0) && (_fdS >= 0)) {
       
  5682          fdM = __MKSMALLINT(_fdM);
       
  5683          fdS = __MKSMALLINT(_fdS);
       
  5684     }
       
  5685 
       
  5686 #endif /* PTY_TEMPL */
  5610 %}.
  5687 %}.
       
  5688 
  5611     fdM notNil ifTrue:[
  5689     fdM notNil ifTrue:[
  5612         ^ Array with:fdM with:fdS.
  5690         ^ Array with:fdM with:fdS.
  5613     ].
  5691     ].
       
  5692 
  5614     ^ nil
  5693     ^ nil
  5615 !
  5694 !
  5616 
  5695 
  5617 makePipe
  5696 makePipe
  5618     "make a pipe, return array with two filedescriptors on success,
  5697     "make a pipe, return array with two filedescriptors on success,
  8148 ! !
  8227 ! !
  8149 
  8228 
  8150 !UnixOperatingSystem class methodsFor:'documentation'!
  8229 !UnixOperatingSystem class methodsFor:'documentation'!
  8151 
  8230 
  8152 version
  8231 version
  8153     ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.7 1998-06-09 13:51:38 cg Exp $'
  8232     ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.8 1998-06-09 17:18:57 cg Exp $'
  8154 ! !
  8233 ! !
  8155 UnixOperatingSystem initialize!
  8234 UnixOperatingSystem initialize!