Annotation of ports/net/xl2tpd/patches/patch-pty_c, Revision 1.1
1.1 ! yason 1: --- pty.c.orig Mon Mar 9 02:25:30 2009
! 2: +++ pty.c Mon May 25 11:01:46 2009
! 3: @@ -25,6 +25,8 @@
! 4: #include <errno.h>
! 5: #include <stdio.h>
! 6: #include <fcntl.h>
! 7: +#include <termios.h>
! 8: +#include <util.h>
! 9: #include "l2tp.h"
! 10:
! 11:
! 12: @@ -47,77 +49,6 @@
! 13: #define PTY01 "0123456789abcdefghijklmnopqrstuv"
! 14: #endif
! 15:
! 16: -#ifndef OPENBSD
! 17: -int getPtyMaster_pty (char *tty10, char *tty01)
! 18: -{
! 19: - char *p10;
! 20: - char *p01;
! 21: - static char dev[] = PTY00;
! 22: - int fd;
! 23: -
! 24: - for (p10 = PTY10; *p10; p10++)
! 25: - {
! 26: - dev[8] = *p10;
! 27: - for (p01 = PTY01; *p01; p01++)
! 28: - {
! 29: - dev[9] = *p01;
! 30: - fd = open (dev, O_RDWR | O_NONBLOCK);
! 31: - if (fd >= 0)
! 32: - {
! 33: - *tty10 = *p10;
! 34: - *tty01 = *p01;
! 35: - return fd;
! 36: - }
! 37: - }
! 38: - }
! 39: - l2tp_log (LOG_CRIT, "%s: No more free pseudo-tty's\n", __FUNCTION__);
! 40: - return -1;
! 41: -}
! 42: -
! 43: -int getPtyMaster_ptmx(char *ttybuf, int ttybuflen)
! 44: -{
! 45: - int fd;
! 46: - char *tty;
! 47: -
! 48: - fd = open("/dev/ptmx", O_RDWR);
! 49: - if (fd == -1)
! 50: - {
! 51: - l2tp_log (LOG_WARNING, "%s: unable to open /dev/ptmx to allocate pty\n",
! 52: - __FUNCTION__);
! 53: - return -EINVAL;
! 54: - }
! 55: -
! 56: - /* change the onwership */
! 57: - if (grantpt(fd))
! 58: - {
! 59: - l2tp_log (LOG_WARNING, "%s: unable to grantpt() on pty\n",
! 60: - __FUNCTION__);
! 61: - close(fd);
! 62: - return -EINVAL;
! 63: - }
! 64: -
! 65: - if (unlockpt(fd))
! 66: - {
! 67: - l2tp_log (LOG_WARNING, "%s: unable to unlockpt() on pty\n",
! 68: - __FUNCTION__);
! 69: - close(fd);
! 70: - return -EINVAL;
! 71: - }
! 72: -
! 73: - tty = ptsname(fd);
! 74: - if (tty == NULL)
! 75: - {
! 76: - l2tp_log (LOG_WARNING, "%s: unable to obtain name of slave tty\n",
! 77: - __FUNCTION__);
! 78: - close(fd);
! 79: - return -EINVAL;
! 80: - }
! 81: - ttybuf[0]='\0';
! 82: - strncat(ttybuf, tty, ttybuflen);
! 83: -
! 84: - return fd;
! 85: -}
! 86: -#ifdef OPENBSD
! 87: int getPtyMaster_ptm(char *ttybuf, int ttybuflen)
! 88: {
! 89: int amaster, aslave;
! 90: @@ -138,36 +69,14 @@ int getPtyMaster_ptm(char *ttybuf, int ttybuflen)
! 91:
! 92: return amaster;
! 93: }
! 94: -#endif /* OPENBSD */
! 95:
! 96: int getPtyMaster(char *ttybuf, int ttybuflen)
! 97: {
! 98: int fd;
! 99: -#ifndef OPENBSD
! 100: - fd = getPtyMaster_ptmx(ttybuf, ttybuflen);
! 101: - char a, b;
! 102: -
! 103: - if(fd >= 0) {
! 104: - return fd;
! 105: - }
! 106: -
! 107: - l2tp_log (LOG_WARNING, "%s: failed to use pts -- using legacy ptys\n", __FUNCTION__);
! 108: - fd = getPtyMaster_pty(&a,&b);
! 109: -
! 110: - if(fd >= 0) {
! 111: - snprintf(ttybuf, ttybuflen, "/dev/tty%c%c", a, b);
! 112: - return fd;
! 113: - }
! 114: -#endif
! 115: -#ifdef OPENBSD
! 116: -
! 117: fd = getPtyMaster_ptm(ttybuf, ttybuflen);
! 118: if(fd >= 0) {
! 119: return fd;
! 120: }
! 121: -#endif /* OPENBSD */
! 122:
! 123: return -EINVAL;
! 124: }
! 125: -
! 126: -#endif
CVSweb