Add pivot_root(2)

This commit is contained in:
Michael Santos
2014-11-15 10:17:46 -05:00
parent f55507d906
commit 8ab1b8908b
2 changed files with 41 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ mount/6
mount_define/1
open/3
pid/0
pivot_root/2
prctl/5
prctl_define/1
read/2

View File

@@ -18,6 +18,10 @@
#include <sys/stat.h>
#include <dirent.h>
#ifdef __linux__
#include <linux/unistd.h>
#endif
/*
* chdir(2)
*
@@ -124,6 +128,42 @@ alcove_sys_chroot(alcove_state_t *ap, const char *arg, size_t len,
: alcove_mk_atom(reply, rlen, "ok");
}
/*
* pivot_root(2)
*
*/
ssize_t
alcove_sys_pivot_root(alcove_state_t *ap, const char *arg, size_t len,
char *reply, size_t rlen)
{
#ifdef __linux__
int index = 0;
char new_root[PATH_MAX] = {0};
char put_old[PATH_MAX] = {0};
size_t nlen = sizeof(new_root)-1;
size_t plen = sizeof(put_old)-1;
int rv = 0;
/* new_root */
if (alcove_decode_iolist(arg, len, &index, new_root, &nlen) < 0 ||
nlen == 0)
return -1;
/* put_old */
if (alcove_decode_iolist(arg, len, &index, put_old, &plen) < 0 ||
plen == 0)
return -1;
rv = syscall(__NR_pivot_root, new_root, put_old);
return (rv < 0)
? alcove_mk_errno(reply, rlen, errno)
: alcove_mk_atom(reply, rlen, "ok");
#else
return alcove_mk_error(reply, rlen, "unsupported");
#endif
}
/*
* getcwd(3)
*