this repo has no description
at fixPythonPipStalling 57 lines 941 B view raw
1#include <stdio.h> 2#include <stdlib.h> 3#include <unistd.h> 4#include <fcntl.h> 5#include <errno.h> 6 7extern int lkm_call(int nr, ...); 8extern int __darling_vchroot(int dfd); 9 10int main(int argc, const char** argv) 11{ 12 if (argc < 3) 13 { 14 fprintf(stderr, "vchroot <dir> <binary> [args...]\n"); 15 return 1; 16 } 17 18 char buf[4096]; 19 sprintf(buf, "%s%s", argv[1], argv[2]); 20 21 if (access(buf, F_OK) != 0) 22 { 23 fprintf(stderr, "Target executable not found: %s\n", buf); 24 return 5; 25 } 26 27 int dfd = open(argv[1], O_RDONLY | O_DIRECTORY); 28 if (dfd == -1) 29 { 30 perror("open"); 31 return 1; 32 } 33 34 if (fchdir(dfd) == -1) 35 { 36 perror("fchdir"); 37 return 2; 38 } 39 40 if (__darling_vchroot(dfd) < 0) 41 { 42 perror("vchroot"); 43 return 3; 44 } 45 46 close(dfd); 47 48 // This is only needed for this binary and shouldn't be passed down 49 unsetenv("DYLD_ROOT_PATH"); 50 51 // printf("Will execv %s\n", argv[2]); 52 execv(argv[2], (char * const *) argv+2); 53 perror("execv"); 54 55 return 4; 56} 57