Closed TheBrokenRail closed 2 years ago
Good catch, I'm not a big fan of having global variables that may affect the users applications (we already have a lot of those). Would not be better to do the chdir restoration in the libapprun_hooks
constructor ? As it's preloaded it will be executed first right ?
https://github.com/AppImageCrafters/AppRun/blob/2496b3929090c58d05ecd2a50d34fbc8262eb64c/src/hooks/main_hook.c#L16
This line of code that runs right before
main
restores the working directory of the parent process. Normally, this works fine. The calling process changes it's working directory so relative interpreters work, then it starts the program, then the hooks restore the current directory right beforemain
.However, there is an issue, if the child process changes its working directory for whatever reason inside of a
__attribute__((constructor))
function, that working directory is overwritten.Suggested fix: Hook
chdir
and set a variable totrue
whenchdir
is called, only restore the original working directory if that variable isfalse
.