initial
This commit is contained in:
commit
aa9512d232
3 changed files with 54 additions and 0 deletions
18
Makefile
Executable file
18
Makefile
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/make
|
||||
|
||||
CFLAGS ?= -Ofast -march=native -mtune=native -static -Wall -Wextra -Wpedantic
|
||||
|
||||
./exec-in-chroot: ./exec-in-chroot.c
|
||||
|
||||
.PHONY: install uninstall clean
|
||||
install: ./exec-in-chroot
|
||||
cp "$<" "${PREFIX}/bin/exec-in-chroot"
|
||||
chmod 4555 "${PREFIX}/bin/exec-in-chroot"
|
||||
cp -n "./exec-in-chroot.conf" "/etc/exec-in-chroot.conf"
|
||||
|
||||
uninstall:
|
||||
rm "${PREFIX}/bin/exec-in-chroot"
|
||||
rm "/etc/exec-in-chroot.conf"
|
||||
|
||||
clean:
|
||||
rm ./exec-in-chroot
|
||||
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;
|
||||
}
|
||||
5
exec-in-chroot.conf
Normal file
5
exec-in-chroot.conf
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# invoked_name chroot_path binary
|
||||
inv1 /path/1 bin1
|
||||
inv2 /path/2
|
||||
inv3
|
||||
inv4 /path/3 bin2
|
||||
Loading…
Add table
Add a link
Reference in a new issue