2000-02-17 20:38:33 +01:00
|
|
|
/* external.cc: Interface to Cygwin internals from external programs.
|
|
|
|
|
2000-02-24 03:49:44 +01:00
|
|
|
Copyright 1997, 1998, 1999, 2000 Cygnus Solutions.
|
2000-02-17 20:38:33 +01: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 07:10:20 +02:00
|
|
|
#include "fhandler.h"
|
|
|
|
#include "sync.h"
|
|
|
|
#include "sigproc.h"
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "pinfo.h"
|
2000-08-25 04:27:42 +02:00
|
|
|
#include <exceptions.h>
|
2000-09-07 18:23:51 +02:00
|
|
|
#include "shared_info.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "cygwin_version.h"
|
|
|
|
#include "perprocess.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
static external_pinfo *
|
2000-07-29 18:24:59 +02:00
|
|
|
fillout_pinfo (pid_t pid, int winpid)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
BOOL nextpid;
|
|
|
|
static external_pinfo ep;
|
|
|
|
|
|
|
|
if ((nextpid = !!(pid & CW_NEXTPID)))
|
|
|
|
pid ^= CW_NEXTPID;
|
2000-07-29 18:24:59 +02:00
|
|
|
|
|
|
|
static winpids pids (0);
|
|
|
|
|
2000-09-13 04:35:05 +02:00
|
|
|
if (!pids.npids || !nextpid)
|
2000-11-05 07:42:23 +01:00
|
|
|
pids.init (winpid);
|
2000-07-29 18:24:59 +02:00
|
|
|
|
2000-08-26 03:36:20 +02:00
|
|
|
static unsigned int i = 0;
|
|
|
|
if (!pid)
|
|
|
|
i = 0;
|
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
memset (&ep, 0, sizeof ep);
|
2000-11-05 07:42:23 +01:00
|
|
|
while (i < pids.npids)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-11-05 07:42:23 +01:00
|
|
|
DWORD thispid = pids.winpid (i);
|
|
|
|
_pinfo *p = pids[i];
|
|
|
|
i++;
|
2000-07-29 18:24:59 +02:00
|
|
|
|
2000-08-26 03:36:20 +02:00
|
|
|
if (!p)
|
|
|
|
{
|
2000-11-05 07:42:23 +01:00
|
|
|
if (!nextpid && thispid != (DWORD) pid)
|
2000-08-26 03:36:20 +02:00
|
|
|
continue;
|
|
|
|
ep.pid = thispid;
|
|
|
|
ep.dwProcessId = cygwin_pid (thispid);
|
|
|
|
ep.process_state = PID_IN_USE;
|
|
|
|
ep.ctty = -1;
|
|
|
|
}
|
2000-09-13 04:35:05 +02:00
|
|
|
else if (nextpid || p->pid == pid)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-08-26 03:36:20 +02:00
|
|
|
ep.ctty = tty_attached (p) ? p->ctty : -1;
|
|
|
|
ep.pid = p->pid;
|
|
|
|
ep.ppid = p->ppid;
|
|
|
|
ep.hProcess = p->hProcess;
|
|
|
|
ep.dwProcessId = p->dwProcessId;
|
|
|
|
ep.uid = p->uid;
|
|
|
|
ep.gid = p->gid;
|
|
|
|
ep.pgid = p->pgid;
|
|
|
|
ep.sid = p->sid;
|
2000-11-14 06:53:32 +01:00
|
|
|
ep.umask = 0;
|
2000-08-26 03:36:20 +02:00
|
|
|
ep.start_time = p->start_time;
|
|
|
|
ep.rusage_self = p->rusage_self;
|
|
|
|
ep.rusage_children = p->rusage_children;
|
|
|
|
strcpy (ep.progname, p->progname);
|
|
|
|
ep.strace_mask = 0;
|
|
|
|
ep.strace_file = 0;
|
|
|
|
|
|
|
|
ep.process_state = p->process_state;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-08-26 03:36:20 +02:00
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
if (!ep.pid)
|
|
|
|
{
|
2000-08-26 03:36:20 +02:00
|
|
|
i = 0;
|
2000-07-29 18:24:59 +02:00
|
|
|
pids.reset ();
|
|
|
|
return 0;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
return &ep;
|
|
|
|
}
|
|
|
|
|
2000-07-29 00:33:43 +02:00
|
|
|
static DWORD
|
2000-11-08 21:36:37 +01:00
|
|
|
get_cygdrive_info (char *user, char *system, char *user_flags,
|
|
|
|
char *system_flags)
|
2000-07-29 00:33:43 +02:00
|
|
|
{
|
2001-01-28 06:51:15 +01:00
|
|
|
int res = mount_table->get_cygdrive_info (user, system, user_flags,
|
|
|
|
system_flags);
|
2000-07-29 00:33:43 +02:00
|
|
|
return (res == ERROR_SUCCESS) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2000-11-08 21:36:37 +01:00
|
|
|
static DWORD
|
|
|
|
get_cygdrive_prefixes (char *user, char *system)
|
|
|
|
{
|
|
|
|
char user_flags[MAX_PATH];
|
|
|
|
char system_flags[MAX_PATH];
|
|
|
|
DWORD res = get_cygdrive_info (user, system, user_flags, system_flags);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
extern "C" DWORD
|
|
|
|
cygwin_internal (cygwin_getinfo_types t, ...)
|
|
|
|
{
|
|
|
|
va_list arg;
|
|
|
|
va_start (arg, t);
|
|
|
|
|
|
|
|
switch (t)
|
|
|
|
{
|
|
|
|
case CW_LOCK_PINFO:
|
2000-07-29 18:24:59 +02:00
|
|
|
return 1;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
case CW_UNLOCK_PINFO:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case CW_GETTHREADNAME:
|
|
|
|
return (DWORD) threadname (va_arg (arg, DWORD));
|
|
|
|
|
|
|
|
case CW_SETTHREADNAME:
|
|
|
|
{
|
|
|
|
char *name = va_arg (arg, char *);
|
|
|
|
regthread (name, va_arg (arg, DWORD));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CW_GETPINFO:
|
2000-07-29 18:24:59 +02:00
|
|
|
return (DWORD) fillout_pinfo (va_arg (arg, DWORD), 0);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
case CW_GETVERSIONINFO:
|
|
|
|
return (DWORD) cygwin_version_strings;
|
|
|
|
|
|
|
|
case CW_READ_V1_MOUNT_TABLES:
|
|
|
|
/* Upgrade old v1 registry mounts to new location. */
|
2001-01-28 06:51:15 +01:00
|
|
|
mount_table->import_v1_mounts ();
|
2000-02-17 20:38:33 +01:00
|
|
|
return 0;
|
|
|
|
|
2000-07-08 06:36:27 +02:00
|
|
|
case CW_USER_DATA:
|
|
|
|
return (DWORD) &__cygwin_user_data;
|
|
|
|
|
2000-07-09 07:29:51 +02:00
|
|
|
case CW_PERFILE:
|
|
|
|
perfile_table = va_arg (arg, struct __cygwin_perfile *);
|
|
|
|
return 0;
|
|
|
|
|
2000-07-29 00:33:43 +02:00
|
|
|
case CW_GET_CYGDRIVE_PREFIXES:
|
|
|
|
{
|
|
|
|
char *user = va_arg (arg, char *);
|
|
|
|
char *system = va_arg (arg, char *);
|
|
|
|
return get_cygdrive_prefixes (user, system);
|
|
|
|
}
|
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
case CW_GETPINFO_FULL:
|
|
|
|
return (DWORD) fillout_pinfo (va_arg (arg, pid_t), 1);
|
|
|
|
|
2000-08-25 04:27:42 +02:00
|
|
|
case CW_INIT_EXCEPTIONS:
|
|
|
|
init_exceptions ((exception_list *) arg);
|
|
|
|
return 0;
|
|
|
|
|
2000-11-08 21:36:37 +01: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 *);
|
|
|
|
return get_cygdrive_info (user, system, user_flags, system_flags);
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
default:
|
|
|
|
return (DWORD) -1;
|
|
|
|
}
|
|
|
|
}
|