2000-02-17 20:38:33 +01:00
|
|
|
/* exec.cc: exec system call support.
|
|
|
|
|
2013-01-21 05:38:31 +01:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008,
|
2015-02-11 14:15:59 +01:00
|
|
|
2009, 2011, 2012, 2015 Red Hat, Inc.
|
2000-02-17 20:38:33 +01: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. */
|
|
|
|
|
2000-08-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2012-02-07 18:15:07 +01:00
|
|
|
#include <process.h>
|
2005-01-12 23:40:46 +01:00
|
|
|
#include "cygerrno.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "path.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "environ.h"
|
2009-09-26 23:01:10 +02:00
|
|
|
#include "sync.h"
|
|
|
|
#include "fhandler.h"
|
|
|
|
#include "dtable.h"
|
2011-01-20 12:09:21 +01:00
|
|
|
#include "pinfo.h"
|
2009-09-26 23:01:10 +02:00
|
|
|
#include "cygheap.h"
|
2011-01-19 10:15:17 +01:00
|
|
|
#include "winf.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2011-01-19 11:28:39 +01:00
|
|
|
execl (const char *path, const char *arg0, ...)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-01-19 11:28:39 +01:00
|
|
|
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);
|
2000-02-17 20:38:33 +01:00
|
|
|
MALLOC_CHECK;
|
2011-01-19 11:28:39 +01:00
|
|
|
return spawnve (_P_OVERLAY, path, (char * const *) argv, cur_environ ());
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2011-01-19 11:28:39 +01:00
|
|
|
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);
|
|
|
|
}
|
2002-10-21 03:00:58 +02:00
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2011-01-19 11:28:39 +01:00
|
|
|
execlp (const char *file, const char *arg0, ...)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
va_list args;
|
|
|
|
const char *argv[1024];
|
2011-01-19 11:28:39 +01:00
|
|
|
path_conv buf;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
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;
|
2011-01-19 11:30:39 +01:00
|
|
|
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
2015-02-11 14:15:59 +01:00
|
|
|
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
2011-01-19 11:28:39 +01:00
|
|
|
(char * const *) argv, cur_environ ());
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
execv (const char *path, char * const *argv)
|
|
|
|
{
|
|
|
|
MALLOC_CHECK;
|
2011-01-19 11:28:39 +01:00
|
|
|
return spawnve (_P_OVERLAY, path, argv, cur_environ ());
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2011-01-19 11:28:39 +01:00
|
|
|
extern "C" int
|
|
|
|
execve (const char *path, char *const argv[], char *const envp[])
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-01-19 11:28:39 +01:00
|
|
|
MALLOC_CHECK;
|
|
|
|
return spawnve (_P_OVERLAY, path, argv, envp);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2013-11-26 18:11:09 +01:00
|
|
|
EXPORT_ALIAS (execve, _execve) /* For newlib */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2011-01-19 11:28:39 +01:00
|
|
|
execvp (const char *file, char * const *argv)
|
2001-10-22 20:39:22 +02:00
|
|
|
{
|
|
|
|
path_conv buf;
|
2011-01-19 11:28:39 +01:00
|
|
|
|
|
|
|
MALLOC_CHECK;
|
2011-01-19 10:15:17 +01:00
|
|
|
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
2015-02-11 14:15:59 +01:00
|
|
|
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
2011-01-19 10:15:17 +01:00
|
|
|
argv, cur_environ ());
|
2001-10-22 20:39:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
2011-01-19 11:28:39 +01:00
|
|
|
execvpe (const char *file, char * const *argv, char *const *envp)
|
2001-10-22 20:39:22 +02:00
|
|
|
{
|
|
|
|
path_conv buf;
|
2011-01-19 11:28:39 +01:00
|
|
|
|
|
|
|
MALLOC_CHECK;
|
2011-01-19 10:15:17 +01:00
|
|
|
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
2015-02-11 14:15:59 +01:00
|
|
|
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
2011-01-19 10:15:17 +01:00
|
|
|
argv, envp);
|
2001-10-22 20:39:22 +02:00
|
|
|
}
|
2009-09-26 23:01:10 +02: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;
|
|
|
|
}
|
2011-01-19 11:28:39 +01:00
|
|
|
|
|
|
|
MALLOC_CHECK;
|
|
|
|
return spawnve (_P_OVERLAY, cfd->pc.get_win32 (), argv, envp);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" pid_t
|
|
|
|
sexecve_is_bad ()
|
|
|
|
{
|
|
|
|
set_errno (ENOSYS);
|
|
|
|
return 0;
|
2009-09-26 23:01:10 +02:00
|
|
|
}
|