2000-02-18 03:38:33 +08:00
|
|
|
/* external.cc: Interface to Cygwin internals from external programs.
|
|
|
|
|
2006-10-23 03:31:33 +08:00
|
|
|
Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
2009-01-16 20:17:28 +08:00
|
|
|
2006, 2007, 2008, 2009 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
Written by Christopher Faylor <cgf@cygnus.com>
|
|
|
|
|
|
|
|
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 "winsup.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "sigproc.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2000-09-08 00:23:51 +08:00
|
|
|
#include "shared_info.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "cygwin_version.h"
|
2001-10-25 05:56:54 +08:00
|
|
|
#include "cygerrno.h"
|
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2001-10-25 05:56:54 +08:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2002-01-29 10:02:03 +08:00
|
|
|
#include "heap.h"
|
2003-12-24 00:26:31 +08:00
|
|
|
#include "cygtls.h"
|
2005-05-09 09:19:38 +08:00
|
|
|
#include "child_info.h"
|
2006-02-03 03:55:45 +08:00
|
|
|
#include "environ.h"
|
2008-11-26 18:18:10 +08:00
|
|
|
#include "cygserver_setpwd.h"
|
2005-11-29 06:32:29 +08:00
|
|
|
#include <unistd.h>
|
2006-02-03 03:55:45 +08:00
|
|
|
#include <stdlib.h>
|
2008-03-07 19:24:51 +08:00
|
|
|
#include <wchar.h>
|
2008-07-30 20:10:20 +08:00
|
|
|
#include <iptypes.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-05-09 09:19:38 +08:00
|
|
|
child_info *get_cygwin_startup_info ();
|
2009-10-07 05:51:17 +08:00
|
|
|
static void exit_process (UINT, bool) __attribute__((noreturn));
|
2005-03-23 03:00:31 +08:00
|
|
|
|
2005-05-19 09:25:20 +08:00
|
|
|
static winpids pids;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
static external_pinfo *
|
2000-07-30 00:24:59 +08:00
|
|
|
fillout_pinfo (pid_t pid, int winpid)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
BOOL nextpid;
|
|
|
|
static external_pinfo ep;
|
2008-02-16 17:37:58 +08:00
|
|
|
static char ep_progname_long_buf[NT_MAX_PATH];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if ((nextpid = !!(pid & CW_NEXTPID)))
|
|
|
|
pid ^= CW_NEXTPID;
|
2000-07-30 00:24:59 +08:00
|
|
|
|
|
|
|
|
2001-10-08 12:26:27 +08:00
|
|
|
static unsigned int i;
|
2000-09-13 10:35:05 +08:00
|
|
|
if (!pids.npids || !nextpid)
|
2001-10-08 12:26:27 +08:00
|
|
|
{
|
2002-11-29 15:05:26 +08:00
|
|
|
pids.set (winpid);
|
2001-10-08 12:26:27 +08:00
|
|
|
i = 0;
|
|
|
|
}
|
2000-07-30 00:24:59 +08:00
|
|
|
|
2000-08-26 09:36:20 +08:00
|
|
|
if (!pid)
|
|
|
|
i = 0;
|
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
memset (&ep, 0, sizeof ep);
|
2000-11-05 14:42:23 +08:00
|
|
|
while (i < pids.npids)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-11-05 14:42:23 +08:00
|
|
|
DWORD thispid = pids.winpid (i);
|
|
|
|
_pinfo *p = pids[i];
|
|
|
|
i++;
|
2000-07-30 00:24:59 +08:00
|
|
|
|
2000-08-26 09:36:20 +08:00
|
|
|
if (!p)
|
|
|
|
{
|
2000-11-05 14:42:23 +08:00
|
|
|
if (!nextpid && thispid != (DWORD) pid)
|
2000-08-26 09:36:20 +08:00
|
|
|
continue;
|
2001-05-12 05:01:44 +08:00
|
|
|
ep.pid = cygwin_pid (thispid);
|
|
|
|
ep.dwProcessId = thispid;
|
2000-08-26 09:36:20 +08:00
|
|
|
ep.process_state = PID_IN_USE;
|
|
|
|
ep.ctty = -1;
|
2001-03-18 10:49:29 +08:00
|
|
|
break;
|
2000-08-26 09:36:20 +08:00
|
|
|
}
|
2001-03-18 10:49:29 +08:00
|
|
|
else if (nextpid || p->pid == pid || (winpid && thispid == (DWORD) pid))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-29 07:48:28 +08:00
|
|
|
ep.ctty = p->ctty;
|
2000-08-26 09:36:20 +08:00
|
|
|
ep.pid = p->pid;
|
|
|
|
ep.ppid = p->ppid;
|
|
|
|
ep.dwProcessId = p->dwProcessId;
|
|
|
|
ep.uid = p->uid;
|
|
|
|
ep.gid = p->gid;
|
|
|
|
ep.pgid = p->pgid;
|
|
|
|
ep.sid = p->sid;
|
2000-11-14 13:53:32 +08:00
|
|
|
ep.umask = 0;
|
2000-08-26 09:36:20 +08:00
|
|
|
ep.start_time = p->start_time;
|
|
|
|
ep.rusage_self = p->rusage_self;
|
|
|
|
ep.rusage_children = p->rusage_children;
|
2007-12-07 02:24:06 +08:00
|
|
|
ep.progname[0] = '\0';
|
|
|
|
strncat (ep.progname, p->progname, MAX_PATH - 1);
|
2000-08-26 09:36:20 +08:00
|
|
|
ep.strace_mask = 0;
|
2002-05-30 05:00:55 +08:00
|
|
|
ep.version = EXTERNAL_PINFO_VERSION;
|
2000-08-26 09:36:20 +08:00
|
|
|
|
|
|
|
ep.process_state = p->process_state;
|
2002-05-29 23:04:29 +08:00
|
|
|
|
|
|
|
ep.uid32 = p->uid;
|
|
|
|
ep.gid32 = p->gid;
|
2007-12-07 02:24:06 +08:00
|
|
|
|
2008-02-16 17:37:58 +08:00
|
|
|
ep.progname_long = ep_progname_long_buf;
|
2007-12-07 02:24:06 +08:00
|
|
|
strcpy (ep.progname_long, p->progname);
|
2001-03-18 10:49:29 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
if (!ep.pid)
|
|
|
|
{
|
2000-08-26 09:36:20 +08:00
|
|
|
i = 0;
|
2000-07-30 00:24:59 +08:00
|
|
|
pids.reset ();
|
|
|
|
return 0;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
return &ep;
|
|
|
|
}
|
|
|
|
|
2007-10-31 21:23:33 +08:00
|
|
|
static inline DWORD
|
2000-11-09 04:36:37 +08:00
|
|
|
get_cygdrive_info (char *user, char *system, char *user_flags,
|
2001-09-08 05:32:07 +08:00
|
|
|
char *system_flags)
|
2000-07-29 06:33:43 +08:00
|
|
|
{
|
2001-01-28 13:51:15 +08:00
|
|
|
int res = mount_table->get_cygdrive_info (user, system, user_flags,
|
|
|
|
system_flags);
|
2000-07-29 06:33:43 +08:00
|
|
|
return (res == ERROR_SUCCESS) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2003-04-03 16:04:41 +08:00
|
|
|
static DWORD
|
|
|
|
check_ntsec (const char *filename)
|
|
|
|
{
|
2003-04-03 16:18:43 +08:00
|
|
|
if (!filename)
|
2008-07-15 04:22:03 +08:00
|
|
|
return true;
|
2003-04-03 16:04:41 +08:00
|
|
|
path_conv pc (filename);
|
2008-07-15 04:22:03 +08:00
|
|
|
return pc.has_acls ();
|
2003-04-03 16:04:41 +08:00
|
|
|
}
|
|
|
|
|
2006-02-03 03:55:45 +08:00
|
|
|
/* Copy cygwin environment variables to the Windows environment. */
|
|
|
|
static void
|
2006-02-11 01:22:34 +08:00
|
|
|
sync_winenv ()
|
2006-02-03 03:55:45 +08:00
|
|
|
{
|
2006-02-11 01:22:34 +08:00
|
|
|
int unused_envc;
|
2008-03-07 19:24:51 +08:00
|
|
|
PWCHAR envblock = NULL;
|
2007-01-12 23:40:13 +08:00
|
|
|
char **envp = build_env (cur_environ (), envblock, unused_envc, false);
|
2008-03-07 19:24:51 +08:00
|
|
|
PWCHAR p = envblock;
|
2006-02-03 03:55:45 +08:00
|
|
|
|
2006-02-11 01:22:34 +08:00
|
|
|
if (envp)
|
2006-02-03 03:55:45 +08:00
|
|
|
{
|
2006-02-11 01:22:34 +08:00
|
|
|
for (char **e = envp; *e; e++)
|
|
|
|
cfree (*e);
|
|
|
|
cfree (envp);
|
2006-02-03 03:55:45 +08:00
|
|
|
}
|
2006-02-11 01:22:34 +08:00
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
while (*p)
|
|
|
|
{
|
2008-03-07 19:24:51 +08:00
|
|
|
PWCHAR eq = wcschr (p, L'=');
|
2006-02-11 01:22:34 +08:00
|
|
|
if (eq)
|
|
|
|
{
|
2008-03-07 19:24:51 +08:00
|
|
|
*eq = L'\0';
|
|
|
|
SetEnvironmentVariableW (p, ++eq);
|
2006-02-11 01:22:34 +08:00
|
|
|
p = eq;
|
|
|
|
}
|
2008-03-07 19:24:51 +08:00
|
|
|
p = wcschr (p, L'\0') + 1;
|
2006-02-11 01:22:34 +08:00
|
|
|
}
|
|
|
|
free (envblock);
|
2006-02-03 03:55:45 +08:00
|
|
|
}
|
|
|
|
|
2009-10-07 05:51:17 +08:00
|
|
|
/*
|
|
|
|
* Cygwin-specific wrapper for win32 ExitProcess and TerminateProcess.
|
|
|
|
* It ensures that the correct exit code, derived from the specified
|
|
|
|
* status value, will be made available to this process's parent (if
|
|
|
|
* that parent is also a cygwin process). If useTerminateProcess is
|
|
|
|
* true, then TerminateProcess(GetCurrentProcess(),...) will be used;
|
|
|
|
* otherwise, ExitProcess(...) is called.
|
|
|
|
*
|
|
|
|
* Used by startup code for cygwin processes which is linked statically
|
|
|
|
* into applications, and is not part of the cygwin DLL -- which is why
|
|
|
|
* this interface is exposed. "Normal" programs should use ANSI exit(),
|
|
|
|
* ANSI abort(), or POSIX _exit(), rather than this function -- because
|
|
|
|
* calling ExitProcess or TerminateProcess, even through this wrapper,
|
|
|
|
* skips much of the cygwin process cleanup code.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
exit_process (UINT status, bool useTerminateProcess)
|
|
|
|
{
|
|
|
|
pid_t pid = getpid ();
|
|
|
|
external_pinfo * ep = fillout_pinfo (pid, 1);
|
|
|
|
DWORD dwpid = ep ? ep->dwProcessId : pid;
|
|
|
|
pinfo p (pid, PID_MAP_RW);
|
|
|
|
if ((dwpid == GetCurrentProcessId()) && (p->pid == ep->pid))
|
|
|
|
p.set_exit_code ((DWORD)status);
|
|
|
|
if (useTerminateProcess)
|
|
|
|
TerminateProcess (GetCurrentProcess(), status);
|
|
|
|
/* avoid 'else' clause to silence warning */
|
|
|
|
ExitProcess (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-28 22:21:40 +08:00
|
|
|
extern "C" unsigned long
|
2000-02-18 03:38:33 +08:00
|
|
|
cygwin_internal (cygwin_getinfo_types t, ...)
|
|
|
|
{
|
|
|
|
va_list arg;
|
2009-10-14 12:17:05 +08:00
|
|
|
unsigned long res = -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
va_start (arg, t);
|
|
|
|
|
|
|
|
switch (t)
|
|
|
|
{
|
|
|
|
case CW_LOCK_PINFO:
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 1;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
case CW_UNLOCK_PINFO:
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 1;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
case CW_GETTHREADNAME:
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (DWORD) cygthread::name (va_arg (arg, DWORD));
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
case CW_SETTHREADNAME:
|
|
|
|
{
|
2002-08-02 00:20:31 +08:00
|
|
|
set_errno (ENOSYS);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
case CW_GETPINFO:
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (DWORD) fillout_pinfo (va_arg (arg, DWORD), 0);
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
case CW_GETVERSIONINFO:
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (DWORD) cygwin_version_strings;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
case CW_READ_V1_MOUNT_TABLES:
|
2002-06-09 08:31:03 +08:00
|
|
|
set_errno (ENOSYS);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 1;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-08 12:36:27 +08:00
|
|
|
case CW_USER_DATA:
|
2009-09-21 10:19:31 +08:00
|
|
|
/* This is a kludge to work around a version of _cygwin_common_crt0
|
|
|
|
which overwrote the cxx_malloc field with the local DLL copy.
|
|
|
|
Hilarity ensues if the DLL is not loaded like while the process
|
|
|
|
is forking. */
|
|
|
|
__cygwin_user_data.cxx_malloc = &default_cygwin_cxx_malloc;
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (DWORD) &__cygwin_user_data;
|
|
|
|
break;
|
2000-07-08 12:36:27 +08:00
|
|
|
|
2000-07-09 13:29:51 +08:00
|
|
|
case CW_PERFILE:
|
|
|
|
perfile_table = va_arg (arg, struct __cygwin_perfile *);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
|
|
|
break;
|
2000-07-09 13:29:51 +08:00
|
|
|
|
2000-07-29 06:33:43 +08:00
|
|
|
case CW_GET_CYGDRIVE_PREFIXES:
|
|
|
|
{
|
|
|
|
char *user = va_arg (arg, char *);
|
|
|
|
char *system = va_arg (arg, char *);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = get_cygdrive_info (user, system, NULL, NULL);
|
2000-07-29 06:33:43 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2000-07-29 06:33:43 +08:00
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
case CW_GETPINFO_FULL:
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (DWORD) fillout_pinfo (va_arg (arg, pid_t), 1);
|
|
|
|
break;
|
2000-07-30 00:24:59 +08:00
|
|
|
|
2000-08-25 10:27:42 +08:00
|
|
|
case CW_INIT_EXCEPTIONS:
|
2005-12-03 12:23:35 +08:00
|
|
|
/* noop */ /* init_exceptions (va_arg (arg, exception_list *)); */
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
|
|
|
break;
|
2000-08-25 10:27:42 +08:00
|
|
|
|
2000-11-09 04:36:37 +08:00
|
|
|
case CW_GET_CYGDRIVE_INFO:
|
|
|
|
{
|
|
|
|
char *user = va_arg (arg, char *);
|
|
|
|
char *system = va_arg (arg, char *);
|
|
|
|
char *user_flags = va_arg (arg, char *);
|
|
|
|
char *system_flags = va_arg (arg, char *);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = get_cygdrive_info (user, system, user_flags, system_flags);
|
2000-11-09 04:36:37 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2000-11-09 04:36:37 +08:00
|
|
|
|
2001-10-25 05:56:54 +08:00
|
|
|
case CW_SET_CYGWIN_REGISTRY_NAME:
|
|
|
|
case CW_GET_CYGWIN_REGISTRY_NAME:
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
|
|
|
break;
|
2001-10-25 05:56:54 +08:00
|
|
|
|
2002-02-15 05:20:06 +08:00
|
|
|
case CW_STRACE_TOGGLE:
|
2002-01-29 10:02:03 +08:00
|
|
|
{
|
|
|
|
pid_t pid = va_arg (arg, pid_t);
|
|
|
|
pinfo p (pid);
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
sig_send (p, __SIGSTRACE);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
2002-01-29 10:02:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_errno (ESRCH);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (DWORD) -1;
|
2002-01-29 10:02:03 +08:00
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2002-02-15 05:20:06 +08:00
|
|
|
|
2002-02-15 05:31:23 +08:00
|
|
|
case CW_STRACE_ACTIVE:
|
|
|
|
{
|
2009-10-14 12:17:05 +08:00
|
|
|
res = strace.active ();
|
2002-02-15 05:31:23 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2002-02-15 05:31:23 +08:00
|
|
|
|
2002-01-29 10:02:03 +08:00
|
|
|
case CW_CYGWIN_PID_TO_WINPID:
|
|
|
|
{
|
|
|
|
pinfo p (va_arg (arg, pid_t));
|
2009-10-14 12:17:05 +08:00
|
|
|
res = p ? p->dwProcessId : 0;
|
2002-01-29 10:02:03 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2002-06-04 01:56:10 +08:00
|
|
|
case CW_EXTRACT_DOMAIN_AND_USER:
|
2002-06-21 13:01:17 +08:00
|
|
|
{
|
2008-07-30 20:10:20 +08:00
|
|
|
WCHAR nt_domain[MAX_DOMAIN_NAME_LEN + 1];
|
|
|
|
WCHAR nt_user[UNLEN + 1];
|
|
|
|
|
2002-06-04 01:56:10 +08:00
|
|
|
struct passwd *pw = va_arg (arg, struct passwd *);
|
|
|
|
char *domain = va_arg (arg, char *);
|
|
|
|
char *user = va_arg (arg, char *);
|
2008-07-30 20:10:20 +08:00
|
|
|
extract_nt_dom_user (pw, nt_domain, nt_user);
|
|
|
|
if (domain)
|
|
|
|
sys_wcstombs (domain, MAX_DOMAIN_NAME_LEN + 1, nt_domain);
|
|
|
|
if (user)
|
|
|
|
sys_wcstombs (user, UNLEN + 1, nt_user);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
2002-06-04 01:56:10 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2002-10-31 05:05:18 +08:00
|
|
|
case CW_CMDLINE:
|
|
|
|
{
|
2003-03-09 01:56:13 +08:00
|
|
|
size_t n;
|
2002-10-31 05:05:18 +08:00
|
|
|
pid_t pid = va_arg (arg, pid_t);
|
|
|
|
pinfo p (pid);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (DWORD) p->cmdline (n);
|
2002-10-31 05:05:18 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2003-04-03 16:04:41 +08:00
|
|
|
case CW_CHECK_NTSEC:
|
|
|
|
{
|
|
|
|
char *filename = va_arg (arg, char *);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = check_ntsec (filename);
|
2003-04-03 16:04:41 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2003-10-23 04:32:20 +08:00
|
|
|
case CW_GET_ERRNO_FROM_WINERROR:
|
2004-05-29 03:50:07 +08:00
|
|
|
{
|
2003-10-23 04:32:20 +08:00
|
|
|
int error = va_arg (arg, int);
|
|
|
|
int deferrno = va_arg (arg, int);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = geterrno_from_win_error (error, deferrno);
|
2003-10-23 04:32:20 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2003-11-04 23:48:19 +08:00
|
|
|
case CW_GET_POSIX_SECURITY_ATTRIBUTE:
|
|
|
|
{
|
2008-08-14 22:05:04 +08:00
|
|
|
path_conv dummy;
|
2003-11-26 21:23:27 +08:00
|
|
|
security_descriptor sd;
|
2003-11-04 23:48:19 +08:00
|
|
|
int attribute = va_arg (arg, int);
|
|
|
|
PSECURITY_ATTRIBUTES psa = va_arg (arg, PSECURITY_ATTRIBUTES);
|
|
|
|
void *sd_buf = va_arg (arg, void *);
|
|
|
|
DWORD sd_buf_size = va_arg (arg, DWORD);
|
2008-08-14 22:05:04 +08:00
|
|
|
set_security_attribute (dummy, attribute, psa, sd);
|
2006-10-22 22:57:43 +08:00
|
|
|
if (!psa->lpSecurityDescriptor)
|
2009-10-14 12:17:05 +08:00
|
|
|
res = sd.size ();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
psa->lpSecurityDescriptor = sd_buf;
|
|
|
|
res = sd.copy (sd_buf, sd_buf_size);
|
|
|
|
}
|
2004-05-29 03:50:07 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2003-11-06 22:33:16 +08:00
|
|
|
case CW_GET_SHMLBA:
|
2004-05-29 03:50:07 +08:00
|
|
|
{
|
2009-10-14 12:17:05 +08:00
|
|
|
res = getpagesize ();
|
2003-11-06 22:33:16 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2003-11-08 17:48:48 +08:00
|
|
|
case CW_GET_UID_FROM_SID:
|
2004-05-29 03:50:07 +08:00
|
|
|
{
|
2005-07-04 16:44:06 +08:00
|
|
|
cygpsid psid = va_arg (arg, PSID);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = psid.get_id (false, NULL);
|
2003-11-08 17:48:48 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2003-11-08 17:48:48 +08:00
|
|
|
case CW_GET_GID_FROM_SID:
|
2004-05-29 03:50:07 +08:00
|
|
|
{
|
2005-07-04 16:44:06 +08:00
|
|
|
cygpsid psid = va_arg (arg, PSID);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = psid.get_id (true, NULL);
|
2003-11-08 17:48:48 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2004-02-25 09:19:13 +08:00
|
|
|
case CW_GET_BINMODE:
|
|
|
|
{
|
|
|
|
const char *path = va_arg (arg, const char *);
|
2005-05-13 23:46:07 +08:00
|
|
|
path_conv p (path, PC_SYM_FOLLOW | PC_NULLEMPTY);
|
2004-02-25 09:19:13 +08:00
|
|
|
if (p.error)
|
|
|
|
{
|
|
|
|
set_errno (p.error);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (unsigned long) -1;
|
2004-02-25 09:19:13 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
else
|
|
|
|
res = p.binmode ();
|
2004-02-25 09:19:13 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2005-03-23 03:00:31 +08:00
|
|
|
case CW_HOOK:
|
|
|
|
{
|
|
|
|
const char *name = va_arg (arg, const char *);
|
|
|
|
const void *hookfn = va_arg (arg, const void *);
|
2005-12-22 01:14:34 +08:00
|
|
|
WORD subsys;
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (unsigned long) hook_or_detect_cygwin (name, hookfn, subsys);
|
2005-03-23 03:00:31 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2005-05-09 09:19:38 +08:00
|
|
|
case CW_ARGV:
|
|
|
|
{
|
|
|
|
child_info_spawn *ci = (child_info_spawn *) get_cygwin_startup_info ();
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (unsigned long) (ci ? ci->moreinfo->argv : NULL);
|
2005-05-09 09:19:38 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2005-05-09 09:19:38 +08:00
|
|
|
case CW_ENVP:
|
|
|
|
{
|
|
|
|
child_info_spawn *ci = (child_info_spawn *) get_cygwin_startup_info ();
|
2009-10-14 12:17:05 +08:00
|
|
|
res = (unsigned long) (ci ? ci->moreinfo->envp : NULL);
|
2005-05-09 09:19:38 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2005-05-17 09:21:06 +08:00
|
|
|
case CW_DEBUG_SELF:
|
|
|
|
error_start_init (va_arg (arg, const char *));
|
|
|
|
try_to_debug ();
|
|
|
|
break;
|
2006-02-11 01:22:34 +08:00
|
|
|
case CW_SYNC_WINENV:
|
|
|
|
sync_winenv ();
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
|
|
|
break;
|
2006-05-25 10:33:13 +08:00
|
|
|
case CW_CYGTLS_PADSIZE:
|
2009-10-14 12:17:05 +08:00
|
|
|
res = CYGTLS_PADSIZE;
|
|
|
|
break;
|
2007-03-30 21:36:06 +08:00
|
|
|
case CW_SET_DOS_FILE_WARNING:
|
|
|
|
{
|
|
|
|
extern bool dos_file_warning;
|
|
|
|
dos_file_warning = va_arg (arg, int);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
2007-03-30 21:36:06 +08:00
|
|
|
}
|
|
|
|
break;
|
2008-11-26 18:18:10 +08:00
|
|
|
case CW_SET_PRIV_KEY:
|
|
|
|
{
|
|
|
|
const char *passwd = va_arg (arg, const char *);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = setlsapwd (passwd);
|
2008-11-26 18:18:10 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2009-01-09 13:18:02 +08:00
|
|
|
case CW_SETERRNO:
|
|
|
|
{
|
|
|
|
const char *file = va_arg (arg, const char *);
|
|
|
|
int line = va_arg (arg, int);
|
|
|
|
seterrno(file, line);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
2009-01-09 13:18:02 +08:00
|
|
|
}
|
|
|
|
break;
|
2009-10-07 05:51:17 +08:00
|
|
|
case CW_EXIT_PROCESS:
|
|
|
|
{
|
|
|
|
UINT status = va_arg (arg, UINT);
|
|
|
|
int useTerminateProcess = va_arg (arg, int);
|
|
|
|
exit_process (status, !!useTerminateProcess); /* no return */
|
|
|
|
}
|
2009-10-13 18:23:31 +08:00
|
|
|
case CW_SET_EXTERNAL_TOKEN:
|
|
|
|
{
|
|
|
|
HANDLE token = va_arg (arg, HANDLE);
|
|
|
|
int type = va_arg (arg, int);
|
|
|
|
set_imp_token (token, type);
|
2009-10-14 12:17:05 +08:00
|
|
|
res = 0;
|
2009-10-13 18:23:31 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
break;
|
2007-03-30 21:36:06 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
default:
|
2009-10-14 12:17:05 +08:00
|
|
|
set_errno (ENOSYS);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2009-10-14 12:17:05 +08:00
|
|
|
va_end (arg);
|
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|