sigar_t already has a handle to advapi32.dll, use it

This commit is contained in:
Doug MacEachern 2005-10-10 20:15:12 +00:00
parent d5558f8487
commit 77df863144
2 changed files with 20 additions and 21 deletions

View File

@ -2,6 +2,8 @@
#include "sigar.h" #include "sigar.h"
#include "sigar_fileinfo.h" #include "sigar_fileinfo.h"
#include "sigar_log.h" #include "sigar_log.h"
#include "sigar_private.h"
#include "sigar_os.h"
#include <string.h> #include <string.h>
@ -1184,6 +1186,11 @@ JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid)
SC_HANDLE mgr; SC_HANDLE mgr;
dSIGAR(0); dSIGAR(0);
if (!sigar->adv_handle) {
sigar_throw_notimpl(env, "advapi32.dll not available");
return 0;
}
name = JENV->GetStringUTFChars(env, jname, &is_copy); name = JENV->GetStringUTFChars(env, jname, &is_copy);
mgr = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, mgr = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE,
@ -1195,28 +1202,19 @@ JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid)
if (svc) { if (svc) {
SERVICE_STATUS_PROCESS status; SERVICE_STATUS_PROCESS status;
DWORD bytes; DWORD bytes;
HANDLE lib; QueryServiceStatusExFunc status_query =
(QueryServiceStatusExFunc)
GetProcAddress(sigar->adv_handle,
"QueryServiceStatusEx");
if ((lib = LoadLibrary("advapi32.dll"))) { if (!status_query) {
QueryServiceStatusExFunc status_query; err = SIGAR_ENOTIMPL;
status_query = }
(QueryServiceStatusExFunc) else if (status_query(svc,
GetProcAddress(lib, "QueryServiceStatusEx"); SC_STATUS_PROCESS_INFO,
(LPBYTE)&status, sizeof(status), &bytes))
if (!status_query) { {
err = SIGAR_ENOTIMPL; pid = status.dwProcessId;
}
else if (status_query(svc,
SC_STATUS_PROCESS_INFO,
(LPBYTE)&status, sizeof(status), &bytes))
{
pid = status.dwProcessId;
}
else {
err = GetLastError();
}
FreeLibrary(lib);
} }
else { else {
err = GetLastError(); err = GetLastError();

View File

@ -45,6 +45,7 @@ public class TestPTQL extends SigarTestCase {
"Pid.PidFile.eq=pid.file", "Pid.PidFile.eq=pid.file",
"Pid.Pid.eq=1", "Pid.Pid.eq=1",
"Pid.Service.eq=Eventlog", "Pid.Service.eq=Eventlog",
"Pid.Service.eq=NOSUCHSERVICE",
"Pid.Service.eq=Hyperic HQ Agent", "Pid.Service.eq=Hyperic HQ Agent",
"State.Name.eq=java,Pid.Pid.ne=$$", //all java procs cept this one "State.Name.eq=java,Pid.Pid.ne=$$", //all java procs cept this one
"Cpu.Percent.ge=0.2", "Cpu.Percent.ge=0.2",