diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2013-12-12 02:36:14 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-12-13 08:30:22 -0500 |
commit | 69c770a690422c6cdc4ea52d9edbba7c20cd1aff (patch) | |
tree | a7aa0eb0d68c931ffc0976c27aa884b8581eef3d /tools/lib | |
parent | 42d6194d133cbaf12f34cbdc4111bd8f7dc0ed2a (diff) |
tools lib traceevent: Make pevent_filter_add_filter_str() return pevent_errno
Refactor the pevent_filter_add_filter_str() to return a proper error
code and get rid of the third error_str argument.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386833777-3790-12-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/traceevent/event-parse.h | 8 | ||||
-rw-r--r-- | tools/lib/traceevent/parse-filter.c | 78 |
2 files changed, 27 insertions, 59 deletions
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h index da942d59cc3a..089964e56ed4 100644 --- a/tools/lib/traceevent/event-parse.h +++ b/tools/lib/traceevent/event-parse.h | |||
@@ -372,7 +372,8 @@ enum pevent_flag { | |||
372 | _PE(ILLEGAL_TOKEN, "illegal token"), \ | 372 | _PE(ILLEGAL_TOKEN, "illegal token"), \ |
373 | _PE(INVALID_PAREN, "open parenthesis cannot come here"), \ | 373 | _PE(INVALID_PAREN, "open parenthesis cannot come here"), \ |
374 | _PE(UNBALANCED_PAREN, "unbalanced number of parenthesis"), \ | 374 | _PE(UNBALANCED_PAREN, "unbalanced number of parenthesis"), \ |
375 | _PE(UNKNOWN_TOKEN, "unknown token") | 375 | _PE(UNKNOWN_TOKEN, "unknown token"), \ |
376 | _PE(FILTER_NOT_FOUND, "no filter found") | ||
376 | 377 | ||
377 | #undef _PE | 378 | #undef _PE |
378 | #define _PE(__code, __str) PEVENT_ERRNO__ ## __code | 379 | #define _PE(__code, __str) PEVENT_ERRNO__ ## __code |
@@ -863,9 +864,8 @@ enum filter_trivial_type { | |||
863 | FILTER_TRIVIAL_BOTH, | 864 | FILTER_TRIVIAL_BOTH, |
864 | }; | 865 | }; |
865 | 866 | ||
866 | int pevent_filter_add_filter_str(struct event_filter *filter, | 867 | enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter, |
867 | const char *filter_str, | 868 | const char *filter_str); |
868 | char **error_str); | ||
869 | 869 | ||
870 | 870 | ||
871 | int pevent_filter_match(struct event_filter *filter, | 871 | int pevent_filter_match(struct event_filter *filter, |
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c index 5aa5012a17ee..78440d73e0ad 100644 --- a/tools/lib/traceevent/parse-filter.c +++ b/tools/lib/traceevent/parse-filter.c | |||
@@ -1209,7 +1209,7 @@ process_filter(struct event_format *event, struct filter_arg **parg, | |||
1209 | return ret; | 1209 | return ret; |
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | static int | 1212 | static enum pevent_errno |
1213 | process_event(struct event_format *event, const char *filter_str, | 1213 | process_event(struct event_format *event, const char *filter_str, |
1214 | struct filter_arg **parg, char **error_str) | 1214 | struct filter_arg **parg, char **error_str) |
1215 | { | 1215 | { |
@@ -1218,21 +1218,15 @@ process_event(struct event_format *event, const char *filter_str, | |||
1218 | pevent_buffer_init(filter_str, strlen(filter_str)); | 1218 | pevent_buffer_init(filter_str, strlen(filter_str)); |
1219 | 1219 | ||
1220 | ret = process_filter(event, parg, error_str, 0); | 1220 | ret = process_filter(event, parg, error_str, 0); |
1221 | if (ret == 1) { | ||
1222 | show_error(error_str, | ||
1223 | "Unbalanced number of ')'"); | ||
1224 | return -1; | ||
1225 | } | ||
1226 | if (ret < 0) | 1221 | if (ret < 0) |
1227 | return ret; | 1222 | return ret; |
1228 | 1223 | ||
1229 | /* If parg is NULL, then make it into FALSE */ | 1224 | /* If parg is NULL, then make it into FALSE */ |
1230 | if (!*parg) { | 1225 | if (!*parg) { |
1231 | *parg = allocate_arg(); | 1226 | *parg = allocate_arg(); |
1232 | if (*parg == NULL) { | 1227 | if (*parg == NULL) |
1233 | show_error(error_str, "failed to allocate filter arg"); | 1228 | return PEVENT_ERRNO__MEM_ALLOC_FAILED; |
1234 | return -1; | 1229 | |
1235 | } | ||
1236 | (*parg)->type = FILTER_ARG_BOOLEAN; | 1230 | (*parg)->type = FILTER_ARG_BOOLEAN; |
1237 | (*parg)->boolean.value = FILTER_FALSE; | 1231 | (*parg)->boolean.value = FILTER_FALSE; |
1238 | } | 1232 | } |
@@ -1240,13 +1234,13 @@ process_event(struct event_format *event, const char *filter_str, | |||
1240 | return 0; | 1234 | return 0; |
1241 | } | 1235 | } |
1242 | 1236 | ||
1243 | static int filter_event(struct event_filter *filter, | 1237 | static enum pevent_errno |
1244 | struct event_format *event, | 1238 | filter_event(struct event_filter *filter, struct event_format *event, |
1245 | const char *filter_str, char **error_str) | 1239 | const char *filter_str, char **error_str) |
1246 | { | 1240 | { |
1247 | struct filter_type *filter_type; | 1241 | struct filter_type *filter_type; |
1248 | struct filter_arg *arg; | 1242 | struct filter_arg *arg; |
1249 | int ret; | 1243 | enum pevent_errno ret; |
1250 | 1244 | ||
1251 | if (filter_str) { | 1245 | if (filter_str) { |
1252 | ret = process_event(event, filter_str, &arg, error_str); | 1246 | ret = process_event(event, filter_str, &arg, error_str); |
@@ -1256,20 +1250,16 @@ static int filter_event(struct event_filter *filter, | |||
1256 | } else { | 1250 | } else { |
1257 | /* just add a TRUE arg */ | 1251 | /* just add a TRUE arg */ |
1258 | arg = allocate_arg(); | 1252 | arg = allocate_arg(); |
1259 | if (arg == NULL) { | 1253 | if (arg == NULL) |
1260 | show_error(error_str, "failed to allocate filter arg"); | 1254 | return PEVENT_ERRNO__MEM_ALLOC_FAILED; |
1261 | return -1; | 1255 | |
1262 | } | ||
1263 | arg->type = FILTER_ARG_BOOLEAN; | 1256 | arg->type = FILTER_ARG_BOOLEAN; |
1264 | arg->boolean.value = FILTER_TRUE; | 1257 | arg->boolean.value = FILTER_TRUE; |
1265 | } | 1258 | } |
1266 | 1259 | ||
1267 | filter_type = add_filter_type(filter, event->id); | 1260 | filter_type = add_filter_type(filter, event->id); |
1268 | if (filter_type == NULL) { | 1261 | if (filter_type == NULL) |
1269 | show_error(error_str, "failed to add a new filter: %s", | 1262 | return PEVENT_ERRNO__MEM_ALLOC_FAILED; |
1270 | filter_str ? filter_str : "true"); | ||
1271 | return -1; | ||
1272 | } | ||
1273 | 1263 | ||
1274 | if (filter_type->filter) | 1264 | if (filter_type->filter) |
1275 | free_arg(filter_type->filter); | 1265 | free_arg(filter_type->filter); |
@@ -1282,18 +1272,12 @@ static int filter_event(struct event_filter *filter, | |||
1282 | * pevent_filter_add_filter_str - add a new filter | 1272 | * pevent_filter_add_filter_str - add a new filter |
1283 | * @filter: the event filter to add to | 1273 | * @filter: the event filter to add to |
1284 | * @filter_str: the filter string that contains the filter | 1274 | * @filter_str: the filter string that contains the filter |
1285 | * @error_str: string containing reason for failed filter | ||
1286 | * | ||
1287 | * Returns 0 if the filter was successfully added | ||
1288 | * -1 if there was an error. | ||
1289 | * | 1275 | * |
1290 | * On error, if @error_str points to a string pointer, | 1276 | * Returns 0 if the filter was successfully added or a |
1291 | * it is set to the reason that the filter failed. | 1277 | * negative error code. |
1292 | * This string must be freed with "free". | ||
1293 | */ | 1278 | */ |
1294 | int pevent_filter_add_filter_str(struct event_filter *filter, | 1279 | enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter, |
1295 | const char *filter_str, | 1280 | const char *filter_str) |
1296 | char **error_str) | ||
1297 | { | 1281 | { |
1298 | struct pevent *pevent = filter->pevent; | 1282 | struct pevent *pevent = filter->pevent; |
1299 | struct event_list *event; | 1283 | struct event_list *event; |
@@ -1304,23 +1288,20 @@ int pevent_filter_add_filter_str(struct event_filter *filter, | |||
1304 | char *event_name = NULL; | 1288 | char *event_name = NULL; |
1305 | char *sys_name = NULL; | 1289 | char *sys_name = NULL; |
1306 | char *sp; | 1290 | char *sp; |
1307 | int rtn = 0; | 1291 | enum pevent_errno rtn = 0; /* PEVENT_ERRNO__SUCCESS */ |
1308 | int len; | 1292 | int len; |
1309 | int ret; | 1293 | int ret; |
1294 | char *error_str = NULL; | ||
1310 | 1295 | ||
1311 | /* clear buffer to reset show error */ | 1296 | /* clear buffer to reset show error */ |
1312 | pevent_buffer_init("", 0); | 1297 | pevent_buffer_init("", 0); |
1313 | 1298 | ||
1314 | if (error_str) | ||
1315 | *error_str = NULL; | ||
1316 | |||
1317 | filter_start = strchr(filter_str, ':'); | 1299 | filter_start = strchr(filter_str, ':'); |
1318 | if (filter_start) | 1300 | if (filter_start) |
1319 | len = filter_start - filter_str; | 1301 | len = filter_start - filter_str; |
1320 | else | 1302 | else |
1321 | len = strlen(filter_str); | 1303 | len = strlen(filter_str); |
1322 | 1304 | ||
1323 | |||
1324 | do { | 1305 | do { |
1325 | next_event = strchr(filter_str, ','); | 1306 | next_event = strchr(filter_str, ','); |
1326 | if (next_event && | 1307 | if (next_event && |
@@ -1333,10 +1314,9 @@ int pevent_filter_add_filter_str(struct event_filter *filter, | |||
1333 | 1314 | ||
1334 | this_event = malloc(len + 1); | 1315 | this_event = malloc(len + 1); |
1335 | if (this_event == NULL) { | 1316 | if (this_event == NULL) { |
1336 | show_error(error_str, "Memory allocation failure"); | ||
1337 | /* This can only happen when events is NULL, but still */ | 1317 | /* This can only happen when events is NULL, but still */ |
1338 | free_events(events); | 1318 | free_events(events); |
1339 | return -1; | 1319 | return PEVENT_ERRNO__MEM_ALLOC_FAILED; |
1340 | } | 1320 | } |
1341 | memcpy(this_event, filter_str, len); | 1321 | memcpy(this_event, filter_str, len); |
1342 | this_event[len] = 0; | 1322 | this_event[len] = 0; |
@@ -1350,30 +1330,18 @@ int pevent_filter_add_filter_str(struct event_filter *filter, | |||
1350 | event_name = strtok_r(NULL, "/", &sp); | 1330 | event_name = strtok_r(NULL, "/", &sp); |
1351 | 1331 | ||
1352 | if (!sys_name) { | 1332 | if (!sys_name) { |
1353 | show_error(error_str, "No filter found"); | ||
1354 | /* This can only happen when events is NULL, but still */ | 1333 | /* This can only happen when events is NULL, but still */ |
1355 | free_events(events); | 1334 | free_events(events); |
1356 | free(this_event); | 1335 | free(this_event); |
1357 | return -1; | 1336 | return PEVENT_ERRNO__FILTER_NOT_FOUND; |
1358 | } | 1337 | } |
1359 | 1338 | ||
1360 | /* Find this event */ | 1339 | /* Find this event */ |
1361 | ret = find_event(pevent, &events, strim(sys_name), strim(event_name)); | 1340 | ret = find_event(pevent, &events, strim(sys_name), strim(event_name)); |
1362 | if (ret < 0) { | 1341 | if (ret < 0) { |
1363 | if (ret == PEVENT_ERRNO__MEM_ALLOC_FAILED) | ||
1364 | show_error(error_str, | ||
1365 | "Memory allocation failure"); | ||
1366 | else if (event_name) | ||
1367 | show_error(error_str, | ||
1368 | "No event found under '%s.%s'", | ||
1369 | sys_name, event_name); | ||
1370 | else | ||
1371 | show_error(error_str, | ||
1372 | "No event found under '%s'", | ||
1373 | sys_name); | ||
1374 | free_events(events); | 1342 | free_events(events); |
1375 | free(this_event); | 1343 | free(this_event); |
1376 | return -1; | 1344 | return ret; |
1377 | } | 1345 | } |
1378 | free(this_event); | 1346 | free(this_event); |
1379 | } while (filter_str); | 1347 | } while (filter_str); |
@@ -1385,7 +1353,7 @@ int pevent_filter_add_filter_str(struct event_filter *filter, | |||
1385 | /* filter starts here */ | 1353 | /* filter starts here */ |
1386 | for (event = events; event; event = event->next) { | 1354 | for (event = events; event; event = event->next) { |
1387 | ret = filter_event(filter, event->event, filter_start, | 1355 | ret = filter_event(filter, event->event, filter_start, |
1388 | error_str); | 1356 | &error_str); |
1389 | /* Failures are returned if a parse error happened */ | 1357 | /* Failures are returned if a parse error happened */ |
1390 | if (ret < 0) | 1358 | if (ret < 0) |
1391 | rtn = ret; | 1359 | rtn = ret; |