OSDN Git Service

Few changes to pppd for VPN.
authorChia-chi Yeh <chiachi@android.com>
Mon, 15 Jun 2009 20:12:02 +0000 (04:12 +0800)
committerChia-chi Yeh <chiachi@android.com>
Fri, 19 Jun 2009 05:35:23 +0000 (13:35 +0800)
1. Remove TARGET_OUT_OPTIONAL_EXECUTABLES from Android.mk
   since pppd is now required by VPN, no longer optinoal.
2. Avoid creating pid files.
3. Use linkname as a suffix of program names which allows
   different users to run different set of scripts. E.g.
   if linkname is "vpn", "/etc/ppp/ip-up-vpn" is executed.

pppd/Android.mk
pppd/main.c

index 4686fea..dcd5f8d 100644 (file)
@@ -34,7 +34,6 @@ LOCAL_C_INCLUDES := \
 
 LOCAL_CFLAGS := -DANDROID_CHANGES -DCHAPMS=1 -DMPPE=1 -Iexternal/openssl/include
 
-LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
 LOCAL_MODULE:= pppd
 
 include $(BUILD_EXECUTABLE)
index 8515c1e..efcc0e2 100644 (file)
@@ -825,6 +825,7 @@ static void
 create_pidfile(pid)
     int pid;
 {
+#ifndef ANDROID_CHANGES
     FILE *pidfile;
 
     slprintf(pidfilename, sizeof(pidfilename), "%s%s.pid",
@@ -836,12 +837,14 @@ create_pidfile(pid)
        error("Failed to create pid file %s: %m", pidfilename);
        pidfilename[0] = 0;
     }
+#endif
 }
 
 void
 create_linkpidfile(pid)
     int pid;
 {
+#ifndef ANDROID_CHANGES
     FILE *pidfile;
 
     if (linkname[0] == 0)
@@ -858,6 +861,7 @@ create_linkpidfile(pid)
        error("Failed to create pid file %s: %m", linkpidfile);
        linkpidfile[0] = 0;
     }
+#endif
 }
 
 /*
@@ -865,12 +869,14 @@ create_linkpidfile(pid)
  */
 void remove_pidfiles()
 {
+#ifndef ANDROID_CHANGES
     if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT)
        warn("unable to delete pid file %s: %m", pidfilename);
     pidfilename[0] = 0;
     if (linkpidfile[0] != 0 && unlink(linkpidfile) < 0 && errno != ENOENT)
        warn("unable to delete pid file %s: %m", linkpidfile);
     linkpidfile[0] = 0;
+#endif
 }
 
 /*
@@ -1636,6 +1642,21 @@ run_program(prog, args, must_exist, done, arg)
     int pid;
     struct stat sbuf;
 
+#ifdef ANDROID_CHANGES
+    /* Originally linkname is used to create named pid files, which is
+    * meaningless to android. Here we use it as a suffix of program names,
+    * so different users can run their own program by specifying it. For
+    * example, "/etc/ppp/ip-up-vpn" will be executed when IPCP is up and
+    * linkname is "vpn". Note that "/" is not allowed for security reasons. */
+    char file[MAXPATHLEN];
+
+    if (linkname[0] && !strchr(linkname, '/')) {
+        snprintf(file, MAXPATHLEN, "%s-%s", prog, linkname);
+        file[MAXPATHLEN - 1] = '\0';
+        prog = file;
+    }
+#endif
+
     /*
      * First check if the file exists and is executable.
      * We don't use access() because that would use the