2000-02-18 03:38:33 +08:00
|
|
|
/* exec.cc: exec system call support.
|
|
|
|
|
2009-09-27 05:01:10 +08:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2009 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2002-10-21 09:00:58 +08:00
|
|
|
#define _execve __FOO_execve_
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <process.h>
|
2005-01-13 06:40:46 +08:00
|
|
|
#include "cygerrno.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "path.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "environ.h"
|
2009-09-27 05:01:10 +08:00
|
|
|
#include "sync.h"
|
|
|
|
#include "fhandler.h"
|
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2002-10-21 09:00:58 +08:00
|
|
|
#undef _execve
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* This is called _execve and not execve because the real execve is defined
|
|
|
|
in libc/posix/execve.c. It calls us. */
|
|
|
|
|
2001-10-23 02:39:22 +08:00
|
|
|
extern "C" int
|
2002-10-21 09:00:58 +08:00
|
|
|
execve (const char *path, char *const argv[], char *const envp[])
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
static char *const empty_env[] = { 0 };
|
|
|
|
MALLOC_CHECK;
|
|
|
|
if (!envp)
|
|
|
|
envp = empty_env;
|
2002-06-11 10:08:00 +08:00
|
|
|
return spawnve (_P_OVERLAY, path, argv, envp);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2004-09-10 16:30:51 +08:00
|
|
|
EXPORT_ALIAS (execve, _execve)
|
2002-10-21 09:00:58 +08:00
|
|
|
|
2001-10-23 02:39:22 +08:00
|
|
|
extern "C" int
|
2000-02-18 03:38:33 +08:00
|
|
|
execl (const char *path, const char *arg0, ...)
|
|
|
|
{
|
|
|
|
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;
|
2002-10-21 09:00:58 +08:00
|
|
|
return execve (path, (char * const *) argv, cur_environ ());
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-10-23 02:39:22 +08:00
|
|
|
extern "C" int
|
2000-02-18 03:38:33 +08:00
|
|
|
execv (const char *path, char * const *argv)
|
|
|
|
{
|
|
|
|
MALLOC_CHECK;
|
2002-10-21 09:00:58 +08:00
|
|
|
return execve (path, (char * const *) argv, cur_environ ());
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-10-23 02:39:22 +08:00
|
|
|
extern "C" pid_t
|
2002-06-11 10:08:00 +08:00
|
|
|
sexecve_is_bad ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-06-11 10:08:00 +08:00
|
|
|
set_errno (ENOSYS);
|
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2006-02-16 06:11:13 +08:00
|
|
|
/* Copy string, until c or <nul> is encountered.
|
|
|
|
NUL-terminate the destination string (s1).
|
|
|
|
Return pointer to terminating byte in dst string. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
char * __stdcall
|
|
|
|
strccpy (char *s1, const char **s2, char c)
|
|
|
|
{
|
|
|
|
while (**s2 && **s2 != c)
|
|
|
|
*s1++ = *((*s2)++);
|
|
|
|
*s1 = 0;
|
|
|
|
|
|
|
|
MALLOC_CHECK;
|
|
|
|
return s1;
|
|
|
|
}
|
|
|
|
|
2001-10-23 02:39:22 +08:00
|
|
|
extern "C" int
|
|
|
|
execvp (const char *path, char * const *argv)
|
|
|
|
{
|
|
|
|
path_conv buf;
|
2009-12-21 23:16:28 +08:00
|
|
|
return execv (find_exec (path, buf, "PATH=", FE_NNF) ?: "", argv);
|
2001-10-23 02:39:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
execvpe (const char *path, char * const *argv, char *const *envp)
|
|
|
|
{
|
|
|
|
path_conv buf;
|
2009-12-21 23:16:28 +08:00
|
|
|
return execve (find_exec (path, buf, "PATH=", FE_NNF) ?: "", argv, envp);
|
2001-10-23 02:39:22 +08:00
|
|
|
}
|
2009-09-27 05:01:10 +08:00
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
fexecve (int fd, char * const *argv, char *const *envp)
|
|
|
|
{
|
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
{
|
|
|
|
syscall_printf ("-1 = fexecve (%d, %p, %p)", fd, argv, envp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return execve (cfd->pc.get_win32 (), argv, envp);
|
|
|
|
}
|