2000-02-17 20:38:33 +01:00
|
|
|
/* exec.cc: exec system call support.
|
|
|
|
|
2001-09-11 22:01:02 +02:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001 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"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <process.h>
|
2001-03-05 07:28:25 +01:00
|
|
|
#include "perprocess.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "fhandler.h"
|
|
|
|
#include "path.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "sigproc.h"
|
|
|
|
#include "pinfo.h"
|
|
|
|
#include "environ.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* This is called _execve and not execve because the real execve is defined
|
|
|
|
in libc/posix/execve.c. It calls us. */
|
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2000-08-25 21:52:04 +02:00
|
|
|
_execve (const char *path, char *const argv[], char *const envp[])
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
static char *const empty_env[] = { 0 };
|
|
|
|
MALLOC_CHECK;
|
|
|
|
if (!envp)
|
|
|
|
envp = empty_env;
|
|
|
|
return _spawnve (NULL, _P_OVERLAY, path, argv, envp);
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01: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;
|
2000-08-02 18:28:18 +02:00
|
|
|
return _execve (path, (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;
|
2000-08-02 18:28:18 +02:00
|
|
|
return _execve (path, (char * const *) argv, cur_environ ());
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the same as a standard exec() calls family, but with NT security support */
|
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" pid_t
|
2000-02-17 20:38:33 +01:00
|
|
|
sexecve (HANDLE hToken, const char *path, const char *const argv[],
|
|
|
|
const char *const envp[])
|
|
|
|
{
|
|
|
|
_spawnve (hToken, _P_OVERLAY, path, argv, envp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sexecl (HANDLE hToken, 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;
|
2000-08-02 18:28:18 +02:00
|
|
|
return sexecve (hToken, path, (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
|
|
|
sexecle (HANDLE hToken, const char *path, const char *arg0, ...)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
va_list args;
|
|
|
|
const char * const *envp;
|
|
|
|
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);
|
|
|
|
|
|
|
|
envp = va_arg (args, const char * const *);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
MALLOC_CHECK;
|
|
|
|
return sexecve(hToken, path, (char * const *) argv, (char * const *) envp);
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sexeclp (HANDLE hToken, 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;
|
2000-08-02 18:28:18 +02:00
|
|
|
return sexecvpe (hToken, path, (const 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
|
|
|
sexeclpe (HANDLE hToken, const char *path, const char *arg0, ...)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
va_list args;
|
|
|
|
const char * const *envp;
|
|
|
|
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);
|
|
|
|
|
|
|
|
envp = va_arg (args, const char * const *);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
MALLOC_CHECK;
|
|
|
|
return sexecvpe (hToken, path, argv, envp);
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sexecv (HANDLE hToken, const char *path, const char * const *argv)
|
|
|
|
{
|
|
|
|
MALLOC_CHECK;
|
2000-08-02 18:28:18 +02:00
|
|
|
return sexecve (hToken, path, 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
|
|
|
sexecp (HANDLE hToken, const char *path, const char * const *argv)
|
|
|
|
{
|
|
|
|
MALLOC_CHECK;
|
2000-08-02 18:28:18 +02:00
|
|
|
return sexecvpe (hToken, path, argv, cur_environ ());
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy string, until c or <nul> is encountered.
|
|
|
|
* NUL-terminate the destination string (s1).
|
|
|
|
* Return pointer to terminating byte in dst string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char * __stdcall
|
|
|
|
strccpy (char *s1, const char **s2, char c)
|
|
|
|
{
|
|
|
|
while (**s2 && **s2 != c)
|
|
|
|
*s1++ = *((*s2)++);
|
|
|
|
*s1 = 0;
|
|
|
|
|
|
|
|
MALLOC_CHECK;
|
|
|
|
return s1;
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:39:22 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sexecvpe (HANDLE hToken, const char *file, const char * const *argv,
|
|
|
|
const char *const *envp)
|
|
|
|
{
|
2000-04-26 07:13:32 +02:00
|
|
|
path_conv buf;
|
2000-02-17 20:38:33 +01:00
|
|
|
MALLOC_CHECK;
|
|
|
|
return sexecve (hToken, find_exec (file, buf), argv, envp);
|
|
|
|
}
|
2001-10-22 20:39:22 +02:00
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
execvp (const char *path, char * const *argv)
|
|
|
|
{
|
|
|
|
path_conv buf;
|
|
|
|
return execv (find_exec (path, buf), argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
execvpe (const char *path, char * const *argv, char *const *envp)
|
|
|
|
{
|
|
|
|
path_conv buf;
|
|
|
|
return execve (find_exec (path, buf), argv, envp);
|
|
|
|
}
|