mirror of
https://github.com/dvorka/hstr.git
synced 2024-09-20 23:06:17 +08:00
Make get_process_name_by_pid more robust and cross-platform by falling back to $SHELL environment variable
This commit is contained in:
parent
32683a3876
commit
d0d346a094
|
@ -144,6 +144,14 @@ char *get_process_name_by_pid(const int pid)
|
|||
fclose(f);
|
||||
}
|
||||
}
|
||||
// if name isn't e.g. bash/zsh at this point, fall back to $SHELL
|
||||
if(strlen(name) > 4){
|
||||
char* shell = strrchr(getenv("SHELL"),'/');
|
||||
if(shell != NULL){
|
||||
shell++;
|
||||
strncpy(name,shell,sizeof(char)*sizeof(name));
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue