[SIGAR-90] Add ptql support for Service.Path
This commit is contained in:
parent
0aed0d800e
commit
02753e3933
|
@ -71,6 +71,7 @@ public class TestPTQL extends SigarTestCase {
|
||||||
"Service.Name.eq=NOSUCHSERVICE",
|
"Service.Name.eq=NOSUCHSERVICE",
|
||||||
"Service.Name.ct=Oracle",
|
"Service.Name.ct=Oracle",
|
||||||
"Service.DisplayName.re=DHCP|DNS",
|
"Service.DisplayName.re=DHCP|DNS",
|
||||||
|
"Service.Path.ct=svchost",
|
||||||
OTHER_JAVA_PROCESS, //all java procs cept this one
|
OTHER_JAVA_PROCESS, //all java procs cept this one
|
||||||
"Cpu.Percent.ge=0.2",
|
"Cpu.Percent.ge=0.2",
|
||||||
"State.Name.sw=java,Args.*.eq=org.jboss.Main", //jboss
|
"State.Name.sw=java,Args.*.eq=org.jboss.Main", //jboss
|
||||||
|
|
|
@ -646,7 +646,8 @@ enum {
|
||||||
PTQL_PID_PID,
|
PTQL_PID_PID,
|
||||||
PTQL_PID_FILE,
|
PTQL_PID_FILE,
|
||||||
PTQL_PID_SERVICE,
|
PTQL_PID_SERVICE,
|
||||||
PTQL_PID_SERVICE_DISPLAY
|
PTQL_PID_SERVICE_DISPLAY,
|
||||||
|
PTQL_PID_SERVICE_PATH
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef SIGAR_64BIT
|
#ifdef SIGAR_64BIT
|
||||||
|
@ -677,6 +678,9 @@ static int ptql_branch_init_service(ptql_parse_branch_t *parsed,
|
||||||
else if (strEQ(parsed->attr, "DisplayName")) {
|
else if (strEQ(parsed->attr, "DisplayName")) {
|
||||||
branch->flags = PTQL_PID_SERVICE_DISPLAY;
|
branch->flags = PTQL_PID_SERVICE_DISPLAY;
|
||||||
}
|
}
|
||||||
|
else if (strEQ(parsed->attr, "Path")) {
|
||||||
|
branch->flags = PTQL_PID_SERVICE_PATH;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return ptql_error(error, "Unsupported %s attribute: %s",
|
return ptql_error(error, "Unsupported %s attribute: %s",
|
||||||
parsed->name, parsed->attr);
|
parsed->name, parsed->attr);
|
||||||
|
@ -721,6 +725,32 @@ static int ptql_branch_init_pid(ptql_parse_branch_t *parsed,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
#define QUERY_SC_SIZE 8192
|
||||||
|
|
||||||
|
static int ptql_service_query_config(SC_HANDLE scm_handle,
|
||||||
|
char *name,
|
||||||
|
LPQUERY_SERVICE_CONFIG config)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
DWORD bytes;
|
||||||
|
SC_HANDLE handle =
|
||||||
|
OpenService(scm_handle, name, SERVICE_QUERY_CONFIG);
|
||||||
|
|
||||||
|
if (!handle) {
|
||||||
|
return GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QueryServiceConfig(handle, config, QUERY_SC_SIZE, &bytes)) {
|
||||||
|
status = SIGAR_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
status = GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseServiceHandle(handle);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
static int ptql_pid_service_list_get(sigar_t *sigar,
|
static int ptql_pid_service_list_get(sigar_t *sigar,
|
||||||
ptql_branch_t *branch,
|
ptql_branch_t *branch,
|
||||||
sigar_proc_list_t *proclist)
|
sigar_proc_list_t *proclist)
|
||||||
|
@ -728,6 +758,8 @@ static int ptql_pid_service_list_get(sigar_t *sigar,
|
||||||
SC_HANDLE handle =
|
SC_HANDLE handle =
|
||||||
OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
|
OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
|
||||||
ENUM_SERVICE_STATUS services[4096];
|
ENUM_SERVICE_STATUS services[4096];
|
||||||
|
char buffer[QUERY_SC_SIZE];
|
||||||
|
LPQUERY_SERVICE_CONFIG config = (LPQUERY_SERVICE_CONFIG)buffer;
|
||||||
BOOL retval;
|
BOOL retval;
|
||||||
DWORD bytes, count, resume=0, i;
|
DWORD bytes, count, resume=0, i;
|
||||||
|
|
||||||
|
@ -742,15 +774,26 @@ static int ptql_pid_service_list_get(sigar_t *sigar,
|
||||||
&bytes, &count, &resume);
|
&bytes, &count, &resume);
|
||||||
|
|
||||||
for (i=0; i<count; i++) {
|
for (i=0; i<count; i++) {
|
||||||
|
int status;
|
||||||
char *value;
|
char *value;
|
||||||
|
char *name = services[i].lpServiceName;
|
||||||
|
|
||||||
switch (branch->flags) {
|
switch (branch->flags) {
|
||||||
case PTQL_PID_SERVICE_DISPLAY:
|
case PTQL_PID_SERVICE_DISPLAY:
|
||||||
value = services[i].lpDisplayName;
|
value = services[i].lpDisplayName;
|
||||||
break;
|
break;
|
||||||
|
case PTQL_PID_SERVICE_PATH:
|
||||||
|
status = ptql_service_query_config(handle, name, config);
|
||||||
|
if (status == SIGAR_OK) {
|
||||||
|
value = config->lpBinaryPathName;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case PTQL_PID_SERVICE:
|
case PTQL_PID_SERVICE:
|
||||||
default:
|
default:
|
||||||
value = services[i].lpServiceName;
|
value = name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,7 +801,7 @@ static int ptql_pid_service_list_get(sigar_t *sigar,
|
||||||
sigar_pid_t service_pid;
|
sigar_pid_t service_pid;
|
||||||
int status =
|
int status =
|
||||||
sigar_service_pid_get(sigar,
|
sigar_service_pid_get(sigar,
|
||||||
services[i].lpServiceName,
|
name,
|
||||||
&service_pid);
|
&service_pid);
|
||||||
|
|
||||||
if (status == SIGAR_OK) {
|
if (status == SIGAR_OK) {
|
||||||
|
|
Loading…
Reference in New Issue