OSDN Git Service

* exec.cc: Rearrange functions in alphabetical order.
authorcorinna <corinna>
Wed, 19 Jan 2011 10:28:39 +0000 (10:28 +0000)
committercorinna <corinna>
Wed, 19 Jan 2011 10:28:39 +0000 (10:28 +0000)
(_execve): Drop temporary define and drop export alias.
(execl): Call spawnve.
(execle): New function.
(execlp): New function.
(execv): Call spawnve.
(execve): Drop converting NULL envp to emtpy envp.
(execvp): Call spawnve.
(execvpe): Drop converting NULL envp to emtpy envp.  Call spawnve.
(fexecve): Call spawnve.
* spawn.cc (spawnve): Convert NULL envp to emtpy envp.  Remove outdated
comment.
(spawnlp): Call spawnve.
(spawnlpe): Ditto.
(spawnvp): Ditto.
(spawnvpe): Fix formatting.

winsup/cygwin/ChangeLog
winsup/cygwin/exec.cc
winsup/cygwin/spawn.cc

index 0461fdf..1cdcd7e 100644 (file)
@@ -1,5 +1,24 @@
 2011-01-19  Corinna Vinschen  <corinna@vinschen.de>
 
+       * exec.cc: Rearrange functions in alphabetical order.
+       (_execve): Drop temporary define and drop export alias.
+       (execl): Call spawnve.
+       (execle): New function.
+       (execlp): New function.
+       (execv): Call spawnve.
+       (execve): Drop converting NULL envp to emtpy envp.
+       (execvp): Call spawnve.
+       (execvpe): Drop converting NULL envp to emtpy envp.  Call spawnve.
+       (fexecve): Call spawnve.
+       * spawn.cc (spawnve): Convert NULL envp to emtpy envp.  Remove outdated
+       comment.
+       (spawnlp): Call spawnve.
+       (spawnlpe): Ditto.
+       (spawnvp): Ditto.
+       (spawnvpe): Fix formatting.
+
+2011-01-19  Corinna Vinschen  <corinna@vinschen.de>
+
        * exec.cc (strccpy): Move function from here...
        * strfuncs.cc (strccpy): ...to here.
        * string.h (strccpy): Declare.
index 327e86a..4ca232c 100644 (file)
@@ -8,7 +8,6 @@ This software is a copyrighted work licensed under the terms of the
 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
 details. */
 
-#define _execve __FOO_execve_
 #include "winsup.h"
 #include <process.h>
 #include "cygerrno.h"
@@ -19,29 +18,52 @@ details. */
 #include "dtable.h"
 #include "cygheap.h"
 #include "winf.h"
-#undef _execve
-
-/* This is called _execve and not execve because the real execve is defined
-   in libc/posix/execve.c.  It calls us.  */
 
 extern "C" int
-execve (const char *path, char *const argv[], char *const envp[])
+execl (const char *path, const char *arg0, ...)
 {
-  static char *const empty_env[] = { 0 };
+  int i;
+  va_list args;
+  const char *argv[1024];
+
+  va_start (args, arg0);
+  argv[0] = arg0;
+  i = 1;
+  do
+      argv[i] = va_arg (args, const char *);
+  while (argv[i++] != NULL);
+  va_end (args);
   MALLOC_CHECK;
-  if (!envp)
-    envp = empty_env;
-  return spawnve (_P_OVERLAY, path, argv, envp);
+  return spawnve (_P_OVERLAY, path, (char * const  *) argv, cur_environ ());
 }
 
-EXPORT_ALIAS (execve, _execve)
+extern "C" int
+execle (const char *path, const char *arg0, ...)
+{
+  int i;
+  va_list args;
+  const char *argv[1024];
+  const char * const *envp;
+
+  va_start (args, arg0);
+  argv[0] = arg0;
+  i = 1;
+  do
+      argv[i] = va_arg (args, const char *);
+  while (argv[i++] != NULL);
+  envp = va_arg (args, const char * const *);
+  va_end (args);
+  MALLOC_CHECK;
+  return spawnve (_P_OVERLAY, path, (char * const  *) argv, envp);
+}
 
 extern "C" int
-execl (const char *path, const char *arg0, ...)
+execlp (const char *file, const char *arg0, ...)
 {
   int i;
   va_list args;
   const char *argv[1024];
+  path_conv buf;
 
   va_start (args, arg0);
   argv[0] = arg0;
@@ -51,42 +73,43 @@ execl (const char *path, const char *arg0, ...)
   while (argv[i++] != NULL);
   va_end (args);
   MALLOC_CHECK;
-  return execve (path, (char * const  *) argv, cur_environ ());
+  return spawnve (_P_OVERLAY, find_exec (file, buf, "PATH=", FE_NNF) ?: "",
+                 (char * const  *) argv, cur_environ ());
 }
 
 extern "C" int
 execv (const char *path, char * const *argv)
 {
   MALLOC_CHECK;
-  return execve (path, (char * const *) argv, cur_environ ());
+  return spawnve (_P_OVERLAY, path, argv, cur_environ ());
 }
 
-extern "C" pid_t
-sexecve_is_bad ()
+extern "C" int
+execve (const char *path, char *const argv[], char *const envp[])
 {
-  set_errno (ENOSYS);
-  return 0;
+  MALLOC_CHECK;
+  return spawnve (_P_OVERLAY, path, argv, envp);
 }
 
 extern "C" int
-execvp (const char *path, char * const *argv)
+execvp (const char *file, char * const *argv)
 {
   path_conv buf;
+
+  MALLOC_CHECK;
   return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
-                 find_exec (path, buf, "PATH=", FE_NNF) ?: "",
+                 find_exec (file, buf, "PATH=", FE_NNF) ?: "",
                  argv, cur_environ ());
 }
 
 extern "C" int
-execvpe (const char *path, char * const *argv, char *const *envp)
+execvpe (const char *file, char * const *argv, char *const *envp)
 {
-  static char *const empty_env[] = { 0 };
-  MALLOC_CHECK;
-  if (!envp)
-    envp = empty_env;
   path_conv buf;
+
+  MALLOC_CHECK;
   return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
-                 find_exec (path, buf, "PATH=", FE_NNF) ?: "",
+                 find_exec (file, buf, "PATH=", FE_NNF) ?: "",
                  argv, envp);
 }
 
@@ -99,5 +122,14 @@ fexecve (int fd, char * const *argv, char *const *envp)
       syscall_printf ("-1 = fexecve (%d, %p, %p)", fd, argv, envp);
       return -1;
     }
-  return execve (cfd->pc.get_win32 (), argv, envp);
+
+  MALLOC_CHECK;
+  return spawnve (_P_OVERLAY, cfd->pc.get_win32 (), argv, envp);
+}
+
+extern "C" pid_t
+sexecve_is_bad ()
+{
+  set_errno (ENOSYS);
+  return 0;
 }
index 90ba65e..4575d7b 100644 (file)
@@ -854,6 +854,8 @@ extern "C" int
 spawnve (int mode, const char *path, const char *const *argv,
        const char *const *envp)
 {
+  static char *const empty_env[] = { NULL };
+
   int ret;
 #ifdef NEWVFORK
   vfork_save *vf = vfork_storage.val ();
@@ -866,11 +868,12 @@ spawnve (int mode, const char *path, const char *const *argv,
 
   syscall_printf ("spawnve (%s, %s, %x)", path, argv[0], envp);
 
+  if (!envp)
+    envp = empty_env;
+
   switch (_P_MODE (mode))
     {
     case _P_OVERLAY:
-      /* We do not pass _P_SEARCH_PATH here. execve doesn't search PATH.*/
-      /* Just act as an exec if _P_OVERLAY set. */
       spawn_guts (path, argv, envp, mode);
       /* Errno should be set by spawn_guts.  */
       ret = -1;
@@ -949,11 +952,12 @@ spawnle (int mode, const char *path, const char *arg0, ...)
 }
 
 extern "C" int
-spawnlp (int mode, const char *path, const char *arg0, ...)
+spawnlp (int mode, const char *file, const char *arg0, ...)
 {
   int i;
   va_list args;
   const char *argv[256];
+  path_conv buf;
 
   va_start (args, arg0);
   argv[0] = arg0;
@@ -965,16 +969,18 @@ spawnlp (int mode, const char *path, const char *arg0, ...)
 
   va_end (args);
 
-  return spawnvpe (mode, path, (char * const *) argv, cur_environ ());
+  return spawnve (mode, find_exec (file, buf), (char * const *) argv,
+                 cur_environ ());
 }
 
 extern "C" int
-spawnlpe (int mode, const char *path, const char *arg0, ...)
+spawnlpe (int mode, const char *file, const char *arg0, ...)
 {
   int i;
   va_list args;
   const char * const *envp;
   const char *argv[256];
+  path_conv buf;
 
   va_start (args, arg0);
   argv[0] = arg0;
@@ -987,7 +993,7 @@ spawnlpe (int mode, const char *path, const char *arg0, ...)
   envp = va_arg (args, const char * const *);
   va_end (args);
 
-  return spawnvpe (mode, path, (char * const *) argv, envp);
+  return spawnve (mode, find_exec (file, buf), (char * const *) argv, envp);
 }
 
 extern "C" int
@@ -997,14 +1003,15 @@ spawnv (int mode, const char *path, const char * const *argv)
 }
 
 extern "C" int
-spawnvp (int mode, const char *path, const char * const *argv)
+spawnvp (int mode, const char *file, const char * const *argv)
 {
-  return spawnvpe (mode, path, argv, cur_environ ());
+  path_conv buf;
+  return spawnve (mode, find_exec (file, buf), argv, cur_environ ());
 }
 
 extern "C" int
 spawnvpe (int mode, const char *file, const char * const *argv,
-                                          const char * const *envp)
+         const char * const *envp)
 {
   path_conv buf;
   return spawnve (mode | _P_PATH_TYPE_EXEC, find_exec (file, buf), argv, envp);