diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2010-06-15 19:20:05 -0400 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-06-15 19:20:05 -0400 |
| commit | ef643a903732e1c27ceac0cd3505e5ffeb714f17 (patch) | |
| tree | 13fba0f9c93e60036fc6ea65007011bd3e9765ad | |
| parent | 3c4cb6c3330b6ec2a26918c54d62b62fe60ed0a1 (diff) | |
kernelshark: Manually look for trace-cmd in PATH
When executing a record, walk the PATH variable to search for
trace-cmd. If it is not found we can nicely give a warning instead
of trying to execute it.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-capture.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/trace-capture.c b/trace-capture.c index b5e8852..27ae757 100644 --- a/trace-capture.c +++ b/trace-capture.c | |||
| @@ -274,6 +274,51 @@ static int calculate_trace_cmd_words(struct trace_capture *cap) | |||
| 274 | return words; | 274 | return words; |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | static char *find_tracecmd(void) | ||
| 278 | { | ||
| 279 | struct stat st; | ||
| 280 | char *path = getenv("PATH"); | ||
| 281 | char *saveptr; | ||
| 282 | char *str; | ||
| 283 | char *loc; | ||
| 284 | char *tracecmd = NULL; | ||
| 285 | int len; | ||
| 286 | int ret; | ||
| 287 | |||
| 288 | if (!path) | ||
| 289 | return NULL; | ||
| 290 | |||
| 291 | path = strdup(path); | ||
| 292 | |||
| 293 | for (str = path; ; str = NULL) { | ||
| 294 | loc = strtok_r(str, ":", &saveptr); | ||
| 295 | if (!loc) | ||
| 296 | break; | ||
| 297 | len = strlen(loc) + 11; | ||
| 298 | tracecmd = malloc_or_die(len); | ||
| 299 | snprintf(tracecmd, len, "%s/trace-cmd", loc); | ||
| 300 | ret = stat(tracecmd, &st); | ||
| 301 | |||
| 302 | if (ret >= 0 && S_ISREG(st.st_mode)) { | ||
| 303 | /* Do we have execute permissions */ | ||
| 304 | if (st.st_uid == geteuid() && | ||
| 305 | st.st_mode & S_IXUSR) | ||
| 306 | break; | ||
| 307 | if (st.st_gid == getegid() && | ||
| 308 | st.st_mode & S_IXGRP) | ||
| 309 | break; | ||
| 310 | if (st.st_mode & S_IXOTH) | ||
| 311 | break; | ||
| 312 | } | ||
| 313 | |||
| 314 | free(tracecmd); | ||
| 315 | tracecmd = NULL; | ||
| 316 | } | ||
| 317 | free(path); | ||
| 318 | |||
| 319 | return tracecmd; | ||
| 320 | } | ||
| 321 | |||
| 277 | static int add_trace_cmd_words(struct trace_capture *cap, char **args) | 322 | static int add_trace_cmd_words(struct trace_capture *cap, char **args) |
| 278 | { | 323 | { |
| 279 | struct event_format *event; | 324 | struct event_format *event; |
| @@ -286,7 +331,10 @@ static int add_trace_cmd_words(struct trace_capture *cap, char **args) | |||
| 286 | 331 | ||
| 287 | output = gtk_entry_get_text(GTK_ENTRY(cap->file_entry)); | 332 | output = gtk_entry_get_text(GTK_ENTRY(cap->file_entry)); |
| 288 | 333 | ||
| 289 | args[words++] = strdup("trace-cmd"); | 334 | args[words++] = find_tracecmd(); |
| 335 | if (!args[0]) | ||
| 336 | return -1; | ||
| 337 | |||
| 290 | args[words++] = strdup("record"); | 338 | args[words++] = strdup("record"); |
| 291 | args[words++] = strdup("-o"); | 339 | args[words++] = strdup("-o"); |
| 292 | args[words++] = strdup(output); | 340 | args[words++] = strdup(output); |
| @@ -706,6 +754,14 @@ static void execute_button_clicked(GtkWidget *widget, gpointer data) | |||
| 706 | GtkWidget *dialog; | 754 | GtkWidget *dialog; |
| 707 | GtkWidget *label; | 755 | GtkWidget *label; |
| 708 | const char *filename; | 756 | const char *filename; |
| 757 | char *tracecmd; | ||
| 758 | |||
| 759 | tracecmd = find_tracecmd(); | ||
| 760 | if (!tracecmd) { | ||
| 761 | warning("trace-cmd not found in path"); | ||
| 762 | return; | ||
| 763 | } | ||
| 764 | free(tracecmd); | ||
| 709 | 765 | ||
| 710 | filename = gtk_entry_get_text(GTK_ENTRY(cap->file_entry)); | 766 | filename = gtk_entry_get_text(GTK_ENTRY(cap->file_entry)); |
| 711 | 767 | ||
