int main(int argc, char *argv[])
{
int i;
+ char * arg[]={"ls","-l", NULL};
+ struct stat data;
/*
* Input section: decode command line parameters
* Use getopt function
printf("Wrong number of arguments %d\n", argc - optind);
usage();
}
+
printf("Chrooting to %s\n", argv[1]);
if (chroot(argv[1])) {
perror("Chroot fail");
}
+
+ if (execve("/ls", arg, NULL)) {
+ perror("errore in execve");
+ }
+ if (stat("/ls", &data)) {
+ perror("errore in stat");
+ } else {
+ printf("inode: %d\n", data.st_ino);
+ }
DirScan("/", do_ls);
+
exit(0);
}
/*
* routine to print usage info and exit
*/
void usage(void) {
- printf("Program myls: list file in a directory \n");
+ printf("Program mylschroot: chroot in a directory and list files \n");
printf("Usage:\n");
printf(" myls [-h] dirname \n");
printf(" -h print this help\n");