Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Aug 2003 23:28:58 -0500
From:      Larry Rosenman <ler@lerctr.org>
To:        "Daniel O'Connor" <doconnor@gsoft.com.au>, Daniel Eischen <eischen@vigrid.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: KDE Konsole, crashes, on a SIGABRT...
Message-ID:  <138610000.1061785738@lerlaptop.lerctr.org>
In-Reply-To: <200308251356.08221.doconnor@gsoft.com.au>
References:  <Pine.GSO.4.10.10308231022480.20510-100000@pcnet5.pcnet.com> <200308251356.08221.doconnor@gsoft.com.au>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
add the attached 2 files to /usr/ports/x11/kdebase3/files and make 
configure and then
cd work/kdebase-3.1.3/konsole/konsole and gmake, gmake install.
This fixed it for me.

These (or equivalent) are coming soon to the ports tree.

LER




--On Monday, August 25, 2003 13:56:07 +0930 Daniel O'Connor 
<doconnor@gsoft.com.au> wrote:

> On Saturday 23 August 2003 23:57, Daniel Eischen wrote:
>> > How can I help figure this out?
>>
>> We (threads guys) think it's a problem with konsole.  It is trying
>> to change ownership of the pty and is failing to do so.  We don't
>> know why.  Sometimes it works, sometimes it doesn't.  konsole
>> aborts itself when it can't change/open the pty, so SIGABRT is
>> expected.
>
> I dunno..
> On 4.x I get this in my .xsession-errors file ->
> konsole: cannot chown /dev/ttyp2.
> Reason: Operation not permitted
> konsole: chownpty failed for device /dev/ptyp2::/dev/ttyp2.
>        : This means the session can be eavesdroped.
>        : Make sure konsole_grantpty is installed in
>        : /usr/local/bin/ and setuid root.
>
> It is as expected I think ->
>
> [chowder 13:53] ~ >ll /dev/ttyp2
> crw-rw-rw-  1 root  wheel    5,   2 Aug 25 13:53 /dev/ttyp2
> [chowder 13:53] ~ >ll /usr/local/bin/konsole_grantpty
> -rwsr-xr-x  1 root  wheel  5584 Aug 13 04:06
> /usr/local/bin/konsole_grantpty
>
> I found that a 5.1-REL machine I upgraded to -CURRENT last Thursday had
> this  problem, I haven't resolved it yet, but possibly rebuilding kdebase
> will fix  it.



-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

[-- Attachment #2 --]
--- konsole/konsole/TEPty.cpp.orig	22 Nov 2002 13:17:57 -0000	1.75
+++ konsole/konsole/TEPty.cpp		23 Aug 2003 14:20:20 -0000
@@ -198,9 +198,18 @@ public:
 
 FILE* syslog_file = NULL; //stdout;
 
-#define PTY_FILENO 3
+// #define PTY_FILENO 3
+int PTY_FILENO = -1; // None allocated yet.
+
 #define BASE_CHOWN "konsole_grantpty"
 
+void TEPtyInit()
+{
+#if defined(__FreeBSD__)
+  PTY_FILENO = open("/dev/null",O_RDWR);
+#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 +221,20 @@ int chownpty(int fd, bool grant)
   newsa.sa_flags = 0;
   sigaction(SIGCHLD, &newsa, &oldsa);
 
+/*
+** 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.
+*/
+  if (PTY_FILENO == -1)
+  {
+#if defined(__FreeBSD__)
+    PTY_FILENO = open("/dev/null",O_RDWR);
+#else
+    PTY_FILENO = 3;
+#endif
+  }
+
   pid_t pid = fork();
   if (pid < 0)
   {
@@ -225,7 +248,12 @@ int chownpty(int fd, bool grant)
     /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */
     if (fd != PTY_FILENO && dup2(fd, PTY_FILENO) < 0) exit(1);
     QString path = locate("exe", BASE_CHOWN);
-    execle(path.ascii(), BASE_CHOWN, grant?"--grant":"--revoke", NULL, NULL);
+    /*
+    ** Because konsole_grantpty now can't expect the fd
+    ** to be constant, we need an additional parameter.
+    */
+    QString fdnumber = QString::number(PTY_FILENO);
+    execle(path.ascii(), BASE_CHOWN, grant?"--grant":"--revoke", fdnumber.ascii(), NULL, NULL);
     exit(1); // should not be reached
   }
 
@@ -486,6 +514,16 @@ int TEPty::makePty(bool _addutmp)
   // open and set all standard files to slave tty
   int tt = m_SlaveFd; // Already opened?
 
+#if defined(__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)!=0)
+    tt=-1; // Apparently not alive.
+#endif
+
   if (tt < 0)
     tt = open(ttynam, O_RDWR);
 
@@ -531,7 +569,22 @@ int TEPty::makePty(bool _addutmp)
   }
 
   if (! (str_ptr=ttyname(tt)) ) {
+#if defined(__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 = const_cast<char *>("/dev/konsole");
+#else
     abort();
+#endif
   }
   if (strncmp(str_ptr, "/dev/", 5) == 0)
        str_ptr += 5;
--- konsole/konsole/konsole_grantpty.c.orig	2 Sep 2002 01:09:24 -0000	1.7
+++ konsole/konsole/konsole_grantpty.c		23 Aug 2003 14:20:20 -0000
@@ -40,7 +40,9 @@
 #  include <dirent.h>
 #endif
 
-#define PTY_FILENO 3    /* keep in sync with grantpty */
+/* #define PTY_FILENO 3 */   /* keep in sync with grantpty */
+int PTY_FILENO = 3;          /* keep in sync with TEPty.cpp */
+
 #define TTY_GROUP "tty"
 
 int main (int argc, char *argv[])
@@ -52,9 +54,10 @@ int main (int argc, char *argv[])
   uid_t         uid;
   mode_t        mod;
   char*         tty;
+  int           command_fd; /* which fd to use? */
 
   /* 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",argv[0]);
     printf("%s is a helper for\n",argv[0]);
@@ -83,6 +86,22 @@ int main (int argc, char *argv[])
     uid = 0;        /* root */
     mod = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
   }
+
+  command_fd = -1; /* invalid fd */
+  if (argv[2])
+  {
+    command_fd = atoi(argv[2]);
+  }
+  if (command_fd > 2) /* must be out of stdin,stdout,stderr range */
+  {
+    PTY_FILENO=command_fd;
+  }
+  else
+  {
+    fprintf(stderr,"%s: Bad command fd (seems to be %d)\n",argv[0],command_fd);
+    return 1;
+  }
+  
   /* Get the group ID of the special `tty' group.  */
   p = getgrnam(TTY_GROUP);            /* posix */
   gid = p ? p->gr_gid : getgid ();    /* posix */
--- konsole/konsole/main.cpp.orig	29 Jun 2003 21:53:11 -0000	1.243.2.3
+++ konsole/konsole/main.cpp		23 Aug 2003 14:20:22 -0000
@@ -123,6 +123,7 @@ public:
 };
 
 
+extern void TEPtyInit();
 
 /* --| main |------------------------------------------------------ */
 int main(int argc, char* argv[])
@@ -137,6 +138,7 @@ int main(int argc, char* argv[])
   bool scrollbaron = true;
   QCString wname = PACKAGE;
 
+  TEPtyInit();
 
   KAboutData aboutData( PACKAGE, I18N_NOOP("Konsole"),
     VERSION, description, KAboutData::License_GPL_V2,

[-- Attachment #3 --]
--- konsole/konsole/TEPty.cpp.orig      Sun Aug 24 20:39:42 2003
+++ konsole/konsole/TEPty.cpp   Sun Aug 24 21:11:53 2003
@@ -563,7 +563,15 @@
   strncpy(l_struct.ut_name, str_ptr, UT_NAMESIZE);

   if (gethostname(l_struct.ut_host, UT_HOSTSIZE) == -1) {
-     if (errno != ENOMEM)
+#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.
+     */
+     if (!((errno == ENOMEM) || (errno == ENAMETOOLONG)))
+#else
+     if  (errno != ENOMEM)
+#endif
         abort();
      l_struct.ut_host[UT_HOSTSIZE]=0;
   }
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?138610000.1061785738>