[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    [PATCH] 1_1_BRANCH: kvt, pty and glibc-2.1 still broken
From:       Franz Sirl <Franz.Sirl-kernel () lauterbach ! com>
Date:       1999-07-24 13:16:21
[Download RAW message or body]

Hi,

the attached patch fixes a problem with the current 1_1 kvt where it can't get
a pty. As this routine was already a mess, I took a clean approach and
implemented the glibc-2.1 part like recommended in the glibc info pages.
Additionally I added wtmp handling to kvt.

This made kvt work in the following environment:

linux-2.2.10/PPC
glibc-2.1.2pre1
XFree86-3.3.3.1
qt-1.44
KDE_1_1_BRANCH as of 19990722 (with kde sound/bigendian fixes, BugID 1581/1582)

Franz.

--- /home/fsirl/kde/kdebase/kvt/command.c	Tue Jun  8 04:09:22 1999
+++ kdebase-1.1.2/kvt/command.c	Sun Jul 18 08:29:36 1999
@@ -24,6 +24,9 @@
  * aggreed to distribute their code under the terms of the GPL
  */
 
+/* define _GNU_SOURCE to get prototypes for getpt() and ptsname() */
+#define _GNU_SOURCE
+
 #include <stdarg.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -167,12 +170,16 @@ static int x_fd;	/* file descriptor of t
 static int fd_width;	/* width of file descriptors being used */
 static int app_cur_keys = 0;/* flag to set cursor keys in application mode */
 static int app_kp_keys = 0; /* flag to set application keypad keys */
+#if __GLIBC__ - 0 == 2 && __GLIBC_MINOR__ >= 1
+char *ttynam;
+#else
 #ifndef SVR4
 static char ptynam[25] = "/dev/ptyxx";
 char ttynam[25] = "/dev/ttyxx";
 #else
 char *ttynam, *ptsname();
 #endif
+#endif
 static Atom wm_del_win;
 extern WindowInfo MyWinInfo;
 
@@ -348,6 +355,29 @@ static void catch_sig(int sig)
   /*  First find a master pty that we can open.  
    */
 
+#if __GLIBC__ - 0 == 2 && __GLIBC_MINOR__ >= 1
+  ptyfd = getpt();
+  if (ptyfd < 0)
+    {
+      error("Can't open a pseudo teletype");
+      return(-1);
+    }
+  if (grantpt(ptyfd) < 0 || unlockpt(ptyfd) < 0)
+    {
+      close(ptyfd);
+      error("Can't grantpt/unlockpt a pseudo teletype");
+      return(-1);
+    }
+  ttynam = ptsname(ptyfd);
+  if (ttynam == 0)
+    {
+      close(ptyfd);
+      error("Pseudo teletype has no name");
+      return(-1);
+    }
+  fcntl(ptyfd,F_SETFL,O_NDELAY);
+  grantpty = 0;
+#else
 #ifdef TIOCGPTN
   strcpy(ptynam,"/dev/ptmx");
   strcpy(ttynam,"/dev/pts/");
@@ -418,6 +448,7 @@ if (ptyfd < 0)
     fcntl(ptyfd,F_SETFL,O_NDELAY);
 #endif  
   }
+#endif /* GLIBC */
 
   for (i = 1; i <= 15; i++)
     signal(i,catch_sig);
--- /home/fsirl/kde/kdebase/kvt/utmp.c	Tue Jun  8 04:09:22 1999
+++ kdebase-1.1.2/kvt/utmp.c	Sun Jul 18 08:24:23 1999
@@ -309,6 +309,7 @@ int write_utmp(struct utmp * u) 
   setutent();
   pututline(u);
   endutent();
+  updwtmp(WTMP_FILE, u);
   pos = (int)NULL;
   madeutent = 1;
 
@@ -404,6 +405,7 @@ void cleanutent() 
 #endif
 	  pututline(u); /* Was reversed with in the original */
 	  endutent();
+	  updwtmp(WTMP_FILE, u);
 	}
     }
 

["kdebase-1.1.2-glibc21.patch" (text/x-c)]

--- /home/fsirl/kde/kdebase/kvt/command.c	Tue Jun  8 04:09:22 1999
+++ kdebase-1.1.2/kvt/command.c	Sun Jul 18 08:29:36 1999
@@ -24,6 +24,9 @@
  * aggreed to distribute their code under the terms of the GPL
  */
 
+/* define _GNU_SOURCE to get prototypes for getpt() and ptsname() */
+#define _GNU_SOURCE
+
 #include <stdarg.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -167,12 +170,16 @@ static int x_fd;	/* file descriptor of t
 static int fd_width;	/* width of file descriptors being used */
 static int app_cur_keys = 0;/* flag to set cursor keys in application mode */
 static int app_kp_keys = 0; /* flag to set application keypad keys */
+#if __GLIBC__ - 0 == 2 && __GLIBC_MINOR__ >= 1
+char *ttynam;
+#else
 #ifndef SVR4
 static char ptynam[25] = "/dev/ptyxx";
 char ttynam[25] = "/dev/ttyxx";
 #else
 char *ttynam, *ptsname();
 #endif
+#endif
 static Atom wm_del_win;
 extern WindowInfo MyWinInfo;
 
@@ -348,6 +355,29 @@ static void catch_sig(int sig)
   /*  First find a master pty that we can open.  
    */
 
+#if __GLIBC__ - 0 == 2 && __GLIBC_MINOR__ >= 1
+  ptyfd = getpt();
+  if (ptyfd < 0)
+    {
+      error("Can't open a pseudo teletype");
+      return(-1);
+    }
+  if (grantpt(ptyfd) < 0 || unlockpt(ptyfd) < 0)
+    {
+      close(ptyfd);
+      error("Can't grantpt/unlockpt a pseudo teletype");
+      return(-1);
+    }
+  ttynam = ptsname(ptyfd);
+  if (ttynam == 0)
+    {
+      close(ptyfd);
+      error("Pseudo teletype has no name");
+      return(-1);
+    }
+  fcntl(ptyfd,F_SETFL,O_NDELAY);
+  grantpty = 0;
+#else
 #ifdef TIOCGPTN
   strcpy(ptynam,"/dev/ptmx");
   strcpy(ttynam,"/dev/pts/");
@@ -418,6 +448,7 @@ if (ptyfd < 0)
     fcntl(ptyfd,F_SETFL,O_NDELAY);
 #endif  
   }
+#endif /* GLIBC */
 
   for (i = 1; i <= 15; i++)
     signal(i,catch_sig);
--- /home/fsirl/kde/kdebase/kvt/utmp.c	Tue Jun  8 04:09:22 1999
+++ kdebase-1.1.2/kvt/utmp.c	Sun Jul 18 08:24:23 1999
@@ -309,6 +309,7 @@ int write_utmp(struct utmp * u) 
   setutent();
   pututline(u);
   endutent();
+  updwtmp(WTMP_FILE, u);
   pos = (int)NULL;
   madeutent = 1;
 
@@ -404,6 +405,7 @@ void cleanutent() 
 #endif
 	  pututline(u); /* Was reversed with in the original */
 	  endutent();
+	  updwtmp(WTMP_FILE, u);
 	}
     }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic