Skip to content

Commit 3b4d928

Browse files
committed
record: skip whitespaces after shebang for scripts
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]>
1 parent 788b200 commit 3b4d928

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

cmds/record.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ static void check_binary(struct uftrace_opts *opts)
16081608
pr_err("Cannot read '%s'", opts->exename);
16091609

16101610
if (memcmp(elf_ident, ELFMAG, SELFMAG)) {
1611-
char *script = check_script_file(opts->exename);
1611+
char *script = str_ltrim(check_script_file(opts->exename));
16121612
char *p;
16131613

16141614
if (script == NULL)

utils/utils.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,37 @@ char *strjoin(char *left, char *right, const char *delim)
594594
return new;
595595
}
596596

597+
/**
598+
* str_ltrim - to trim left spaces
599+
* @str: input string
600+
*
601+
* This function make @str to left trimmed @str
602+
*/
603+
char *str_ltrim(char *str)
604+
{
605+
if (!str)
606+
return NULL;
607+
while (isspace((unsigned char)*str)) {
608+
str++;
609+
}
610+
return str;
611+
}
612+
613+
/**
614+
* str_rtrim - to trim right spaces
615+
* @str: input string
616+
*
617+
* This function make @str to right trimmed @str
618+
*/
619+
char *str_rtrim(char *str)
620+
{
621+
char *p = strchr(str, '\0');
622+
while (--p >= str && isspace(*p))
623+
;
624+
*(p + 1) = '\0';
625+
return str;
626+
}
627+
597628
/**
598629
* strv_split - split given string and construct a string vector
599630
* @strv: string vector

utils/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ void strv_append(struct strv *strv, const char *str);
389389
void strv_replace(struct strv *strv, int idx, const char *str);
390390
char *strv_join(struct strv *strv, const char *delim);
391391
void strv_free(struct strv *strv);
392+
char *str_ltrim(char *str);
393+
char *str_rtrim(char *str);
392394

393395
char **parse_cmdline(char *cmd, int *argc);
394396
void free_parsed_cmdline(char **argv);

0 commit comments

Comments
 (0)