setting up a git repo for this
This commit is contained in:
commit
768c45ea89
2 changed files with 52 additions and 0 deletions
0
foo/bar
Normal file
0
foo/bar
Normal file
52
main.c
Normal file
52
main.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include <stdio.h>
|
||||
#include <linux/sched.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mount.h>
|
||||
#include <dirent.h>
|
||||
#define _GNU_SOURCE
|
||||
#include <sched.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
struct args {
|
||||
int c;
|
||||
char **v;
|
||||
};
|
||||
|
||||
uint8_t CSTACK[8192];
|
||||
|
||||
int myreaddir(void *fooargs) {
|
||||
int len;
|
||||
struct dirent *pDirent;
|
||||
DIR *pDir;
|
||||
struct args *myargs = (struct args *) fooargs;
|
||||
|
||||
if (myargs->c < 2) {
|
||||
printf ("Usage: testprog <dirname>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
mount(NULL, myargs->v[1], NULL, MS_PRIVATE, NULL);
|
||||
mount(NULL, ".", NULL, MS_PRIVATE, NULL);
|
||||
umount(myargs->v[1]);
|
||||
|
||||
pDir = opendir (myargs->v[1]);
|
||||
if (pDir == NULL) {
|
||||
printf ("Cannot open directory '%s'\n", myargs->v[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ((pDirent = readdir(pDir)) != NULL) {
|
||||
printf ("[%s]\n", pDirent->d_name);
|
||||
}
|
||||
closedir (pDir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int c, char *v[]) {
|
||||
struct args fooargs = {c: c, v: v};
|
||||
|
||||
int ret = clone(&myreaddir, CSTACK+8192, CLONE_NEWUTS|CLONE_NEWNS|CLONE_NEWCGROUP|CLONE_NEWIPC|CLONE_NEWNET|CLONE_NEWPID, (void *) &fooargs);
|
||||
|
||||
printf("%05d %05d\n", ret, errno);
|
||||
}
|
Loading…
Add table
Reference in a new issue