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:

  #! /usr/bin/env python3

This patch makes uftrace to understand the above shebang as well.

Fixed: namhyung#1690
Signed-off-by: Yi Hong <[email protected]>
  • Loading branch information
yihong0618 committed May 11, 2023
1 parent 788b200 commit 3b4d928
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmds/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ 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);
char *script = str_ltrim(check_script_file(opts->exename));
char *p;

if (script == NULL)
Expand Down
31 changes: 31 additions & 0 deletions utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,37 @@ char *strjoin(char *left, char *right, const char *delim)
return new;
}

/**
* str_ltrim - to trim left spaces
* @str: input string
*
* This function make @str to left trimmed @str
*/
char *str_ltrim(char *str)
{
if (!str)
return NULL;
while (isspace((unsigned char)*str)) {
str++;
}
return str;
}

/**
* str_rtrim - to trim right spaces
* @str: input string
*
* This function make @str to right trimmed @str
*/
char *str_rtrim(char *str)
{
char *p = strchr(str, '\0');
while (--p >= str && isspace(*p))
;
*(p + 1) = '\0';
return str;
}

/**
* strv_split - split given string and construct a string vector
* @strv: string vector
Expand Down
2 changes: 2 additions & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ void strv_append(struct strv *strv, const char *str);
void strv_replace(struct strv *strv, int idx, const char *str);
char *strv_join(struct strv *strv, const char *delim);
void strv_free(struct strv *strv);
char *str_ltrim(char *str);
char *str_rtrim(char *str);

char **parse_cmdline(char *cmd, int *argc);
void free_parsed_cmdline(char **argv);
Expand Down

0 comments on commit 3b4d928

Please sign in to comment.