diff options
Diffstat (limited to 'tdecore/kpty.cpp')
| -rw-r--r-- | tdecore/kpty.cpp | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/tdecore/kpty.cpp b/tdecore/kpty.cpp index 1e5806133..d801b7c9a 100644 --- a/tdecore/kpty.cpp +++ b/tdecore/kpty.cpp @@ -24,17 +24,12 @@ #include <config.h> #include "kpty.h" -#include "kprocess.h" +#include "tdeprocess.h" #ifdef __sgi #define __svr4__ #endif -#ifdef __osf__ -#define _OSF_SOURCE -#include <float.h> -#endif - #ifdef _AIX #define _ALL_SOURCE #endif @@ -91,11 +86,9 @@ extern "C" { } #endif -#if !defined(__osf__) -# ifdef HAVE_TERMIO_H +#ifdef HAVE_TERMIO_H /* needed at least on AIX */ -# include <termio.h> -# endif +# include <termio.h> #endif #if defined(HAVE_TCGETATTR) @@ -128,7 +121,7 @@ extern "C" { #endif #include <kdebug.h> -#include <kstandarddirs.h> // locate +#include <tdestandarddirs.h> // locate #ifndef CINTR #define CINTR 0x03 @@ -217,49 +210,60 @@ bool KPty::setPty(int pty_master) bool KPty::_attachPty(int pty_master) { - TQCString ptyName; + if (d->slaveFd < 0 ) { kdDebug(175) << "KPty::_attachPty(): " << pty_master << endl; -#if defined(HAVE_PTSNAME) && defined(HAVE_GRANTPT) +#if defined(HAVE_PTSNAME) char *ptsn = ptsname(d->masterFd); if (ptsn) { - grantpt(d->masterFd); d->ttyName = ptsn; } else { ::close(d->masterFd); d->masterFd = -1; + return false; } #endif - struct stat st; - if (stat(d->ttyName.data(), &st)) - return false; // this just cannot happen ... *cough* Yeah right, I just - // had it happen when pty #349 was allocated. I guess - // there was some sort of leak? I only had a few open. - if (((st.st_uid != getuid()) || - (st.st_mode & (S_IRGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH))) && - !chownpty(true)) - { - kdWarning(175) - << "KPty::_attachPty(): " << "chownpty failed for device " << ptyName << "::" << d->ttyName << endl - << "KPty::_attachPty(): " << "This means the communication can be eavesdropped." << endl; - } +#if defined(HAVE_GRANTPT) + if (grantpt(d->masterFd)) { + return false; + } +#else + struct stat st; + if (stat(d->ttyName.data(), &st)) + return false; // this just cannot happen ... *cough* Yeah right, I just + // had it happen when pty #349 was allocated. I guess + // there was some sort of leak? I only had a few open. + if (((st.st_uid != getuid()) || + (st.st_mode & (S_IRGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH))) && + !chownpty(true)) + { + kdWarning(175) + << "KPty::_attachPty(): " << "chownpty failed for device " << d->ttyName << endl + << "KPty::_attachPty(): " << "This means the communication can be eavesdropped." << endl; + } +#endif #ifdef BSD - revoke(d->ttyName.data()); + revoke(d->ttyName.data()); #endif #ifdef HAVE_UNLOCKPT - unlockpt(d->masterFd); + unlockpt(d->masterFd); #endif - d->slaveFd = ::open(d->ttyName.data(), O_RDWR | O_NOCTTY); - if (d->slaveFd < 0) - { - kdWarning(175) << "KPty::_attachPty(): " << "Can't open slave pseudo teletype" << endl; - ::close(d->masterFd); - d->masterFd = -1; - return false; + d->slaveFd = ::open(d->ttyName.data(), O_RDWR | O_NOCTTY); + if (d->slaveFd < 0) + { + kdWarning(175) << "KPty::_attachPty(): " << "Can't open slave pseudo teletype" << endl; + ::close(d->masterFd); + d->masterFd = -1; + return false; + } +#ifdef HAVE_OPENPTY + // set screen size + ioctl(d->slaveFd, TIOCSWINSZ, (char *)&d->winSize); +#endif } #if (defined(__svr4__) || defined(__sgi__)) @@ -294,8 +298,10 @@ bool KPty::_attachPty(int pty_master) _tcsetattr(d->slaveFd, &ttmode); +#ifndef HAVE_OPENPTY // set screen size ioctl(d->slaveFd, TIOCSWINSZ, (char *)&d->winSize); +#endif fcntl(d->masterFd, F_SETFD, FD_CLOEXEC); fcntl(d->slaveFd, F_SETFD, FD_CLOEXEC); @@ -308,7 +314,7 @@ bool KPty::open() if (d->masterFd >= 0) return true; -#if defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(HAVE_OPENPTY) char cpty[16]; if (openpty(&d->masterFd, &d->slaveFd, cpty, NULL, &d->winSize) == 0) { @@ -329,7 +335,11 @@ bool KPty::open() // We try, as we know them, one by one. #if defined(HAVE_PTSNAME) && defined(HAVE_GRANTPT) -#ifdef _AIX +#if defined(HAVE_GETPT) + d->masterFd = ::getpt(); +#elif defined(HAVE_POSIX_OPENPT) + d->masterFd = ::posix_openpt(O_RDWR); +#elif defined(_AIX) d->masterFd = ::open("/dev/ptc",O_RDWR); #else d->masterFd = ::open("/dev/ptmx",O_RDWR); |
