newlib/winsup/cygwin/exec.cc
Christopher Faylor 55fc91b9d6 * exceptions.cc (interruptible): Allocate slightly more space for directory
name check.  Windows 95 seems to null-terminate the directory otherwise.
(interrupt_on_return): Issue a fatal error if we can't find the caller's stack.
* spawn.cc (find_exec): Accept a path_conv argument rather than a buffer so
that the caller can find things out about a translated path.
(perhaps_suffix): Ditto.
(spawn_guts): Allocate path_conv stuff here so that we can find out stuff about
the translated path (this is work in progress).
* environ.cc (environ_init): Accept an as-yet unused argument indicating
whether we were invoked from a cygwin parent or not.
(winenv): Ditto.
(posify): Accept an argument indicating whether the path has already been
translated.
* dlfcn.cc (check_access): Provide a path_conv buffer to find_exec.
* exec.cc (sexecvpe): Ditto.
* path.cc (path_conv::check): Rename from path_conv::path_conv.
(mount_item::getmntent): Recognize "Cygwin executable" bit.
(symlink_info::check): Remove debugging statements.
* path.h (class path_conv): Add iscygexec method.  Rewrite constructor to call
"check" method to allow multiple operations on a path_conv variable.
* pinfo.cc (pinfo_init): Pass argument to environ_init.
* shared.h: Bump PROC_MAGIC.
* winsup.h: Reflect above changes to function arguments.
* include/sys/mount.h: Add MOUNT_CYGWIN_EXEC type.
2000-04-26 05:13:32 +00:00

205 lines
3.9 KiB
C++

/* exec.cc: exec system call support.
Copyright 1996, 1997, 1998, 2000 Cygnus Solutions.
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. */
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <process.h>
#include "winsup.h"
/* This is called _execve and not execve because the real execve is defined
in libc/posix/execve.c. It calls us. */
extern "C"
pid_t
_execve (const char *path, const char *const argv[], const char *const envp[])
{
static char *const empty_env[] = { 0 };
MALLOC_CHECK;
if (!envp)
envp = empty_env;
return _spawnve (NULL, _P_OVERLAY, path, argv, envp);
}
extern "C"
int
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;
return _execve (path, (char * const *) argv, *user_data->envptr);
}
extern "C"
int
execv (const char *path, char * const *argv)
{
MALLOC_CHECK;
return _execve (path, (char * const *) argv, *user_data->envptr);
}
/* the same as a standard exec() calls family, but with NT security support */
extern "C"
pid_t
sexecve (HANDLE hToken, const char *path, const char *const argv[],
const char *const envp[])
{
_spawnve (hToken, _P_OVERLAY, path, argv, envp);
return -1;
}
extern "C"
int
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;
return sexecve (hToken, path, (char * const *) argv, *user_data->envptr);
}
extern "C"
int
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);
}
extern "C"
int
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;
return sexecvpe (hToken, path, (const char * const *) argv,
*user_data->envptr);
}
extern "C"
int
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);
}
extern "C"
int
sexecv (HANDLE hToken, const char *path, const char * const *argv)
{
MALLOC_CHECK;
return sexecve (hToken, path, argv, *user_data->envptr);
}
extern "C"
int
sexecp (HANDLE hToken, const char *path, const char * const *argv)
{
MALLOC_CHECK;
return sexecvpe (hToken, path, argv, *user_data->envptr);
}
/*
* 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;
}
extern "C"
int
sexecvpe (HANDLE hToken, const char *file, const char * const *argv,
const char *const *envp)
{
path_conv buf;
MALLOC_CHECK;
return sexecve (hToken, find_exec (file, buf), argv, envp);
}