vte r2212 - in trunk: . gnome-pty-helper



Author: chpe
Date: Thu Nov 27 23:57:10 2008
New Revision: 2212
URL: http://svn.gnome.org/viewvc/vte?rev=2212&view=rev

Log:
	Bug 562385 â gnome-pty-helper goes to 100% cpu usage

	* gnome-pty-helper/gnome-pty-helper.c: (pass_fd), (pty_free),
	(main): Make sure data structures are correctly aligned and of the
	right size.

Modified:
   trunk/ChangeLog
   trunk/gnome-pty-helper/gnome-pty-helper.c

Modified: trunk/gnome-pty-helper/gnome-pty-helper.c
==============================================================================
--- trunk/gnome-pty-helper/gnome-pty-helper.c	(original)
+++ trunk/gnome-pty-helper/gnome-pty-helper.c	Thu Nov 27 23:57:10 2008
@@ -94,20 +94,16 @@
 #endif
 #endif /* CMSG_DATA */
 
-static struct cmsghdr *cmptr;
-static int CONTROLLEN;
-
-static int
-init_msg_pass (void)
-{
-	CONTROLLEN = (CMSG_DATA (cmptr) - (unsigned char *)cmptr) + sizeof(int);
-	cmptr = malloc (CONTROLLEN);
-
-	if (cmptr)
-		return 0;
-
-	return -1;
-}
+/* Solaris doesn't define these */
+#ifndef CMSG_ALIGN
+#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))
+#endif
+#ifndef CMSG_SPACE
+#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr)))
+#endif
+#ifndef CMSG_LEN
+#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
+#endif
 
 static int
 pass_fd (int client_fd, int fd)
@@ -115,6 +111,8 @@
         struct iovec  iov[1];
         struct msghdr msg;
         char          buf [1];
+        char    cmsgbuf[CMSG_SPACE(sizeof(int))];
+        struct  cmsghdr *cmptr;
 
 	iov [0].iov_base = buf;
 	iov [0].iov_len  = 1;
@@ -123,12 +121,13 @@
 	msg.msg_iovlen     = 1;
 	msg.msg_name       = NULL;
 	msg.msg_namelen    = 0;
-	msg.msg_control    = (caddr_t) cmptr;
-	msg.msg_controllen = CONTROLLEN;
+	msg.msg_control    = (caddr_t) cmsgbuf;
+	msg.msg_controllen = sizeof(cmsgbuf);
 
+        cmptr = CMSG_FIRSTHDR(&msg);
 	cmptr->cmsg_level = SOL_SOCKET;
 	cmptr->cmsg_type  = SCM_RIGHTS;
-	cmptr->cmsg_len   = CONTROLLEN;
+	cmptr->cmsg_len   = CMSG_LEN(sizeof(int));
 	*(int *)CMSG_DATA (cmptr) = fd;
 
 	if (sendmsg (client_fd, &msg, 0) != 1)
@@ -153,12 +152,6 @@
 #include <sys/uio.h>
 
 static int
-init_msg_pass ()
-{
-  return 0;
-}
-
-static int
 pass_fd (int client_fd, int fd)
 {
   struct iovec  iov[1];
@@ -184,12 +177,6 @@
 #else
 #include <stropts.h>
 #ifdef I_SENDFD
-static int
-init_msg_pass ()
-{
-	/* nothing */
-	return 0;
-}
 
 int
 pass_fd (int client_fd, int fd)
@@ -707,9 +694,6 @@
 	signal (SIGHUP, exit_handler);
 	signal (SIGTERM, exit_handler);
 
-	if (init_msg_pass () == -1)
-		exit (1);
-
 	while (!done) {
 		res = n_read (STDIN_FILENO, &op, sizeof (op));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]