kov changed libgksu/trunk/ChangeLog, libgksu/trunk/libgksu/libgksu.c

Gustavo Noronha kov at alioth.debian.org
Sat Jun 9 20:22:54 UTC 2007


Mensagem de log: 
reworked the way gksu_su{,do}_full relays the child's
output, making it sleep rather than wakeup every
few microseconds (Addressing Debian Bug #425679)


-----


Modified: libgksu/trunk/ChangeLog
===================================================================
--- libgksu/trunk/ChangeLog	2007-05-11 03:59:14 UTC (rev 797)
+++ libgksu/trunk/ChangeLog	2007-06-09 20:22:53 UTC (rev 798)
@@ -1,3 +1,10 @@
+2007-06-09  Gustavo Noronha Silva  <kov at debian.org>
+
+	* libgksu/libgksu.c:
+	- reworked the way gksu_su{,do}_full relays the child's
+	  output, making it sleep rather than wakeup every
+	  few microseconds (Addressing Debian Bug #425679)
+
 2007-05-11  Gustavo Noronha Silva  <kov at debian.org>
 
 	* configure.ac:

Modified: libgksu/trunk/libgksu/libgksu.c
===================================================================
--- libgksu/trunk/libgksu/libgksu.c	2007-05-11 03:59:14 UTC (rev 797)
+++ libgksu/trunk/libgksu/libgksu.c	2007-06-09 20:22:53 UTC (rev 798)
@@ -1886,7 +1886,7 @@
   if (context->sn_context)
     gksu_context_launch_initiate (context);
 
-  pid = forkpty (&fdpty, NULL, NULL, NULL);
+  pid = forkpty(&fdpty, NULL, NULL, NULL);
   if (pid == 0)
     {
       gchar **cmd = g_malloc (sizeof(gchar*)*7);
@@ -1977,7 +1977,7 @@
 	  tcgetattr (fdpty, &tio);
 	  for (count = 0; (tio.c_lflag & ECHO) && count < 15; count++)
 	    {
-	      usleep (30);
+	      usleep (1000);
 	      tcgetattr (fdpty, &tio);
 	    }
 
@@ -2185,76 +2185,51 @@
 	    }
 	}
 
-      FD_ZERO(&rfds);
-      FD_SET(fdpty, &rfds);
-
-      tv.tv_sec = 0;
-      tv.tv_usec = 100;
-
-      while (!waitpid (pid, &status, WNOHANG))
+      cmdline = g_strdup("bin/su");
+      /* wait for the child process to end or become something other
+	 than su */
+      while ((!waitpid (pid, &status, WNOHANG)) &&
+	     (g_str_has_suffix(cmdline, "bin/su")))
 	{
-	  bzero (buf, 256);
-	  usleep (200);
-
 	  if (cmdline)
 	    g_free (cmdline);
 	  cmdline = get_process_name (pid);
-
-	  usleep(1000);
-
-	  if (select (fdpty+1, &rfds, NULL, NULL, &tv) < 0)
-	    {
-	      g_set_error (error, gksu_quark, GKSU_ERROR_PIPEREAD,
-			   _("Could not read from the pipe "
-			     "with the child: %s"),
-			   strerror(errno));
-	      return FALSE;
-	    }
-
-	  if(FD_ISSET(fdpty, &rfds))
-	    {
-	      bzero(buf, 256);
-	      read (fdpty, buf, 255);
-	      fprintf (stderr, "%s", buf);
-	    }
-	  else
-	    FD_SET(fdpty, &rfds);
+	  usleep(100000);
 	}
 
-      while (1)
+      if (context->sn_context)
+	gksu_context_launch_complete (context);
+
+      bzero(buf, 256);
+      while (read (fdpty, buf, 255) > 0)
 	{
-	  bzero(buf, 256);
-	  if(read (fdpty, buf, 255) <= 0)
-	    break;
 	  fprintf (stderr, "%s", buf);
+	  bzero(buf, 256);
 	}
 
-      if (context->sn_context)
-	gksu_context_launch_complete (context);
+      if (!WIFEXITED(status))
+	waitpid(pid, &status, 0);
 
-      if (WIFEXITED(status))
+      if (WEXITSTATUS(status))
 	{
-	  if (WEXITSTATUS(status))
+	  if(cmdline)
 	    {
-	      if(cmdline)
+	      /* su already exec()ed something else, don't report
+	       * exit status errors in that case
+	       */
+	      if (!g_str_has_suffix (cmdline, "su"))
 		{
-		  /* su already exec()ed something else, don't report
-		   * exit status errors in that case
-		   */
-		  if (!g_str_has_suffix (cmdline, "su"))
-		    {
-		      g_free (cmdline);
-		      return FALSE;
-		    }
 		  g_free (cmdline);
+		  return FALSE;
 		}
-
-	      if (error == NULL)
-		g_set_error (error, gksu_quark,
-			     GKSU_ERROR_CHILDFAILED,
-			     _("su terminated with %d status"),
-			     WEXITSTATUS(status));
+	      g_free (cmdline);
 	    }
+
+	  if (error == NULL)
+	    g_set_error (error, gksu_quark,
+			 GKSU_ERROR_CHILDFAILED,
+			 _("su terminated with %d status"),
+			 WEXITSTATUS(status));
 	}
     }
 
@@ -2636,7 +2611,7 @@
 	      return FALSE;
 	    }
 
-	  usleep (100);
+	  usleep (1000);
 
 	  fprintf (outfile, "%s\n", password);
 	  fclose (outfile);
@@ -2650,8 +2625,6 @@
 	  fgets (buffer, 255, infile);
 	  /* this is the status we are interessted in */
 	  fgets (buffer, 255, infile);
-	  /* turn it ON again */
-	  fcntl(parent_pipe[0], F_SETFL, fcntl(parent_pipe[0], F_GETFL) | O_NONBLOCK);
 	}
       else
 	{
@@ -2700,57 +2673,51 @@
 			       "the system administrator."));
 	    }
 	}
-      while (!waitpid (pid, &status, WNOHANG))
+
+      cmdline = g_strdup("sudo");
+      /* wait for the child process to end or become something other
+	 then sudo */
+      while ((!waitpid (pid, &status, WNOHANG)) &&
+	     (g_str_has_suffix(cmdline, "sudo")))
 	{
 	  if (cmdline)
 	    g_free (cmdline);
 	  cmdline = get_process_name (pid);
-
-	  usleep(1000);
-
-	  bzero(buffer, 256);
-	  if(!fgets (buffer, 255, infile))
-	    continue;
-	  fprintf (stderr, "%s", buffer);
+	  usleep(100000);
 	}
 
-      /* make sure we did read everything */
-      while (1)
+      if (context->sn_context)
+	gksu_context_launch_complete (context);
+
+      while (read (parent_pipe[0], buffer, 255) > 0)
 	{
-	  bzero(buffer, 256);
-	  if(!fread (buffer, sizeof(gchar), 255, infile))
-	    break;
 	  fprintf (stderr, "%s", buffer);
-	  fflush (stderr);
+	  bzero(buffer, 256);
 	}
 
-      if (context->sn_context)
-	gksu_context_launch_complete (context);
+      if (!WIFEXITED(status))
+	waitpid(pid, &status, 0);
       sudo_reset_xauth (context, xauth, xauth_env);
 
-      if (WIFEXITED(status))
+      if (WEXITSTATUS(status))
 	{
-	  if (WEXITSTATUS(status))
+	  if(cmdline)
 	    {
-	      if(cmdline)
+	      /* sudo already exec()ed something else, don't report
+	       * exit status errors in that case
+	       */
+	      if (!g_str_has_suffix (cmdline, "sudo"))
 		{
-		  /* sudo already exec()ed something else, don't report
-		   * exit status errors in that case
-		   */
-		  if (!g_str_has_suffix (cmdline, "sudo"))
-		    {
-		      g_free (cmdline);
-		      return FALSE;
-		    }
 		  g_free (cmdline);
+		  return FALSE;
 		}
-
-	      if (error == NULL)
-		g_set_error (error, gksu_quark,
-			     GKSU_ERROR_CHILDFAILED,
-			     _("sudo terminated with %d status"),
-			     WEXITSTATUS(status));
+	      g_free (cmdline);
 	    }
+	  if (error == NULL)
+	    g_set_error (error, gksu_quark,
+			 GKSU_ERROR_CHILDFAILED,
+			 _("sudo terminated with %d status"),
+			 WEXITSTATUS(status));
 	}
     }
 




More information about the gksu-commits mailing list