CVS commit by ossi: don't use fixed fd for kgrantpty. should make FreeBSD users happy. :) M +8 -7 kgrantpty.c 1.10 [POSSIBLY UNSAFE: printf] M +2 -7 kpty.cpp 1.10 --- kdelibs/kdecore/kgrantpty.c #1.9:1.10 @@ -41,5 +41,4 @@ #endif -#define PTY_FILENO 3 /* keep in sync with kpty */ #define TTY_GROUP "tty" @@ -53,9 +52,10 @@ int main (int argc, char *argv[]) mode_t mod; char* tty; + int fd; /* check preconditions **************************************************/ - if (argc != 2 || (strcmp(argv[1],"--grant") && strcmp(argv[1],"--revoke"))) + if (argc != 3 || (strcmp(argv[1],"--grant") && strcmp(argv[1],"--revoke"))) { - printf("usage: %s (--grant|--revoke)\n" + printf("usage: %s (--grant|--revoke) \n" "%s is a helper for the KDE core libraries.\n" "It is not intended to be called from the command line.\n" @@ -86,4 +86,5 @@ int main (int argc, char *argv[]) p = getgrnam(TTY_GROUP); /* posix */ gid = p ? p->gr_gid : getgid (); /* posix */ + fd = atoi(argv[2]); /* get slave pty name from master pty file handle in PTY_FILENO *********/ @@ -111,5 +112,5 @@ int main (int argc, char *argv[]) struct stat dsb; - if (fstat(PTY_FILENO, &dsb) != -1) { + if (fstat(fd, &dsb) != -1) { if ((dp = opendir(_PATH_DEV)) != NULL) { while ((dirp = readdir(dp))) { @@ -132,6 +133,6 @@ int main (int argc, char *argv[]) } #else - /* Check that PTY_FILENO is a valid master pseudo terminal. */ - pty = ttyname(PTY_FILENO); /* posix */ + /* Check that fd is a valid master pseudo terminal. */ + pty = ttyname(fd); /* posix */ #endif @@ -141,5 +142,5 @@ int main (int argc, char *argv[]) return 1; /* FAIL */ } - close(PTY_FILENO); + close(fd); /* matches /dev/pty?? */ --- kdelibs/kdecore/kpty.cpp #1.9:1.10 @@ -157,5 +157,4 @@ public: }; -#define PTY_FILENO 3 #define BASE_CHOWN "kgrantpty" @@ -502,11 +501,7 @@ bool KPty::chownpty(bool grant) if (pid == 0) { - /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */ - if (d->masterFd != PTY_FILENO && - dup2(d->masterFd , PTY_FILENO) < 0) - exit(1); QString path = locate("exe", BASE_CHOWN); - execle(path.ascii(), BASE_CHOWN, grant?"--grant":"--revoke", (void *)0, - NULL); + execle(path.ascii(), BASE_CHOWN, grant?"--grant":"--revoke", + QString::number(d->masterFd).ascii(), (void *)0, (void *)0); exit(1); // should not be reached }