[SIGAR-121] Add Service.Pid PTQL support
This commit is contained in:
parent
80ef448f8c
commit
eeb3f26ad4
@ -20,6 +20,8 @@ package org.hyperic.sigar.win32.test;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hyperic.sigar.Sigar;
|
||||||
|
import org.hyperic.sigar.ptql.ProcessFinder;
|
||||||
import org.hyperic.sigar.test.SigarTestCase;
|
import org.hyperic.sigar.test.SigarTestCase;
|
||||||
|
|
||||||
import org.hyperic.sigar.win32.Service;
|
import org.hyperic.sigar.win32.Service;
|
||||||
@ -27,6 +29,7 @@ import org.hyperic.sigar.win32.ServiceConfig;
|
|||||||
import org.hyperic.sigar.win32.Win32Exception;
|
import org.hyperic.sigar.win32.Win32Exception;
|
||||||
|
|
||||||
public class TestService extends SigarTestCase {
|
public class TestService extends SigarTestCase {
|
||||||
|
private static final String EVENTLOG_NAME = "Eventlog";
|
||||||
private static final String TEST_NAME = "MyTestService";
|
private static final String TEST_NAME = "MyTestService";
|
||||||
|
|
||||||
private static final String PREFIX =
|
private static final String PREFIX =
|
||||||
@ -43,7 +46,7 @@ public class TestService extends SigarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testServiceOpen() throws Exception {
|
public void testServiceOpen() throws Exception {
|
||||||
Service service = new Service("Eventlog");
|
Service service = new Service(EVENTLOG_NAME);
|
||||||
service.getConfig();
|
service.getConfig();
|
||||||
service.close();
|
service.close();
|
||||||
|
|
||||||
@ -93,6 +96,19 @@ public class TestService extends SigarTestCase {
|
|||||||
assertGtZeroTrace("getServiceConfigs", configs.size());
|
assertGtZeroTrace("getServiceConfigs", configs.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testServicePtql() throws Exception {
|
||||||
|
Sigar sigar = new Sigar();
|
||||||
|
try {
|
||||||
|
long pid = sigar.getServicePid(EVENTLOG_NAME);
|
||||||
|
String ptql = "Service.Pid.eq=" + pid;
|
||||||
|
List names = Service.getServiceNames(sigar, ptql);
|
||||||
|
traceln(ptql + "==" + names);
|
||||||
|
assertTrue(names.contains(EVENTLOG_NAME));
|
||||||
|
} finally {
|
||||||
|
sigar.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testServiceCreateDelete() throws Exception {
|
public void testServiceCreateDelete() throws Exception {
|
||||||
if (!TEST_CREATE) {
|
if (!TEST_CREATE) {
|
||||||
return;
|
return;
|
||||||
|
@ -683,7 +683,8 @@ enum {
|
|||||||
PTQL_PID_SERVICE_NAME,
|
PTQL_PID_SERVICE_NAME,
|
||||||
PTQL_PID_SERVICE_DISPLAY,
|
PTQL_PID_SERVICE_DISPLAY,
|
||||||
PTQL_PID_SERVICE_PATH,
|
PTQL_PID_SERVICE_PATH,
|
||||||
PTQL_PID_SERVICE_EXE
|
PTQL_PID_SERVICE_EXE,
|
||||||
|
PTQL_PID_SERVICE_PID
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef SIGAR_64BIT
|
#ifdef SIGAR_64BIT
|
||||||
@ -745,6 +746,9 @@ static int ptql_branch_init_service(ptql_parse_branch_t *parsed,
|
|||||||
/* basename of Path */
|
/* basename of Path */
|
||||||
branch->flags = PTQL_PID_SERVICE_EXE;
|
branch->flags = PTQL_PID_SERVICE_EXE;
|
||||||
}
|
}
|
||||||
|
else if (strEQ(parsed->attr, "Pid")) {
|
||||||
|
branch->flags = PTQL_PID_SERVICE_PID;
|
||||||
|
}
|
||||||
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);
|
||||||
@ -834,6 +838,7 @@ static int sigar_services_walk(sigar_services_walker_t *walker,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
for (i=0; i<ss.count; i++) {
|
for (i=0; i<ss.count; i++) {
|
||||||
|
sigar_pid_t service_pid = 0;
|
||||||
int status;
|
int status;
|
||||||
char *value = NULL;
|
char *value = NULL;
|
||||||
char *name = ss.services[i].lpServiceName;
|
char *name = ss.services[i].lpServiceName;
|
||||||
@ -867,13 +872,21 @@ static int sigar_services_walk(sigar_services_walker_t *walker,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PTQL_PID_SERVICE_PID:
|
||||||
|
sigar_service_pid_get(walker->sigar,
|
||||||
|
name,
|
||||||
|
&service_pid);
|
||||||
|
break;
|
||||||
case PTQL_PID_SERVICE_NAME:
|
case PTQL_PID_SERVICE_NAME:
|
||||||
default:
|
default:
|
||||||
value = name;
|
value = name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptql_str_match(walker->sigar, branch, value)) {
|
if ((value && ptql_str_match(walker->sigar, branch, value)) ||
|
||||||
|
(service_pid &&
|
||||||
|
pid_branch_match(branch, service_pid, atoi(branch->data.str))))
|
||||||
|
{
|
||||||
if (walker->add_service(walker, name) != SIGAR_OK) {
|
if (walker->add_service(walker, name) != SIGAR_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user