Skip to content

Commit

Permalink
record: skip whitespaces after shebang for scripts
Browse files Browse the repository at this point in the history
Python tracing won't work when the shebang line has a space like below:

Fixed: namhyung#1690

Signed-off-by: yihong0618 <[email protected]>
  • Loading branch information
yihong0618 committed May 10, 2023
1 parent 788b200 commit 667ffe1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmds/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,8 @@ static void check_binary(struct uftrace_opts *opts)
pr_err("Cannot read '%s'", opts->exename);

if (memcmp(elf_ident, ELFMAG, SELFMAG)) {
char *script = check_script_file(opts->exename);
// for issue 1690 unable to identify shebang when it has initial spaces
char *script = str_trim(check_script_file(opts->exename));
char *p;

if (script == NULL)
Expand Down
25 changes: 25 additions & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,31 @@ static inline char *has_kernel_filter(char *buf)
return NULL;
}

// this code is copy from event-utils.h
static inline char *str_trim(char *string)
{
char *ret;

if (!string)
return NULL;
while (*string) {
if (!isspace(*string))
break;
string++;
}
ret = string;

string = ret + strlen(ret) - 1;
while (string > ret) {
if (!isspace(*string))
break;
string--;
}
string[1] = 0;

return ret;
}

struct uftrace_time_range {
uint64_t first;
uint64_t start;
Expand Down

0 comments on commit 667ffe1

Please sign in to comment.