-
Notifications
You must be signed in to change notification settings - Fork 28
Fix orphaned FUSE daemon process after AppImage exit #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
8
commits into
main
Choose a base branch
from
copilot/fix-orphaned-process-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7a71e24
Initial plan
Copilot aac2e8b
Close keepalive pipe before execv to prevent FUSE daemon orphan
Copilot 3828d3a
Final verification and documentation
Copilot adc00d4
Remove codeql artifact and add to gitignore
Copilot 2442c30
Fork before exec to close keepalive pipe after AppRun exits
Copilot 876881d
Address code review feedback: close pipes, check waitpid, fix memory …
Copilot f66ad0d
Update src/runtime/runtime.c
probonopd 38a08cc
Update src/runtime/runtime.c
probonopd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,3 +67,4 @@ squashfs-root/ | |
|
|
||
| # build products | ||
| src/runtime/runtime | ||
| _codeql_detected_source_root | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1846,11 +1846,52 @@ int main(int argc, char* argv[]) { | |
| strcpy(filename, mount_dir); | ||
| strcat(filename, "/AppRun"); | ||
|
|
||
| /* TODO: Find a way to get the exit status and/or output of this */ | ||
| execv(filename, real_argv); | ||
| /* Error if we continue here */ | ||
| perror("execv error"); | ||
| exit(EXIT_EXECERROR); | ||
| /* Fork before exec to ensure we can close the keepalive pipe after AppRun exits */ | ||
| pid_t apprun_pid = fork(); | ||
| if (apprun_pid == -1) { | ||
| perror("fork error"); | ||
| exit(EXIT_EXECERROR); | ||
| } | ||
|
|
||
| if (apprun_pid == 0) { | ||
| /* Child process - close keepalive pipe before exec */ | ||
| close(keepalive_pipe[0]); | ||
|
|
||
| /* exec AppRun */ | ||
| execv(filename, real_argv); | ||
| /* Error if we continue here */ | ||
| perror("execv error"); | ||
| exit(EXIT_EXECERROR); | ||
| } else { | ||
| /* Parent process - wait for AppRun to finish, then close pipe */ | ||
| int status; | ||
| pid_t waited_pid; | ||
| do { | ||
| waited_pid = waitpid(apprun_pid, &status, 0); | ||
| } while (waited_pid == -1 && errno == EINTR); | ||
| if (waited_pid == -1) { | ||
| perror("waitpid error"); | ||
| close(keepalive_pipe[0]); | ||
| free(real_argv); | ||
| exit(EXIT_EXECERROR); | ||
| } | ||
|
|
||
| /* Close the keepalive pipe after AppRun exits to terminate FUSE daemon */ | ||
| close(keepalive_pipe[0]); | ||
|
|
||
| /* Free allocated memory before exit */ | ||
| free(real_argv); | ||
|
|
||
| /* Exit with the same status as AppRun */ | ||
| if (WIFEXITED(status)) { | ||
| exit(WEXITSTATUS(status)); | ||
| } else if (WIFSIGNALED(status)) { | ||
| /* Child was killed by a signal, exit with 128 + signal number */ | ||
| exit(128 + WTERMSIG(status)); | ||
| } else { | ||
| exit(EXIT_EXECERROR); | ||
|
Comment on lines
+1886
to
+1892
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The child process inherits both ends of the keepalive pipe but doesn't use them. Both pipe ends should be closed before execv() to prevent the child from holding unnecessary file descriptors. Add
close(keepalive_pipe[0]);andclose(keepalive_pipe[1]);before the execv call on line 1858.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an obvious oversight that was there before. I am just a little concerned that the pipe loses its usefulness when it is closed here already. (Yes, technically the parent process would keep its side open anyway).
This needs to be tested thoroughly. The nature of the bug requires a quite sophisticated setup, though, which is time consuming.