32 #include <sys/types.h>
35 #include <sys/ioctl.h>
36 #if defined(__osf__) || defined(__CYGWIN__)
41 #include <tqcstring.h>
44 #include <kstandarddirs.h>
45 #include "tdesu_pty.h"
53 extern "C" int grantpt(
int fd) __THROW;
57 extern "C" char * ptsname(
int fd) __THROW;
61 extern "C" int unlockpt(
int fd) __THROW;
65 extern "C" char *_getpty(
int *,
int, mode_t,
int);
76 #elif defined(HAVE_UTIL_H)
97 #if (defined(HAVE_GETPT) || defined(HAVE_POSIX_OPENPT)) && defined(HAVE_PTSNAME)
102 #elif defined(HAVE_POSIX_OPENPT)
103 ptyfd = ::posix_openpt(O_RDWR);
108 #elif defined(HAVE_OPENPTY)
112 int master_fd, slave_fd;
113 if (openpty(&master_fd, &slave_fd, name, 0L, 0L) != -1) {
122 kdDebug(900) << k_lineinfo <<
"Opening pty failed.\n";
125 #elif defined(HAVE__GETPTY)
128 ttyname = _getpty(&master_fd,O_RDWR,0600,0);
133 kdDebug(900) << k_lineinfo <<
"Opening pty failed.error" << errno <<
'\n';
142 ptyfd = open(
"/dev/ptmx", O_RDWR);
144 ptyname =
"/dev/ptmx";
148 #elif defined (TIOCGPTN)
150 if (ioctl(ptyfd, TIOCGPTN, &ptyno) == 0) {
151 ttyname.sprintf(
"/dev/pts/%d", ptyno);
160 for (
const char *c1 =
"pqrstuvwxyzabcde"; *c1 !=
'\0'; c1++)
162 for (
const char *c2 =
"0123456789abcdef"; *c2 !=
'\0'; c2++)
164 ptyname.sprintf(
"/dev/pty%c%c", *c1, *c2);
165 ttyname.sprintf(
"/dev/tty%c%c", *c1, *c2);
166 if (access(ptyname, F_OK) < 0)
168 ptyfd = open(ptyname, O_RDWR);
177 for (
int i=0; i<256; i++)
179 ptyname.sprintf(
"/dev/ptyp%d", i);
180 ttyname.sprintf(
"/dev/ttyp%d", i);
181 if (access(ptyname, F_OK) < 0)
183 ptyfd = open(ptyname, O_RDWR);
191 kdDebug(900) << k_lineinfo <<
"Unknown system or all methods failed.\n";
206 return ::grantpt(ptyfd);
208 #elif defined(HAVE_OPENPTY)
217 if (ptyname.left(8) !=
"/dev/pty")
221 if (TDEStandardDirs::findExe(
"konsole_grantpty").isEmpty())
223 kdError(900) << k_lineinfo <<
"konsole_grantpty not found.\n";
228 const int pty_fileno = 3;
231 if ((pid = fork()) == -1)
233 kdError(900) << k_lineinfo <<
"fork(): " << perror <<
"\n";
241 waitpid(pid, &ret, 0);
242 if (WIFEXITED(ret) && !WEXITSTATUS(ret))
244 kdError(900) << k_lineinfo <<
"konsole_grantpty returned with error: "
245 << WEXITSTATUS(ret) <<
"\n";
250 if (ptyfd != pty_fileno && dup2(ptyfd, pty_fileno) < 0)
252 execlp(
"konsole_grantpty",
"konsole_grantpty",
"--grant", (
void *)0);
253 kdError(900) << k_lineinfo <<
"exec(): " << perror <<
"\n";
277 return ::unlockpt(ptyfd);
279 #elif defined(TIOCSPTLCK)
283 return ioctl(ptyfd, TIOCSPTLCK, &flag);
int unlockpt()
Unlock the slave side.
PTY()
Construct a PTY object.
int grantpt()
Grant access to the slave side.
TQCString ptsname()
Get the slave name.
~PTY()
Destructs the object.
int getpt()
Allocate a pty.