From a5373bf7cc8f2b858d9e1e7e93cccc73892c8385 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 22 Dec 2006 05:52:23 +0000 Subject: [PATCH] add flags to branch, use for Pid query --- src/sigar_ptql.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index 8b2c89ea..649edf6d 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -66,6 +66,7 @@ struct ptql_branch_t { ptql_lookup_t *lookup; void *data; unsigned int data_size; + unsigned int flags; union { ptql_op_ui64_t ui64; ptql_op_ui32_t ui32; @@ -421,18 +422,35 @@ static int ptql_branch_match(ptql_branch_t *branch) } } +enum { + PTQL_PID_PID, + PTQL_PID_FILE, + PTQL_PID_SERVICE +}; + static int ptql_branch_init_pid(ptql_parse_branch_t *parsed, ptql_branch_t *branch) { if (strEQ(parsed->attr, "Pid")) { + branch->flags = PTQL_PID_PID; branch->data = (void*)atoi(parsed->value); /*XXX*/ return SIGAR_OK; } else if (strEQ(parsed->attr, "PidFile")) { + branch->flags = PTQL_PID_FILE; branch->data = strdup(parsed->value); branch->data_size = strlen(parsed->value); return SIGAR_OK; } + else if (strEQ(parsed->attr, "Service")) { +#ifdef WIN32 + branch->flags = PTQL_PID_SERVICE; + branch->data = strdup(parsed->value); + branch->data_size = strlen(parsed->value); +#else + return SIGAR_PTQL_MALFORMED_QUERY; +#endif + } else { return SIGAR_PTQL_MALFORMED_QUERY; } @@ -446,7 +464,7 @@ static int ptql_pid_match(sigar_t *sigar, (ptql_branch_t *)data; sigar_pid_t match_pid; - if (branch->data_size) { + if (branch->flags == PTQL_PID_FILE) { char buffer[SIGAR_PATH_MAX+1]; int status = sigar_file2str((const char *)branch->data, @@ -456,6 +474,13 @@ static int ptql_pid_match(sigar_t *sigar, } match_pid = strtoull(buffer, NULL, 10); /*XXX validate*/ } + else if (branch->flags == PTQL_PID_SERVICE) { +#ifdef WIN32 + return !SIGAR_OK; /*XXX*/ +#else + return !SIGAR_OK; +#endif + } else { match_pid = (sigar_pid_t)branch->data; }