@@ -1846,14 +1846,37 @@ int main(int argc, char* argv[]) {
18461846 strcpy (filename , mount_dir );
18471847 strcat (filename , "/AppRun" );
18481848
1849- /* Close the keepalive pipe before exec to ensure FUSE daemon terminates when we exit */
1850- close (keepalive_pipe [0 ]);
1849+ /* Fork before exec to ensure we can close the keepalive pipe after AppRun exits */
1850+ pid_t apprun_pid = fork ();
1851+ if (apprun_pid == -1 ) {
1852+ perror ("fork error" );
1853+ exit (EXIT_EXECERROR );
1854+ }
18511855
1852- /* TODO: Find a way to get the exit status and/or output of this */
1853- execv (filename , real_argv );
1854- /* Error if we continue here */
1855- perror ("execv error" );
1856- exit (EXIT_EXECERROR );
1856+ if (apprun_pid == 0 ) {
1857+ /* Child process - exec AppRun */
1858+ execv (filename , real_argv );
1859+ /* Error if we continue here */
1860+ perror ("execv error" );
1861+ exit (EXIT_EXECERROR );
1862+ } else {
1863+ /* Parent process - wait for AppRun to finish, then close pipe */
1864+ int status ;
1865+ waitpid (apprun_pid , & status , 0 );
1866+
1867+ /* Close the keepalive pipe after AppRun exits to terminate FUSE daemon */
1868+ close (keepalive_pipe [0 ]);
1869+
1870+ /* Exit with the same status as AppRun */
1871+ if (WIFEXITED (status )) {
1872+ exit (WEXITSTATUS (status ));
1873+ } else if (WIFSIGNALED (status )) {
1874+ /* Child was killed by a signal, exit with 128 + signal number */
1875+ exit (128 + WTERMSIG (status ));
1876+ } else {
1877+ exit (EXIT_EXECERROR );
1878+ }
1879+ }
18571880 }
18581881
18591882 return 0 ;
0 commit comments