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: #1690

Signed-off-by: Gabriel Kim <[email protected]>
  • Loading branch information
GabrielKimm committed Jul 30, 2023
1 parent 534a366 commit e5d3207
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
46 changes: 27 additions & 19 deletions utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,30 +598,38 @@ char *strjoin(char *left, char *right, const char *delim)
* str_trim - to trim all spaces
* @str: input string
*
* This function make @str to right trimmed @str
* This function make @str to all trimmed @str
*/
char *str_trim(char *str)
{
int i = 0;
int j = 0;
bool spaceFound = false;

if (!str)
return NULL;

while (str[j]) {
if (str[j] != ' ' || !spaceFound) {
str[i] = str[j];
i++;
spaceFound = (str[j] == ' ');
}
j++;
}
str = str_ltrim(str);
str = str_rtrim(str);
return str;
}

if (i > 0 && str[i - 1] == ' ')
i--;
/**
* str_ltrim - to trim left spaces
* @str: input string
*
* This function make @str to left trimmed @str
*/
char *str_ltrim(char *str)
{
return str_trim(str);
}

str[i] = '\0';
/**
* 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;
}

Expand Down
2 changes: 2 additions & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ 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_trim(char *str);
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 e5d3207

Please sign in to comment.