38 lines
1.2 KiB
C
38 lines
1.2 KiB
C
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
const char *appdir = "/root/linuxdeploy-root";
|
|
char apprun[256], ldbin[256], new_path[4096];
|
|
struct stat st;
|
|
|
|
snprintf(apprun, sizeof(apprun), "%s/AppRun", appdir);
|
|
snprintf(ldbin, sizeof(ldbin), "%s/usr/bin/linuxdeploy", appdir);
|
|
|
|
fprintf(stderr, "[ld-wrapper] APPDIR=%s\n", appdir);
|
|
fprintf(stderr, "[ld-wrapper] AppRun exists: %s\n", stat(apprun, &st) == 0 ? "yes" : "NO");
|
|
fprintf(stderr, "[ld-wrapper] linuxdeploy exists: %s\n", stat(ldbin, &st) == 0 ? "yes" : "NO");
|
|
fflush(stderr);
|
|
|
|
setenv("APPDIR", appdir, 1);
|
|
char *old_path = getenv("PATH");
|
|
snprintf(new_path, sizeof(new_path), "%s/usr/bin:%s", appdir, old_path ? old_path : "");
|
|
setenv("PATH", new_path, 1);
|
|
|
|
if (stat(ldbin, &st) == 0) {
|
|
fprintf(stderr, "[ld-wrapper] exec %s\n", ldbin);
|
|
fflush(stderr);
|
|
execv(ldbin, argv);
|
|
perror("[ld-wrapper] execv linuxdeploy");
|
|
}
|
|
|
|
fprintf(stderr, "[ld-wrapper] fallback exec %s\n", apprun);
|
|
fflush(stderr);
|
|
execv(apprun, argv);
|
|
perror("[ld-wrapper] execv AppRun");
|
|
return 1;
|
|
}
|