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_fileinfo.h"
#include "sigar_log.h"
#include "sigar_private.h"
#include "sigar_os.h"
#include <string.h>
@ -1184,6 +1186,11 @@ JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid)
SC_HANDLE mgr;
dSIGAR(0);
if (!sigar->adv_handle) {
sigar_throw_notimpl(env, "advapi32.dll not available");
return 0;
}
name = JENV->GetStringUTFChars(env, jname, &is_copy);
mgr = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE,
@ -1195,13 +1202,10 @@ JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid)
if (svc) {
SERVICE_STATUS_PROCESS status;
DWORD bytes;
HANDLE lib;
if ((lib = LoadLibrary("advapi32.dll"))) {
QueryServiceStatusExFunc status_query;
status_query =
QueryServiceStatusExFunc status_query =
(QueryServiceStatusExFunc)
GetProcAddress(lib, "QueryServiceStatusEx");
GetProcAddress(sigar->adv_handle,
"QueryServiceStatusEx");
if (!status_query) {
err = SIGAR_ENOTIMPL;
@ -1215,12 +1219,6 @@ JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid)
else {
err = GetLastError();
}
FreeLibrary(lib);
}
else {
err = GetLastError();
}
CloseServiceHandle(svc);
}
else {

View File

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