initial
This commit is contained in:
commit
aa9512d232
3 changed files with 54 additions and 0 deletions
31
exec-in-chroot.c
Normal file
31
exec-in-chroot.c
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue