diff --git a/bindings/java/src/jni/javasigar.c b/bindings/java/src/jni/javasigar.c index c8ab0dd5..2fcd01d9 100644 --- a/bindings/java/src/jni/javasigar.c +++ b/bindings/java/src/jni/javasigar.c @@ -114,6 +114,13 @@ static void sigar_throw_notimpl(JNIEnv *env, char *msg) JENV->ThrowNew(env, errorClass, msg); } +static void sigar_throw_ptql_malformed(JNIEnv *env, char *msg) +{ + jclass errorClass = SIGAR_FIND_CLASS("ptql/MalformedQueryException"); + + JENV->ThrowNew(env, errorClass, msg); +} + static void sigar_throw_error(JNIEnv *env, jni_sigar_t *jsigar, int err) { jclass errorClass; @@ -1199,7 +1206,15 @@ JNIEXPORT void SIGAR_JNI(ptql_SigarProcessQuery_create) } if (status != SIGAR_OK) { - sigar_throw_exception(env, "Malformed query"); /*XXX*/ + char buf[1024], *msg=buf; + if (status == SIGAR_PTQL_MALFORMED_QUERY) { + msg = "Malformed query"; + } + else { + sigar_strerror_get(status, buf, sizeof(buf)); + } + + sigar_throw_ptql_malformed(env, msg); } else { sigar_set_pointer(env, obj, query); diff --git a/bindings/java/src/org/hyperic/sigar/ptql/ProcessQueryFactory.java b/bindings/java/src/org/hyperic/sigar/ptql/ProcessQueryFactory.java index 5180fc75..aaf5ac2f 100644 --- a/bindings/java/src/org/hyperic/sigar/ptql/ProcessQueryFactory.java +++ b/bindings/java/src/org/hyperic/sigar/ptql/ProcessQueryFactory.java @@ -160,11 +160,7 @@ public class ProcessQueryFactory implements Comparator { if (useNative) { pQuery = new SigarProcessQuery(); - try { - ((SigarProcessQuery)pQuery).create(query); - } catch (SigarException e) { - throw new MalformedQueryException(e.getMessage()); - } + ((SigarProcessQuery)pQuery).create(query); cache.put(query, pQuery); return pQuery; } diff --git a/bindings/java/src/org/hyperic/sigar/ptql/SigarProcessQuery.java b/bindings/java/src/org/hyperic/sigar/ptql/SigarProcessQuery.java index a3d8442f..4cbb2e8d 100644 --- a/bindings/java/src/org/hyperic/sigar/ptql/SigarProcessQuery.java +++ b/bindings/java/src/org/hyperic/sigar/ptql/SigarProcessQuery.java @@ -28,7 +28,7 @@ public class SigarProcessQuery implements ProcessQuery { long longSigarWrapper = 0; //same, but where sizeof(void*) > sizeof(int) native void create(String ptql) - throws SigarException; + throws MalformedQueryException; native void destroy(); diff --git a/include/sigar_ptql.h b/include/sigar_ptql.h index 7842452b..1c5b1ecf 100644 --- a/include/sigar_ptql.h +++ b/include/sigar_ptql.h @@ -19,6 +19,8 @@ #ifndef SIGAR_PTQL_H #define SIGAR_PTQL_H +#define SIGAR_PTQL_MALFORMED_QUERY -1 + typedef struct sigar_ptql_query_t sigar_ptql_query_t; typedef int (*sigar_ptql_re_impl_t)(void *, char *, char *); diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index 52c24273..3b2c163e 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -35,9 +35,6 @@ #define strtonum_failed(src, ptr) \ ((src == ptr) || (errno == ERANGE) || (*ptr != '\0')) -/* XXX need more specific errors */ -#define SIGAR_PTQL_MALFORMED_QUERY 1 - typedef struct ptql_parse_branch_t ptql_parse_branch_t; typedef struct ptql_branch_t ptql_branch_t; @@ -631,7 +628,7 @@ static int ptql_branch_init_pid(ptql_parse_branch_t *parsed, char *ptr; branch->data.pid = str2pid(parsed->value, ptr); if (strtonum_failed(parsed->value, ptr)) { - return SIGAR_PTQL_MALFORMED_QUERY; + return EINVAL; } } return SIGAR_OK; @@ -652,7 +649,7 @@ static int ptql_branch_init_pid(ptql_parse_branch_t *parsed, } else { - return SIGAR_PTQL_MALFORMED_QUERY; + return EINVAL; } } @@ -675,7 +672,7 @@ static int ptql_pid_match(sigar_t *sigar, } match_pid = strtoull(buffer, &ptr, 10); if (strtonum_failed(buffer, ptr)) { - return SIGAR_PTQL_MALFORMED_QUERY; + return errno; } } else if (branch->flags == PTQL_PID_SERVICE) { @@ -711,7 +708,7 @@ static int ptql_args_branch_init(ptql_parse_branch_t *parsed, if (strtonum_failed(parsed->attr, end)) { /* conversion failed */ - return SIGAR_PTQL_MALFORMED_QUERY; + return errno; } } return SIGAR_OK; @@ -830,7 +827,7 @@ static int ptql_branch_init_port(ptql_parse_branch_t *parsed, branch->flags = SIGAR_NETCONN_UDP; } else { - return SIGAR_PTQL_MALFORMED_QUERY; + return EINVAL; } branch->data.ui32 = atoi(parsed->value); /*XXX*/ @@ -1005,7 +1002,7 @@ static int ptql_branch_parse(char *query, ptql_parse_branch_t *branch) branch->op_flags |= PTQL_OP_FLAG_PARENT; break; default: - return SIGAR_PTQL_MALFORMED_QUERY; + return EINVAL; } ++query; @@ -1142,7 +1139,7 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed, if (!is_set) { branch->value.ui64 = strtoull(parsed->value, &ptr, 10); if (strtonum_failed(parsed->value, ptr)) { - return SIGAR_PTQL_MALFORMED_QUERY; + return errno; } } break; @@ -1151,7 +1148,7 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed, if (!is_set) { branch->value.ui32 = strtoul(parsed->value, &ptr, 10); if (strtonum_failed(parsed->value, ptr)) { - return SIGAR_PTQL_MALFORMED_QUERY; + return errno; } } break; @@ -1160,7 +1157,7 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed, if (!is_set) { branch->value.dbl = strtod(parsed->value, &ptr); if (strtonum_failed(parsed->value, ptr)) { - return SIGAR_PTQL_MALFORMED_QUERY; + return errno; } } break;