This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Some corrections to my pty patch


Hi,

This patch fixes the damage I've done to `openpty'.  I also found a
possible memory leak in my `grantpt' implementation.  And I realised
that the description of the `pt_chown' program in its help message was
a bit misleading.

Mark


1998-09-18  Mark Kettenis  <kettenis@phys.uva.nl>

	* login/programs/pt_chown.c (more_help): Correct message that
	describes the purpose of the program.

	* login/openpty.c: Do not include pty-private.h.
	(pts_name): New function.  Return name of slave pseudo terminal in
	an allocated buffer if necessary.
	(openpty): Use pts_name to get name of the slave end of the pseudo
	terminal pair.

	* sysdeps/unix/grantpt.c (grantpt): Free buffer allocated by
	pts_name before return.


Index: login/programs/pt_chown.c
--- Local.15/login/programs/pt_chown.c Fri, 18 Sep 1998 18:44:53 +0200 kettenis (libc/37_pt_chown.c 1.2 644)
+++ Local.15(w)/login/programs/pt_chown.c Fri, 18 Sep 1998 22:49:05 +0200 kettenis (libc/37_pt_chown.c 1.2 644)
@@ -72,10 +72,11 @@
     {
     case ARGP_KEY_HELP_PRE_DOC:
       asprintf (&cp, gettext ("\
-Set the owner, group and access permission of the terminal passed on\
- file descriptor `%d'.  This is the helper program for the `grantpt'\
- function.  It is not intended to be run directly from the command\
- line.\n"),
+Set the owner, group and access permission of the slave pseudo\
+ terminal corresponding to the master pseudo terminal passed on\
+ file descriptor `%d'.  This is the helper program for the\
+ `grantpt' function.  It is not intended to be run directly from\
+ the command line.\n"),
 		PTY_FILENO);
       return cp;
     case ARGP_KEY_HELP_EXTRA:
Index: sysdeps/unix/grantpt.c
--- Local.15/sysdeps/unix/grantpt.c Fri, 18 Sep 1998 18:44:53 +0200 kettenis (libc/38_grantpt.c 1.3 644)
+++ Local.15(w)/sysdeps/unix/grantpt.c Fri, 18 Sep 1998 20:02:37 +0200 kettenis (libc/38_grantpt.c 1.3 644)
@@ -90,6 +90,7 @@
 int
 grantpt (int fd)
 {
+  int retval = -1;
 #ifdef PATH_MAX
   char _buf[PATH_MAX];
 #else
@@ -109,7 +110,7 @@
     return -1;
   
   if (__stat (buf, &st) < 0)
-    return -1;
+    goto cleanup;
 
   /* Make sure that we own the device.  */
   uid = __getuid ();
@@ -143,14 +144,15 @@
 	goto helper;
     }
 
-  return 0;
+  retval = 0;
+  goto cleanup;
 
   /* We have to use the helper program.  */
  helper:
 
   pid = __fork ();
   if (pid == -1)
-    return -1;
+    goto cleanup;
   else if (pid == 0)
     {
       /* Disable core dumps.  */
@@ -170,34 +172,36 @@
       int w;
       
       if (__waitpid (pid, &w, 0) == -1)
-	return -1;
+	goto cleanup;
       if (!WIFEXITED (w))
-	{
-	  __set_errno (ENOEXEC);
-	  return -1;
-	}
+	__set_errno (ENOEXEC);
       else
 	switch (WEXITSTATUS(w))
 	  {
 	  case 0:
+	    retval = 0;
 	    break;
 	  case FAIL_EBADF:
 	    __set_errno (EBADF);
-	    return -1;
+	    break;
 	  case FAIL_EINVAL:
 	    __set_errno (EINVAL);
-	    return -1;
+	    break;
 	  case FAIL_EACCES:
 	    __set_errno (EACCES);
-	    return -1;
+	    break;
 	  case FAIL_EXEC:
 	    __set_errno (ENOEXEC);
-	    return -1;
+	    break;
 
 	  default:
 	    assert(! "getpt: internal error: invalid exit code from pt_chown");
 	  }
     }
 
-  return 0;
+ cleanup:
+  if (buf != _buf)
+    free (buf);
+  
+  return retval;
 }
Only in Local.15(w): login/openpty.c


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]