@@ -602,6 +602,28 @@ int main(int argc, char *argv[]) {
602602 exit (0 );
603603 }
604604
605+ // calculate full path of AppImage
606+ int length ;
607+ char fullpath [PATH_MAX ];
608+
609+ if (getenv ("TARGET_APPIMAGE" ) == NULL ) {
610+ // If we are operating on this file itself
611+ ssize_t len = readlink (appimage_path , fullpath , sizeof (fullpath ));
612+ if (len < 0 ) {
613+ perror ("Failed to obtain absolute path" );
614+ exit (EXIT_EXECERROR );
615+ }
616+ fullpath [len ] = '\0' ;
617+ } else {
618+ char * abspath = realpath (appimage_path , NULL );
619+ if (abspath == NULL ) {
620+ perror ("Failed to obtain absolute path" );
621+ exit (EXIT_EXECERROR );
622+ }
623+ strcpy (fullpath , abspath );
624+ free (abspath );
625+ }
626+
605627 if (arg && strcmp (arg , "appimage-extract-and-run" ) == 0 ) {
606628 char * hexlified_digest = NULL ;
607629
@@ -662,6 +684,11 @@ int main(int argc, char *argv[]) {
662684 }
663685 new_argv [new_argc ] = NULL ;
664686
687+ /* Setting some environment variables that the app "inside" might use */
688+ setenv ("APPIMAGE" , fullpath , 1 );
689+ setenv ("ARGV0" , argv0_path , 1 );
690+ setenv ("APPDIR" , prefix , 1 );
691+
665692 execv (apprun_path , new_argv );
666693
667694 int error = errno ;
@@ -838,18 +865,6 @@ int main(int argc, char *argv[]) {
838865 for (;;) pause ();
839866 }
840867
841- int length ;
842- char fullpath [PATH_MAX ];
843-
844- if (getenv ("TARGET_APPIMAGE" ) == NULL ){
845- // If we are operating on this file itself
846- length = readlink (appimage_path , fullpath , sizeof (fullpath ));
847- fullpath [length ] = '\0' ;
848- } else {
849- // If we are operating on a different AppImage than this file
850- sprintf (fullpath , "%s" , appimage_path ); // TODO: Make absolute
851- }
852-
853868 /* Setting some environment variables that the app "inside" might use */
854869 setenv ( "APPIMAGE" , fullpath , 1 );
855870 setenv ( "ARGV0" , argv0_path , 1 );
0 commit comments