gnome-core: gnome-login-check, dns-helper in GNOME2?



Hi, 
Everytime when i start GNOME2, gnome-seesion wants to check local host
name, by gnome-login-check using dns-helper (in gnome-login-check.c),
small support program from gnome-libs-1.2.x... 
I tought that i can fix that by using some old and deprecated
gnome_dns_* functions but they are not available anymore in GNOME 2 ;-)
I've created a small patch, it is resolving a hostname after fork(), and
returns a result through pipe. It may help, well at least it removes
that annoying message at startup...

Regards,
Igor


--- ./gnome-core-1.5.6.orig/gsm/gnome-login-check.c	Tue Nov 27 00:36:04 2001
+++ ./gnome-core-1.5.6/gsm/gnome-login-check.c	Mon Feb  4 11:49:56 2002
@@ -23,6 +23,8 @@
 #include <gdk/gdkx.h>
 #include <stdio.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
 #include <sys/wait.h>
 #include <errno.h>
 #include <limits.h>
@@ -138,6 +140,38 @@
 	
 	gtk_main_quit ();
 }
+static
+int dns_resolve(int *fd, char *hostname)
+{
+	int pipes[2], pid;
+	struct in_addr ip_addr;
+
+	if (pipe(pipes) == -1)
+		return -1;
+
+	if ((pid = fork()) == -1)
+		return -1;
+
+	if (!pid) {
+		if ((ip_addr.s_addr = inet_addr(hostname)) == INADDR_NONE) {
+			struct hostent *he;
+
+			if (!(he = gethostbyname(hostname)))
+				ip_addr.s_addr = INADDR_NONE;
+			else
+				memcpy((char *) &ip_addr, he->h_addr, sizeof(ip_addr));
+		}
+		write(pipes[1], &ip_addr, sizeof(ip_addr));
+
+		_exit(0);
+	}
+
+	close(pipes[1]);
+
+	*fd = pipes[0];
+
+	return 0;
+}
 
 /* Check if a DNS lookup on `hostname` can be done */
 static gboolean
@@ -153,45 +187,19 @@
 	if (!hostname)
 		return FALSE;
 	else {
-		gint pid;
-		int in_fd[2];
-		int out_fd[2];
+		gint fd;
 		
-		if (pipe(in_fd))
-			return FALSE;
-		if (pipe(out_fd))
+		if (dns_resolve(&fd, hostname) == -1) 
 			return FALSE;
-		
-		if (!(pid = fork())) { /* Child */
-			close (in_fd[1]);
-			close (out_fd[0]);
 			
-			dup2 (in_fd[0], STDIN_FILENO);
-			dup2 (out_fd[1], STDOUT_FILENO);
-			
-			execlp ("dns-helper", "dns-helper", NULL);
-
-			/* Should never be reached */
-			_exit (0);
+		/* GDK_INPUT_EXCEPTION is a temporary hack here */
+		input_tag = gdk_input_add (fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
+				   input_callback, &success);
+		timeout_tag = gtk_timeout_add (1000, startup_timeout, &progress_amount);
 
-		} else if (pid > 0) { /* Parent */
-			write (in_fd[1], hostname, strlen(hostname));
-			close (in_fd[1]);
-			close (in_fd[0]);
+		gtk_main ();
 			
-			close (out_fd[1]);
-			
-			/* GDK_INPUT_EXCEPTION is a temporary hack here */
-			input_tag = gdk_input_add (out_fd[0], GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
-						   input_callback, &success);
-			timeout_tag = gtk_timeout_add (1000, startup_timeout, &progress_amount);
-
-			gtk_main ();
-			
-			return success;
-		  
-		} else
-			return FALSE;
+		return success;
 	}
 }
 


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