This commit is contained in:
kit 2026-05-18 16:11:59 -04:00
commit aa9512d232
3 changed files with 54 additions and 0 deletions

31
exec-in-chroot.c Normal file
View file

@ -0,0 +1,31 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
const char *chroot_path = "/mnt/nfs/chroots/ff-build";
int main (int argc, char **argv) {
uid_t user = getuid ();
char *cwd = getcwd (NULL, 0);
if (chroot (chroot_path) != 0) {
perror ("chroot");
return errno;
}
if (seteuid (user) != 0) {
perror ("seteuid");
return errno;
}
if (chdir (cwd) != 0) {
perror ("chdir");
chdir ("/");
}
free (cwd);
execvp (argv [0], &argv [0]);
perror ("execvp");
return errno;
}