diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-02-01 20:32:19 -0500 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-02-01 20:32:19 -0500 |
commit | 7705add9aef2c188f8dd0f896402833a12812d33 (patch) | |
tree | 30dc81e68e031a99c528ae2a84e89b66f9929c12 | |
parent | 14003545bca64d270621caad2f565bd224a10e1b (diff) | |
download | ktrace-7705add9aef2c188f8dd0f896402833a12812d33.tar.gz |
ktrace: Have event_completion() be extendable
Currently event_completion() uses its own counter for the ccli_list_add*()
functions. This means something that calls it can not add to the list.
Have the counter passed to event_completion() such that the caller has
more control.
Also combine enable_event_completion() with disable_event_completion()
into disenable_event_completion() as the code for both became a bit more
complex, but is still exactly the same.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | src/create.c | 18 | ||||
-rw-r--r-- | src/enable.c | 32 | ||||
-rw-r--r-- | src/ktrace.h | 2 |
3 files changed, 24 insertions, 28 deletions
diff --git a/src/create.c b/src/create.c index 3b5eaf7..1cd1236 100644 --- a/src/create.c +++ b/src/create.c @@ -733,14 +733,13 @@ static int kprobe_completion(struct ccli *ccli, void *data, } int event_completion(struct ccli *ccli, struct tep_handle *tep, - char ***list, char *match, char append) + char ***list, int *cnt, char *match, char append) { char **systems; char **events; char *system; char *event; char *p; - int cnt = 0; int ret = 0; int i; @@ -761,11 +760,11 @@ int event_completion(struct ccli *ccli, struct tep_handle *tep, if (ret < 0) break; if (append && event && !strcmp(event, match)) { - ret = ccli_list_add_printf(ccli, list, &cnt, + ret = ccli_list_add_printf(ccli, list, cnt, "%s.", event); free(event); } else { - ret = ccli_list_insert(ccli, list, &cnt, event); + ret = ccli_list_insert(ccli, list, cnt, event); } } tracefs_list_free(events); @@ -775,7 +774,7 @@ int event_completion(struct ccli *ccli, struct tep_handle *tep, return 0; for (i = 0; ret >= 0 && systems[i]; i++) - ret = ccli_list_add(ccli, list, &cnt, systems[i]); + ret = ccli_list_add(ccli, list, cnt, systems[i]); tracefs_list_free(systems); /* Use '/' as a delim */ @@ -847,7 +846,10 @@ static int eprobe_completion(struct ccli *ccli, void *data, ccli_line_refresh(ccli); return 0; case 1: - return event_completion(ccli, tep, list, match, 0); + ret = event_completion(ccli, tep, list, &cnt, match, 0); + if (ret < 0) + ccli_list_free(ccli, list, cnt); + return ret; default: event = find_event(tep, argv[1]); if (!event) { @@ -1087,10 +1089,12 @@ static int synthetic_completion(struct ccli *ccli, void *data, if (strchr(match, '.')) return append_event_field(ccli, tep, list, argv[word], match); - ret = event_completion(ccli, tep, list, match, '.'); + ret = event_completion(ccli, tep, list, &cnt, match, '.'); /* Do not add a space if this is an event */ if (ret > 0 && !match[len]) match[len] = CCLI_NOSPACE; + if (ret < 0) + ccli_list_free(ccli, list, cnt); return ret; default: p = strchr(match, '='); diff --git a/src/enable.c b/src/enable.c index d670ccf..c17909e 100644 --- a/src/enable.c +++ b/src/enable.c @@ -121,27 +121,19 @@ int cmd_disable(struct ccli *ccli, const char *command, const char *line, return 0; } -static int enable_event_completion(struct ccli *ccli, void *data, - int argc, char **argv, - char ***list, int word, char *match) -{ - struct tep_handle *tep = data; - - if (word == 0) - return event_completion(ccli, tep, list, match, 0); - - return 0; -} - -static int disable_event_completion(struct ccli *ccli, void *data, - int argc, char **argv, - char ***list, int word, char *match) +static int disenable_event_completion(struct ccli *ccli, void *data, + int argc, char **argv, + char ***list, int word, char *match) { struct tep_handle *tep = data; + int cnt = 0; + int ret = 0; if (word == 0) - return event_completion(ccli, tep, list, match, 0); + ret = event_completion(ccli, tep, list, &cnt, match, 0); + if (ret < 0) + ccli_list_free(ccli, list, cnt); return 0; } @@ -167,8 +159,8 @@ int enable_completion(struct ccli *ccli, const char *command, return 0; if (strcmp(argv[1], "event") == 0) - ret = enable_event_completion(ccli, data, argc - 2, argv + 2, - list, word - 2, match); + ret = disenable_event_completion(ccli, data, argc - 2, argv + 2, + list, word - 2, match); ccli_argv_free(argv); @@ -198,8 +190,8 @@ int disable_completion(struct ccli *ccli, const char *command, return 0; if (strcmp(argv[1], "event") == 0) - ret = disable_event_completion(ccli, data, argc - 2, argv + 2, - list, word - 2, match); + ret = disenable_event_completion(ccli, data, argc - 2, argv + 2, + list, word - 2, match); ccli_argv_free(argv); diff --git a/src/ktrace.h b/src/ktrace.h index 27fab9a..11e1b83 100644 --- a/src/ktrace.h +++ b/src/ktrace.h @@ -33,6 +33,6 @@ int cmd_disable(struct ccli *ccli, const char *command, const char *line, struct tep_event *find_event(struct tep_handle *tep, char *ename); int event_completion(struct ccli *ccli, struct tep_handle *tep, - char ***list, char *match, char append); + char ***list, int *cnt, char *match, char append); #endif |