#include <stdio.h>
#include <stdlib.h>
-#ifdef __UNIX__
+#ifndef _MSC_VER
#include <unistd.h>
#endif
namespace processes {
-#ifdef __WIN32__
+#ifdef _MSC_VER
#include <tlhelp32.h>
const astring NTVDM_NAME = "ntvdm.exe";
// the umbrella process that hangs onto 16 bit tasks for NT.
- #ifdef _MSCVER
- #include <vdmdbg.h>
- #endif
-#endif
-#ifdef __UNIX__
+// #ifdef _MSCVER
+// #include <vdmdbg.h>
+// #endif
+#else
#include <signal.h>
#include <stdio.h>
#endif
class process_implementation_hider
{
public:
-#ifdef __WIN32__
+#ifdef _MSC_VER
// psapi members:
application_instance psapi_dll;
application_instance vdm_dll;
BOOL (WINAPI *enumerate_processes)(basis::un_int *, basis::un_int cb, basis::un_int *);
BOOL (WINAPI *enumerate_modules)(HANDLE, HMODULE *, basis::un_int, basis::un_int *);
basis::un_int (WINAPI *get_module_name)(HANDLE, HMODULE, LPTSTR, basis::un_int);
-#ifdef _MSCVER
- INT (WINAPI *tasker_16bit)(basis::un_int, TASKENUMPROCEX fp, LPARAM);
-#endif
+//#ifdef _MSCVER
+// INT (WINAPI *tasker_16bit)(basis::un_int, TASKENUMPROCEX fp, LPARAM);
+//#endif
// toolhelp members:
application_instance kernel32_dll;
/// HANDLE hSnapShot;
process_implementation_hider()
- : psapi_dll(NIL), vdm_dll(NIL), enumerate_processes(NIL),
- enumerate_modules(NIL), get_module_name(NIL),
-#ifdef _MSCVER
- tasker_16bit(NIL),
-#endif
- kernel32_dll(NIL), create_snapshot(NIL), first_process(NIL),
- next_process(NIL) {}
+ : psapi_dll(NULL_POINTER), vdm_dll(NULL_POINTER), enumerate_processes(NULL_POINTER),
+ enumerate_modules(NULL_POINTER), get_module_name(NULL_POINTER),
+//#ifdef _MSCVER
+// tasker_16bit(NULL_POINTER),
+//#endif
+ kernel32_dll(NULL_POINTER), create_snapshot(NULL_POINTER), first_process(NULL_POINTER),
+ next_process(NULL_POINTER) {}
~process_implementation_hider() {
if (psapi_dll) FreeLibrary(psapi_dll);
if (vdm_dll) FreeLibrary(vdm_dll);
if (kernel32_dll) FreeLibrary(kernel32_dll);
- psapi_dll = NIL;
- vdm_dll = NIL;
- kernel32_dll = NIL;
+ psapi_dll = NULL_POINTER;
+ vdm_dll = NULL_POINTER;
+ kernel32_dll = NULL_POINTER;
}
#endif
};
process_control::process_control()
: _ptrs(new process_implementation_hider),
-#ifdef __WIN32__
+#ifdef _MSC_VER
_use_psapi(true),
-#endif
-#ifdef __UNIX__
+#else
_rando(new chaos),
#endif
_healthy(false)
// Check to see if were running under Windows95 or Windows NT.
version osver = application_configuration::get_OS_version();
-#ifdef __WIN32__
+#ifdef _MSC_VER
if (osver.v_revision() == VER_PLATFORM_WIN32_WINDOWS) {
// we're on Windows 95, so use the toolhelp API for the processes.
_use_psapi = false;
_healthy = initialize_psapi_support();
else
_healthy = initialize_toolhelp_support();
-#endif
-#ifdef __UNIX__
+#else
_healthy = true;
#endif
}
process_control::~process_control()
{
WHACK(_ptrs);
-#ifdef __UNIX__
+#ifndef _MSC_VER
WHACK(_rando);
#endif
}
bool process_control::query_processes(process_entry_array &to_fill)
{
if (!_healthy) return false;
-#ifdef __WIN32__
+#ifdef _MSC_VER
if (!_use_psapi) {
// we're on Windows 95 or something, so use the toolhelp API for the
// processes.
// we're on Windows NT and so on; use the process API (PSAPI) to get info.
return get_processes_with_psapi(to_fill);
}
-#endif
-#ifdef __UNIX__
+#else
return get_processes_with_ps(to_fill);
#endif
}
-#ifdef __WIN32__
+#ifdef _MSC_VER
bool process_control::initialize_psapi_support()
{
// create an instance of the PSAPI dll for querying 32-bit processes and
_ptrs->get_module_name
= (basis::un_int (WINAPI *)(HANDLE, HMODULE, LPTSTR, basis::un_int))
GetProcAddress(_ptrs->psapi_dll, "GetModuleFileNameExA");
-#ifdef _MSCVER
- _ptrs->tasker_16bit = (INT(WINAPI *)(basis::un_int, TASKENUMPROCEX, LPARAM))
- GetProcAddress(_ptrs->vdm_dll, "VDMEnumTaskWOWEx");
-#endif
+//#ifdef _MSCVER
+// _ptrs->tasker_16bit = (INT(WINAPI *)(basis::un_int, TASKENUMPROCEX, LPARAM))
+// GetProcAddress(_ptrs->vdm_dll, "VDMEnumTaskWOWEx");
+//#endif
if (!_ptrs->enumerate_processes || !_ptrs->enumerate_modules
|| !_ptrs->get_module_name
-#ifdef _MSCVER
- || !_ptrs->tasker_16bit
-#endif
+//#ifdef _MSCVER
+// || !_ptrs->tasker_16bit
+//#endif
) return false;
return true;
FUNCDEF("zap_process");
#endif
if (!_healthy) return false;
-#ifdef __UNIX__
+#ifndef _MSC_VER
int ret = kill(to_zap, 9);
// send the serious take-down signal to the process.
return !ret;
-#endif
-#ifdef __WIN32__
+#else
HANDLE h = OpenProcess(PROCESS_TERMINATE, false, to_zap);
if (!h) {
#ifdef DEBUG_PROCESS_CONTROL
process_entry process_control::query_process(basis::un_int to_query)
{
-// FUNCDEF("query_process");
+ FUNCDEF("query_process");
process_entry to_return;
process_entry_array to_fill;
}
//hmmm: implement more specifically.
-#ifdef __UNIX__
+#ifndef _MSC_VER
//put in the single process grabber deal.
-#endif
-#ifdef __WIN32__
+#else
//grab the entry from the list.
#endif
//////////////
-#ifdef __WIN32__
+#ifdef _MSC_VER
// this section is the PSAPI version of the query.
// called back on each 16 bit task.
// loop over the process enumeration function until we are sure that we
// have allocated a large enough space for all existing processes.
bool got_all = false;
- basis::un_int *pid_list = NIL;
+ basis::un_int *pid_list = NULL_POINTER;
basis::un_int max_size = 428 * sizeof(basis::un_int);
basis::un_int actual_size = 0;
while (!got_all) {
(new_entry.path().end() - NTVDM_NAME.length() + 1,
new_entry.path().end());
temp.to_lower();
-#ifdef _MSCVER
-//hmmm: pull this back in for mingw when it seems to be supported, if ever.
- if (temp == NTVDM_NAME) {
- // set up a callback stampede on the 16 bit processes.
- process_info_clump info(pid_list[i], to_fill);
- _ptrs->tasker_16bit(pid_list[i], (TASKENUMPROCEX)process_16bit,
- (LPARAM)&info);
- }
-#endif
+//#ifdef _MSCVER
+////hmmm: pull this back in for mingw when it seems to be supported, if ever.
+// if (temp == NTVDM_NAME) {
+// // set up a callback stampede on the 16 bit processes.
+// process_info_clump info(pid_list[i], to_fill);
+// _ptrs->tasker_16bit(pid_list[i], (TASKENUMPROCEX)process_16bit,
+// (LPARAM)&info);
+// }
+//#endif
}
}
}
#endif // __WIN32__
-#ifdef __UNIX__
+#ifndef _MSC_VER
-#define CLOSE_TMP_FILE { \
+#define CLOSE_TEMPORARY_FILE { \
/* continuable_error("process_control", "get_processes_with_ps", error); */ \
if (output) { \
fclose(output); \
_rando->inclusive(1, 400000));
a_sprintf cmd("ps wax --format \"%%p %%a\" >%s", tmpfile.s());
//hmmm: add more info as we expand the process entry.
- FILE *output = NIL; // initialize now to establish variable for our macro.
+ FILE *output = NULL_POINTER; // initialize now to establish variable for our macro.
int sysret = system(cmd.s());
if (negative(sysret)) {
LOG("got negative return from system()!");
- CLOSE_TMP_FILE;
+ CLOSE_TEMPORARY_FILE;
return false;
}
output = fopen(tmpfile.s(), "r");
if (!output) {
LOG("failed to open process list file!");
- CLOSE_TMP_FILE;
+ CLOSE_TEMPORARY_FILE;
return false;
}
const int max_buff = 10000;
if (size_read > 0)
accumulator += astring(astring::UNTERMINATED, buff, size_read);
}
- CLOSE_TMP_FILE;
+ CLOSE_TEMPORARY_FILE;
// parse the string up now.
bool first_line = true;
while (accumulator.length()) {