Samuel Thibault wrote:
zhengda, le Sun 17 Aug 2008 13:40:59 +0200, a écrit :
I wonder how I return ENOMEM? Does asprintf() write the errno itself?
Yes.
Should the function returns immediately after __asprintf() returns error?
It has to clean its mess first of course.
Hello,
Here is the patch.
Since my mail client always makes some mess in the indentation, I put it
in the attachment.
I hope it's OK this time:)
Zheng Da
Needed for glibc-2_7-branch
2008-06-30 Zheng Da <[EMAIL PROTECTED]>
* hurd/hurdsocks.c (_hurd_socket_server): Searches environment variables
for the socket server insteading of using the default one.
(SOCK_SERV_%d, SOCK_SERV_DIR): The environment variables that contains
the locations of the socket server.
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-17 08:46:05.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, "SOCK_SERV_%d", domain) < 0)
+ goto out;
+
+ np = getenv (name);
+ __free (name);
+ name = NULL;
+
+ if (np == NULL)
+ {
+ char *sock_servs;
+
+ sock_servs = getenv ("SOCK_SERV_DIR");
+ 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;
+ 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;