Skip to content

Commit 6917f75

Browse files
committed
Set typical AppImage vars in extract-and-run mode
1 parent 3934c65 commit 6917f75

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/runtime.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,19 @@ 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+
length = readlink(appimage_path, fullpath, sizeof(fullpath));
612+
fullpath[length] = '\0';
613+
} else {
614+
// If we are operating on a different AppImage than this file
615+
sprintf(fullpath, "%s", appimage_path); // TODO: Make absolute
616+
}
617+
605618
if (arg && strcmp(arg, "appimage-extract-and-run") == 0) {
606619
char* hexlified_digest = NULL;
607620

@@ -662,6 +675,11 @@ int main(int argc, char *argv[]) {
662675
}
663676
new_argv[new_argc] = NULL;
664677

678+
/* Setting some environment variables that the app "inside" might use */
679+
setenv("APPIMAGE", fullpath, 1);
680+
setenv("ARGV0", argv0_path, 1);
681+
setenv("APPDIR", prefix, 1);
682+
665683
execv(apprun_path, new_argv);
666684

667685
int error = errno;
@@ -838,18 +856,6 @@ int main(int argc, char *argv[]) {
838856
for (;;) pause();
839857
}
840858

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-
853859
/* Setting some environment variables that the app "inside" might use */
854860
setenv( "APPIMAGE", fullpath, 1 );
855861
setenv( "ARGV0", argv0_path, 1 );

0 commit comments

Comments
 (0)