Diff for /libaitio/src/pty.c between versions 1.3 and 1.7

version 1.3, 2012/03/29 01:31:34 version 1.7, 2014/02/08 22:06:17
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012Copyright 2004 - 2014
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 47  SUCH DAMAGE. Line 47  SUCH DAMAGE.
   
   
 /*  /*
 * ioAllocPTY() Allocate new PTY and TTY * ioAllocPTY() - Allocate new PTY and TTY
  *   *
  * @ptyfd = master fd, pty   * @ptyfd = master fd, pty
  * @ttyfd = slave fd, tty   * @ttyfd = slave fd, tty
Line 57  SUCH DAMAGE. Line 57  SUCH DAMAGE.
  * @winz = winsize for terminal   * @winz = winsize for terminal
  * return: -1 error or 0 ok   * return: -1 error or 0 ok
  */   */
inline intint
 ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict name, int namesiz,   ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict name, int namesiz, 
                 struct termios * __restrict term, struct winsize * __restrict winz)                  struct termios * __restrict term, struct winsize * __restrict winz)
 {  {
         assert(ptyfd && ttyfd);          assert(ptyfd && ttyfd);
         if (!ptyfd || !ttyfd || (name && namesiz < 64)) {          if (!ptyfd || !ttyfd || (name && namesiz < 64)) {
                io_SetErr(EINVAL, "Error:: invalid arguments ...");                io_SetErr(EINVAL, "Invalid arguments");
                 return -1;                  return -1;
         }          }
   
Line 77  ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict n Line 77  ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict n
 }  }
   
 /*  /*
 * ioFreePTY() Release PTY and TTY device * ioFreePTY() - Release PTY and TTY device
  *   *
  * @ptyfd = master fd, pty (==-1 skip closing pty)   * @ptyfd = master fd, pty (==-1 skip closing pty)
  * @ttyname = tty filename   * @ttyname = tty filename
  * return: none   * return: none
  */   */
inline voidvoid
 ioFreePTY(int ptyfd, const char *ttyname)  ioFreePTY(int ptyfd, const char *ttyname)
 {  {
         assert(ttyname);          assert(ttyname);
Line 92  ioFreePTY(int ptyfd, const char *ttyname) Line 92  ioFreePTY(int ptyfd, const char *ttyname)
   
         if (ptyfd != -1)          if (ptyfd != -1)
                 close(ptyfd);                  close(ptyfd);
        if (ttyname) {        if (*ttyname) {
                 chown(ttyname, (uid_t) 0, (gid_t) 0);                  chown(ttyname, (uid_t) 0, (gid_t) 0);
                 chmod(ttyname, (mode_t) 0666);                  chmod(ttyname, (mode_t) 0666);
         }          }
 }  }
   
 /*  /*
 * ioChgWinPTY() Change window size of PTY * ioChgWinPTY() - Change window size of PTY
  *   *
  * @ptyfd = master fd, pty   * @ptyfd = master fd, pty
  * @row = row   * @row = row
Line 108  ioFreePTY(int ptyfd, const char *ttyname) Line 108  ioFreePTY(int ptyfd, const char *ttyname)
  * @ypxl = y pixels   * @ypxl = y pixels
  * return: -1 error or 0 ok   * return: -1 error or 0 ok
  */   */
inline intint
 ioChgWinPTY(int ptyfd, u_short row, u_short col, u_short xpxl, u_short ypxl)  ioChgWinPTY(int ptyfd, u_short row, u_short col, u_short xpxl, u_short ypxl)
 {  {
         struct winsize w;          struct winsize w;
Line 127  ioChgWinPTY(int ptyfd, u_short row, u_short col, u_sho Line 127  ioChgWinPTY(int ptyfd, u_short row, u_short col, u_sho
 }  }
   
 /*  /*
 * ioSetOwnerTTY() Set owner to TTY * ioSetOwnerTTY() - Set owner to TTY
  *   *
  * @ttyname = tty filename   * @ttyname = tty filename
  * @UID = uid   * @UID = uid
Line 144  ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GI Line 144  ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GI
   
         assert(ttyname);          assert(ttyname);
         if (!ttyname) {          if (!ttyname) {
                io_SetErr(EINVAL, "Error:: invalid arguments ...");                io_SetErr(EINVAL, "Invalid arguments");
                 return -1;                  return -1;
         }          }
   
Line 177  ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GI Line 177  ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GI
 }  }
   
 /*  /*
 * ioSetSidTTY() Makes the process's controlling TTY and sets it to sane modes. * ioSetSidTTY() - Makes the process's controlling TTY and sets it to sane modes.
  *   *
  * @ttyfd = slave fd, tty   * @ttyfd = slave fd, tty
  * @ttyname = tty filename   * @ttyname = tty filename
Line 201  ioSetSidTTY(int *ttyfd, const char *ttyname) Line 201  ioSetSidTTY(int *ttyfd, const char *ttyname)
         /* Verify that we are successfully disconnected from the controlling tty. */          /* Verify that we are successfully disconnected from the controlling tty. */
         fd = open(_PATH_TTY, O_RDWR | O_NOCTTY);          fd = open(_PATH_TTY, O_RDWR | O_NOCTTY);
         if (fd >= 0) {          if (fd >= 0) {
                io_SetErr(ENXIO, "Error:: Failed to disconnect from controlling tty.");                io_SetErr(ENXIO, "Failed to disconnect from controlling tty");
                 close(fd);                  close(fd);
                 return -1;                  return -1;
         }          }
Line 239  ioSetSidTTY(int *ttyfd, const char *ttyname) Line 239  ioSetSidTTY(int *ttyfd, const char *ttyname)
 }  }
   
 /*  /*
 * ioSetRAWMode() Enter into RAW mode * ioSetRAWMode() - Enter into RAW mode
  *   *
  * @fd = tty fd   * @fd = tty fd
  * @otio = saved old termios for later restore if !=NULL   * @otio = saved old termios for later restore if !=NULL
  * return: -1 error or 0 ok   * return: -1 error or 0 ok
  */   */
inline intint
 ioSetRAWMode(int fd, struct termios *otio)  ioSetRAWMode(int fd, struct termios *otio)
 {  {
         struct termios tio;          struct termios tio;
Line 279  ioSetRAWMode(int fd, struct termios *otio) Line 279  ioSetRAWMode(int fd, struct termios *otio)
 }  }
   
 /*  /*
 * ioRestoreMode() Restore termios to tty fd * ioRestoreMode() - Restore termios to tty fd
  *   *
  * @fd = tty fd   * @fd = tty fd
  * @tio = termios structure for restore   * @tio = termios structure for restore
  * return: -1 error or 0 ok   * return: -1 error or 0 ok
  */   */
inline intint
 ioRestoreMode(int fd, struct termios tio)  ioRestoreMode(int fd, struct termios tio)
 {  {
         if (tcsetattr(fd, TCSADRAIN, &tio) == -1) {          if (tcsetattr(fd, TCSADRAIN, &tio) == -1) {
Line 297  ioRestoreMode(int fd, struct termios tio) Line 297  ioRestoreMode(int fd, struct termios tio)
 }  }
   
 /*  /*
 * ioForkPTY() Fork new process with session leader and new TTY * ioForkPTY() - Fork new process with session leader and new TTY
  *   *
  * @ptyfd = master fd, pty   * @ptyfd = master fd, pty
  * @name = tty device name if not null   * @name = tty device name if not null

Removed from v.1.3  
changed lines
  Added in v.1.7


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>