mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kpty: use ptsname_r() if available, assume ptsname() is available
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
ac0a81cd61
commit
e529267d21
4 changed files with 22 additions and 33 deletions
|
@ -150,7 +150,7 @@ if (UNIX)
|
|||
check_function_exists(posix_openpt HAVE_POSIX_OPENPT)
|
||||
endif (openpty_in_libc OR openpty_in_libutil)
|
||||
|
||||
check_function_exists(ptsname HAVE_PTSNAME)
|
||||
check_function_exists(ptsname_r HAVE_PTSNAME_R)
|
||||
check_function_exists(tcgetattr HAVE_TCGETATTR)
|
||||
check_function_exists(tcsetattr HAVE_TCSETATTR)
|
||||
endif (UNIX)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#cmakedefine HAVE_POSIX_OPENPT 1
|
||||
#cmakedefine HAVE_GRANTPT 1
|
||||
#cmakedefine HAVE_OPENPTY 1
|
||||
#cmakedefine HAVE_PTSNAME 1
|
||||
#cmakedefine HAVE_PTSNAME_R 1
|
||||
#cmakedefine HAVE_REVOKE 1
|
||||
#cmakedefine HAVE_UNLOCKPT 1
|
||||
#cmakedefine HAVE_TCGETATTR
|
||||
|
|
|
@ -69,10 +69,9 @@ int main (int argc, char *argv[])
|
|||
gid_t gid;
|
||||
uid_t uid;
|
||||
mode_t mod;
|
||||
char* tty;
|
||||
char* tty = 0;
|
||||
int fd;
|
||||
#if !defined(HAVE_PTSNAME) && defined(TIOCGPTN)
|
||||
int ptyno;
|
||||
#if defined(HAVE_PTSNAME_R)
|
||||
char ttyb[32];
|
||||
#endif
|
||||
|
||||
|
@ -96,14 +95,14 @@ int main (int argc, char *argv[])
|
|||
fd = atoi(argv[2]);
|
||||
|
||||
/* get slave pty name from master pty file handle *********/
|
||||
#ifdef HAVE_PTSNAME
|
||||
#ifdef HAVE_PTSNAME_R
|
||||
::memset(ttyb, '\0', sizeof(ttyb) * sizeof(char));
|
||||
if (ptsname_r(fd, ttyb, sizeof(ttyb)) == 0) {
|
||||
tty = ttyb;
|
||||
if (!tty)
|
||||
#else
|
||||
tty = ptsname(fd);
|
||||
if (!tty)
|
||||
#elif defined(TIOCGPTN)
|
||||
if (!ioctl(fd, TIOCGPTN, &ptyno)) {
|
||||
sprintf(ttyb, "/dev/pts/%d", ptyno);
|
||||
tty = ttyb;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* Check that fd is a valid master pseudo terminal. */
|
||||
|
|
|
@ -190,8 +190,6 @@ bool KPty::open()
|
|||
|
||||
#else
|
||||
|
||||
#if defined(HAVE_PTSNAME) || defined(TIOCGPTN)
|
||||
|
||||
#ifdef HAVE_POSIX_OPENPT
|
||||
d->masterFd = ::posix_openpt(O_RDWR|O_NOCTTY);
|
||||
#elif defined(PTM_DEVICE)
|
||||
|
@ -201,16 +199,15 @@ bool KPty::open()
|
|||
#endif
|
||||
if (d->masterFd >= 0)
|
||||
{
|
||||
#ifdef HAVE_PTSNAME
|
||||
#ifdef HAVE_PTSNAME_R
|
||||
char ptsn[32];
|
||||
::memset(ptsn, '\0', sizeof(ptsn) * sizeof(char));
|
||||
if (ptsname_r(fd, ptsn, sizeof(ptsn)) == 0) {
|
||||
d->ttyName = ptsn;
|
||||
#else
|
||||
char *ptsn = ptsname(d->masterFd);
|
||||
if (ptsn) {
|
||||
d->ttyName = ptsn;
|
||||
#else
|
||||
int ptyno;
|
||||
if (!ioctl(d->masterFd, TIOCGPTN, &ptyno)) {
|
||||
char buf[32];
|
||||
sprintf(buf, "/dev/pts/%d", ptyno);
|
||||
d->ttyName = buf;
|
||||
#endif
|
||||
#ifdef HAVE_GRANTPT
|
||||
if (!grantpt(d->masterFd))
|
||||
|
@ -222,7 +219,6 @@ bool KPty::open()
|
|||
::close(d->masterFd);
|
||||
d->masterFd = -1;
|
||||
}
|
||||
#endif // HAVE_PTSNAME || TIOCGPTN
|
||||
|
||||
// Linux device names, FIXME: Trouble on other systems?
|
||||
for (const char* s3 = "pqrstuvwxyzabcde"; *s3; s3++)
|
||||
|
@ -332,10 +328,6 @@ bool KPty::open()
|
|||
|
||||
bool KPty::open(int fd)
|
||||
{
|
||||
#if !defined(HAVE_PTSNAME) && !defined(TIOCGPTN)
|
||||
kWarning(175) << "Unsupported attempt to open pty with fd" << fd;
|
||||
return false;
|
||||
#else
|
||||
Q_D(KPty);
|
||||
|
||||
if (d->masterFd >= 0) {
|
||||
|
@ -345,16 +337,15 @@ bool KPty::open(int fd)
|
|||
|
||||
d->ownMaster = false;
|
||||
|
||||
# ifdef HAVE_PTSNAME
|
||||
# ifdef HAVE_PTSNAME_R
|
||||
char ptsn[32];
|
||||
::memset(ptsn, '\0', sizeof(ptsn) * sizeof(char));
|
||||
if (ptsname_r(fd, ptsn, sizeof(ptsn)) == 0) {
|
||||
d->ttyName = ptsn;
|
||||
# else
|
||||
char *ptsn = ptsname(fd);
|
||||
if (ptsn) {
|
||||
d->ttyName = ptsn;
|
||||
# else
|
||||
int ptyno;
|
||||
if (!ioctl(fd, TIOCGPTN, &ptyno)) {
|
||||
char buf[32];
|
||||
sprintf(buf, "/dev/pts/%d", ptyno);
|
||||
d->ttyName = buf;
|
||||
# endif
|
||||
} else {
|
||||
kWarning(175) << "Failed to determine pty slave device for fd" << fd;
|
||||
|
@ -368,7 +359,6 @@ bool KPty::open(int fd)
|
|||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void KPty::closeSlave()
|
||||
|
|
Loading…
Add table
Reference in a new issue