Created
September 1, 2016 11:13
-
-
Save RoliSoft/84813cc353caec614dee8bf74c1b09ef to your computer and use it in GitHub Desktop.
Small lib to mock chroot() for pacman in Arch Linux running under WSL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc libmockchroot.c -shared -fPIC -ldl -o /lib64/libmockchroot.so | |
// echo "/lib64/libmockchroot.so" >> /etc/ld.so.preload | |
#define _GNU_SOURCE | |
#include <unistd.h> | |
#include <libgen.h> | |
#include <dlfcn.h> | |
#include <linux/limits.h> | |
#include <string.h> | |
int chroot(const char *path) | |
{ | |
// return 0 for pacman | |
char dest[PATH_MAX]; | |
if (readlink("/proc/self/exe", dest, PATH_MAX) != -1) { | |
char* file = basename(dest); | |
if (strcmp(file, "pacman") == 0) { | |
return 0; | |
} | |
} | |
// passthrough for others, | |
// currently results in -1 and errno=38 | |
int (*_chroot)(const char*); | |
_chroot = dlsym(RTLD_NEXT, "chroot"); | |
return (*_chroot)(path); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment