From owner-freebsd-test@FreeBSD.ORG Sun Aug 24 15:22:16 2003 Return-Path: Delivered-To: freebsd-test@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1B6B316A4BF for ; Sun, 24 Aug 2003 15:22:16 -0700 (PDT) Received: from meitner.wh.uni-dortmund.de (meitner.wh.Uni-Dortmund.DE [129.217.129.133]) by mx1.FreeBSD.org (Postfix) with ESMTP id F3B9B43F85 for ; Sun, 24 Aug 2003 15:22:14 -0700 (PDT) (envelope-from michaelnottebrock@gmx.net) Received: from lofi.dyndns.org (pc2-105.intern.meitner [10.3.12.105]) by meitner.wh.uni-dortmund.de (Postfix) with ESMTP id DA24E167677 for ; Mon, 25 Aug 2003 00:22:13 +0200 (CEST) Received: from kiste.my.domain (kiste.my.domain [192.168.8.4]) (authenticated bits=0) by lofi.dyndns.org (8.12.9/8.12.9) with ESMTP id h7OMMCq8037442 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Mon, 25 Aug 2003 00:22:13 +0200 (CEST) (envelope-from michaelnottebrock@gmx.net) From: Michael Nottebrock Organization: FreeBSD To: freebsd-test@freebsd.org Date: Mon, 25 Aug 2003 00:22:08 +0200 User-Agent: KMail/1.5.3 MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Boundary-03=_UqTS/zMruhwbgiL"; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <200308250022.12524.michaelnottebrock@gmx.net> X-Virus-Scanned: by amavisd-new Subject: Test X-BeenThere: freebsd-test@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: lofi@freebsd.org List-Id: Test posting area List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Aug 2003 22:22:16 -0000 --Boundary-03=_UqTS/zMruhwbgiL Content-Type: multipart/mixed; boundary="Boundary-01=_QqTS/t5CR7iqyeX" Content-Transfer-Encoding: 7bit Content-Description: signed data Content-Disposition: inline --Boundary-01=_QqTS/t5CR7iqyeX Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Description: body text Content-Disposition: inline =2D-=20 ,_, | Michael Nottebrock | lofi@freebsd.org (/^ ^\) | FreeBSD - The Power to Serve | http://www.freebsd.org \u/ | K Desktop Environment on FreeBSD | http://freebsd.kde.org --Boundary-01=_QqTS/t5CR7iqyeX Content-Type: text/x-diff; charset="us-ascii"; name="konsole.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="konsole.diff" Index: TEPty.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdebase/konsole/konsole/TEPty.cpp,v retrieving revision 1.75 diff -u -3 -p -r1.75 TEPty.cpp =2D-- TEPty.cpp 22 Nov 2002 13:17:57 -0000 1.75 +++ TEPty.cpp 24 Aug 2003 21:44:00 -0000 @@ -65,6 +65,9 @@ #include #endif =20 +// Get the Q_OS_* defines +#include + #ifdef __sgi #define __svr4__ #endif @@ -88,6 +91,10 @@ #include #endif =20 +#ifdef Q_OS_FREEBSD +#include +#endif + #include #include =20 @@ -198,9 +205,30 @@ public: =20 FILE* syslog_file =3D NULL; //stdout; =20 =2D#define PTY_FILENO 3 +#define DEFAULT_PTY_FILENO 3 +int PTY_FILENO =3D -1; // None allocated yet. + #define BASE_CHOWN "konsole_grantpty" =20 +void TEPtyInit() +{ +/* +** FreeBSD can't dup2(fd,3) because fd 3 is already in use by +** some weird pipe. So instead, we get a new throwaway fd +** that's not in use by anyone. +*/ +#ifdef Q_OS_FREEBSD + PTY_FILENO =3D open("/dev/null",O_RDWR); + if (PTY_FILENO =3D=3D -1) { + perror("konsole:open PTY"); + /* This won't work either, but hey .. */ + PTY_FILENO =3D DEFAULT_PTY_FILENO; + } +#else + PTY_FILENO =3D DEFAULT_PTY_FILENO; +#endif +} + int chownpty(int fd, bool grant) // param fd: the fd of a master pty. // param grant: true to grant, false to revoke @@ -212,6 +240,8 @@ int chownpty(int fd, bool grant) newsa.sa_flags =3D 0; sigaction(SIGCHLD, &newsa, &oldsa); =20 + if (PTY_FILENO =3D=3D -1) TEPtyInit(); + pid_t pid =3D fork(); if (pid < 0) { @@ -225,7 +255,12 @@ int chownpty(int fd, bool grant) /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */ if (fd !=3D PTY_FILENO && dup2(fd, PTY_FILENO) < 0) exit(1); QString path =3D locate("exe", BASE_CHOWN); =2D execle(path.ascii(), BASE_CHOWN, grant?"--grant":"--revoke", NULL, N= ULL); + /* + ** Because konsole_grantpty now can't expect the fd + ** to be constant, we need an additional parameter. + */ + QString fdnumber =3D QString::number(PTY_FILENO); + execle(path.ascii(), BASE_CHOWN, grant?"--grant":"--revoke", fdnumber.= ascii(), NULL, NULL); exit(1); // should not be reached } =20 @@ -486,6 +521,16 @@ int TEPty::makePty(bool _addutmp) // open and set all standard files to slave tty int tt =3D m_SlaveFd; // Already opened? =20 +#ifdef Q_OS_FREEBSD + /* + ** It seems to be possible for SlaveFd to be closed in error + ** somewhere along the line. So check it for "liveness". + */ + struct stat sb; + if (fstat(tt,&sb)!=3D0) + tt=3D-1; // Apparently not alive. +#endif + if (tt < 0) tt =3D open(ttynam, O_RDWR); =20 @@ -524,14 +569,57 @@ int TEPty::makePty(bool _addutmp) } strncpy(l_struct.ut_name, str_ptr, UT_NAMESIZE); =20 +#ifdef Q_OS_FREEBSD + /* FreeBSD until august 22, 2003 returned ENOMEM for too-long + ** hostnames. Then sanity prevailed (?) and the error was changed + ** to NAMETOOLONG, but this breaks konsole .. again. + ** + ** Instead of bailing out with long hostnames, put in partial + ** hostnames (the first UT_HOSTSIZE characters) instead. + */ + char hostnamebuffer[MAXHOSTNAMELEN+1]; + memset(hostnamebuffer,0,MAXHOSTNAMELEN+1); + if (gethostname(hostnamebuffer, MAXHOSTNAMELEN) =3D=3D -1) + { + if ( (errno=3D=3DENOMEM) || (errno=3D=3DENAMETOOLONG) ) { + /* ignore it, but very odd */ + } + else { + /* Not much chance of this being visible anywhere ... */ + perror("konsole:gethostname"); + abort(); + } + } + /* Copy hostname, possibly only partially */ + memset(l_struct.ut_host,0,UT_HOSTSIZE); + strncpy(l_struct.ut_host,hostnamebuffer,UT_HOSTSIZE); + l_struct.ut_host[UT_HOSTSIZE]=3D0; +#else + /* Non-FreeBSD systems */ if (gethostname(l_struct.ut_host, UT_HOSTSIZE) =3D=3D -1) { =2D if (errno !=3D ENOMEM) + if (errno !=3D ENOMEM) abort(); l_struct.ut_host[UT_HOSTSIZE]=3D0; } +#endif =20 if (! (str_ptr=3Dttyname(tt)) ) { +#ifdef Q_OS_FREEBSD + /* + ** In FreeBSD, the ttyname() call always returns NULL + ** for the kinds of devices (ptys) we have opened, + ** so don't abort, use a foolish default value instead. + ** The call to login() probably won't work _anyway_, + ** since normally users can't update the wtmp file. + ** + ** If we were real sticklers for accuracy, we'd copy the + ** code from konsole_grantpty that does it's darndest to + ** file out the right tty name. + */ + str_ptr =3D const_cast("/dev/konsole"); +#else abort(); +#endif } if (strncmp(str_ptr, "/dev/", 5) =3D=3D 0) str_ptr +=3D 5; @@ -607,7 +695,7 @@ void TEPty::startPgm(const char* pgm, QV // #define CERASE 0177 // #endif =20 =2D#if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD_= _) || defined (__bsdi__) || defined(__APPLE__) +#if defined (Q_OS_FREEBSD) || defined (__NetBSD__) || defined (__OpenBSD__= ) || defined (__bsdi__) || defined(__APPLE__) ioctl(0,TIOCGETA,(char *)&ttmode); #else # if defined (_HPUX_SOURCE) || defined(__Lynx__) @@ -621,7 +709,7 @@ void TEPty::startPgm(const char* pgm, QV ttmode.c_cc[VINTR] =3D CTRL('C'); ttmode.c_cc[VQUIT] =3D CTRL('\\'); ttmode.c_cc[VERASE] =3D 0177; =2D#if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD_= _) || defined (__bsdi__) || defined(__APPLE__) +#if defined (Q_OS_FREEBSD) || defined (__NetBSD__) || defined (__OpenBSD__= ) || defined (__bsdi__) || defined(__APPLE__) ioctl(0,TIOCSETA,(char *)&ttmode); #else # ifdef _HPUX_SOURCE Index: konsole_grantpty.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdebase/konsole/konsole/Attic/konsole_grantpty.c,v retrieving revision 1.7 diff -u -3 -p -r1.7 konsole_grantpty.c =2D-- konsole_grantpty.c 2 Sep 2002 01:09:24 -0000 1.7 +++ konsole_grantpty.c 24 Aug 2003 21:44:01 -0000 @@ -40,7 +40,9 @@ # include #endif =20 =2D#define PTY_FILENO 3 /* keep in sync with grantpty */ +#define DEFAULT_PTY_FILENO 3 /* keep in sync with TEPty.cpp */ +int PTY_FILENO =3D DEFAULT_PTY_FILENO; + #define TTY_GROUP "tty" =20 int main (int argc, char *argv[]) @@ -52,11 +54,13 @@ int main (int argc, char *argv[]) uid_t uid; mode_t mod; char* tty; + int command_fd; /* which fd to use? */ =20 /* check preconditions *************************************************= */ =2D if (argc !=3D 2 || (strcmp(argv[1],"--grant") && strcmp(argv[1],"--rev= oke"))) + if (( (argc !=3D 3) && (argc !=3D 2) /* optional third arg */ ) ||=20 + (strcmp(argv[1],"--grant") && strcmp(argv[1],"--revoke"))) { =2D printf("usage: %s (--grant|--revoke)\n",argv[0]); + printf("usage: %s (--grant|--revoke) [fd]\n",argv[0]); printf("%s is a helper for\n",argv[0]); printf("konsole and not intented to\n"); printf("be called from the command\n"); @@ -83,6 +87,22 @@ int main (int argc, char *argv[]) uid =3D 0; /* root */ mod =3D S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; } + + command_fd =3D DEFAULT_PTY_FILENO; + if (argv[2]) + { + command_fd =3D atoi(argv[2]); + } + if (command_fd > 2) /* must be out of stdin,stdout,stderr range */ + { + PTY_FILENO=3Dcommand_fd; + } + else + { + fprintf(stderr,"%s: Bad command fd (seems to be %d)\n",argv[0],command= _fd); + return 1; + } + =20 /* Get the group ID of the special `tty' group. */ p =3D getgrnam(TTY_GROUP); /* posix */ gid =3D p ? p->gr_gid : getgid (); /* posix */ @@ -117,6 +137,9 @@ int main (int argc, char *argv[]) if (dirp->d_fileno !=3D dsb.st_ino) continue; { + /* Else this is the right device file .. any possible memory + ** leak here because two files match is unimportant? + */ int pdlen =3D strlen(_PATH_DEV), namelen =3D strlen(dirp->d_name); pty =3D malloc(pdlen + namelen + 1); if (pty) { Index: main.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdebase/konsole/konsole/main.cpp,v retrieving revision 1.243.2.3 diff -u -3 -p -r1.243.2.3 main.cpp =2D-- main.cpp 29 Jun 2003 21:53:11 -0000 1.243.2.3 +++ main.cpp 24 Aug 2003 21:44:02 -0000 @@ -123,6 +123,7 @@ public: }; =20 =20 +extern void TEPtyInit(); =20 /* --| main |------------------------------------------------------ */ int main(int argc, char* argv[]) @@ -137,6 +138,7 @@ int main(int argc, char* argv[]) bool scrollbaron =3D true; QCString wname =3D PACKAGE; =20 + TEPtyInit(); =20 KAboutData aboutData( PACKAGE, I18N_NOOP("Konsole"), VERSION, description, KAboutData::License_GPL_V2, --Boundary-01=_QqTS/t5CR7iqyeX-- --Boundary-03=_UqTS/zMruhwbgiL Content-Type: application/pgp-signature Content-Description: signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA/STqUXhc68WspdLARAuXnAJ9ZBx435cm/5IR3qISU8eOEFXA+0QCdHDjz kgJ0cI+86rPEmQWwoghdRhs= =gj7W -----END PGP SIGNATURE----- --Boundary-03=_UqTS/zMruhwbgiL--