bug-hurd
[Top][All Lists]
Advanced

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

Re: The patch of glibc which allows the user to override the pfinet serv


From: zhengda
Subject: Re: The patch of glibc which allows the user to override the pfinet server
Date: Wed, 09 Jul 2008 14:02:18 +0200
User-agent: Thunderbird 2.0.0.14 (X11/20080421)

zhengda wrote:
Neal H. Walfield wrote:
If more network protocols are implemented, we have to provide more environment variables for the servers.

Or you use an environment variable that is based on a stem and the
protocol number.  So instead of SOCK_INET_SERV_PATH,
SOCK_SERV_%d_PATH.  Perhaps it is best to support both.  The number of
protocol is not increasing at a terribly fast rate.
The new version of the patch is below.
I wonder if I can use __snprintf(). The code in the original glibc doesn't use it.

Needed for glibc-2_7-branch

2008-06-30 Zheng Da <address@hidden>

* hurd/hurdsocks.c: _hurd_socket_server() searches in environment variables
     for the socket server insteading of using the default one.

--- glibc-2.7-old/hurd/hurdsock.c   2008-06-21 01:38:30.300000000 +0200
+++ glibc-2.7/hurd/hurdsock.c   2008-07-02 08:33:49.570000000 +0200
@@ -76,16 +76,30 @@

  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 sock_serv_env_name[30];
+      int len;
+      char *name = NULL;
+      char *np = NULL;
+     __snprintf (sock_serv_env_name, 30, "SOCK_SERV_%d_PATH", domain);
+      if ((np = getenv (sock_serv_env_name)) == NULL)
+        {
+          char *sock_serv_path = NULL;
+          sock_serv_path = getenv ("SOCK_SERV_PATH");
+          if (sock_serv_path == NULL)
+            sock_serv_path = _SERVERS_SOCKET;
+          len = strlen (sock_serv_path);
+          name = (char *)malloc (len + 100);
+          if (name == NULL)
+ __libc_fatal ("hurd: Can't allocate the socket server path\n");
+         np = name;
+         __snprintf (np, len + 100, "%s/%d", sock_serv_path, domain);
+        }
+
      server = __file_name_lookup (np, 0, 0);
      if (domain <= max_domain)
-      servers[domain] = server;
+        servers[domain] = server;
+      if (name)
+        free (name);
    }
  else
    server = servers[domain];

Best,
Zheng Da


I also write a SHELL script "runwithpfinet" to set the environment variables and run the command provided by the user. The environment variables used by glibc are SOCK_SERV_%d for overriding the specific socket server and SOCK_SERV for all default servers.

#!/bin/sh
SOCK_NUM=$1
shift
if [ $# -lt 1 ]; then
   echo "run command"
   exit 1
fi
export SOCK_SERV_2=$HOME/socket$SOCK_NUM/2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/storage/glibc-2.7/build-tree/hurd-i386-libc
echo $*
$*

The first argument of the script specifies the pfinet server, and the rest of arguments are command. It works in most of cases. but it doesn't work with "ping" when the user execute "runwithpfinet 1 ping www.google.com". "ping" still uses the default pfinet server. The main reason, I think, is that "ping" has a sticky bit. When the user runs it, it gets the privilege of root, and meanwhile, the environment variables are changed.
Does anyone has any ideas to fix the problem?

Best,
Zheng Da




reply via email to

[Prev in Thread] Current Thread [Next in Thread]