This is the mail archive of the libc-alpha@sourceware.org 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]
Other format: [Raw text]

[PATCH,HURD] Allow to override the /servers/socket path


Hello,

The patch below permits to override the /servers/socket path with the
user's own preference.

Samuel

2008-06-30 Zheng Da <zhengda1936@gmail.com>

	* hurd/hurdsocks.c (_hurd_socket_server): Default server to
	MACH_PORT_NULL. Search SERVERS_SOCKET_* and SERVER_SOCKETS environment
	variables for the socket server before using the default one.

diff -u glibc-2.7-old/hurd/hurdsock.c glibc-2.7/hurd/hurdsock.c
--- glibc-2.7-old/hurd/hurdsock.c	2008-06-21 01:38:30.000000000 +0200
+++ glibc-2.7/hurd/hurdsock.c	2008-08-22 03:26:44.000000000 +0200
@@ -45,7 +45,7 @@
 socket_t
 _hurd_socket_server (int domain, int dead)
 {
-  socket_t server;
+  socket_t server = MACH_PORT_NULL;
 
   HURD_CRITICAL_BEGIN;
   __mutex_lock (&lock);
@@ -76,16 +76,34 @@
 
   if (domain > max_domain || servers[domain] == MACH_PORT_NULL)
     {
-      char name[sizeof (_SERVERS_SOCKET) + 100];
-      char *np = &name[sizeof (name)];
-      *--np = '\0';
-      np = _itoa (domain, np, 10, 0);
-      *--np = '/';
-      np -= sizeof (_SERVERS_SOCKET) - 1;
-      memcpy (np, _SERVERS_SOCKET, sizeof (_SERVERS_SOCKET) - 1);
+      char *name;
+      char *np;
+
+      if (__asprintf (&name, "SERVERS_SOCKET_%d", domain) < 0)
+	goto out;
+
+      np = getenv (name);
+      __free (name);
+      name = NULL;
+
+      if (np == NULL)
+	{
+	  char *sock_servs;
+
+	  sock_servs = getenv ("SERVERS_SOCKET");
+	  if (sock_servs == NULL)
+	    sock_servs = _SERVERS_SOCKET;
+	  if (__asprintf (&name, "%s/%d", sock_servs, domain) < 0)
+	    goto out;
+
+	  np = name;
+	}
+
       server = __file_name_lookup (np, 0, 0);
       if (domain <= max_domain)
	servers[domain] = server;
+
+      __free (name); 
     }
   else
     server = servers[domain];
@@ -94,6 +112,7 @@
     /* If the server node is absent, we don't support that protocol.  */
     errno = EAFNOSUPPORT;
 
+out:
   __mutex_unlock (&lock);
   HURD_CRITICAL_END;


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