X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;f=sources%2Fmylschroot.c;h=56b3d63c9d2228ce0fb9e8d11a3cb6a069711fb4;hb=d451ac30382ae398b9a2242a4f82b3438affc8a7;hp=9d4d705af845483aa0cfbf06ef4b082c4d367f11;hpb=da88189d1ab4d9220496cadb1274a70f6fb96fa0;p=gapil.git diff --git a/sources/mylschroot.c b/sources/mylschroot.c index 9d4d705..56b3d63 100644 --- a/sources/mylschroot.c +++ b/sources/mylschroot.c @@ -18,33 +18,37 @@ */ /***************************************************************************** * - * File myls.c: An example ls done after a chroot + * File mylschroot.c: An example ls done after a chroot + * List files and their size inside a given directory inside a chroot * * Author: S. Piccardi Mar. 2005 * - * $Id$ - * *****************************************************************************/ -#include -#include -#include /* directory */ -#include /* C standard library */ -#include +/* + * Include needed headers + */ +#include /* primitive system data types */ +#include /* file characteristics constants and functions */ +#include /* directory operation constants and functions */ +#include /* C standard library */ +#include /* unix standard library */ #include "Gapil.h" -/* - * Program myls - * - * List files and their size inside a given directory + +/* + * Function and globals definitions */ -/* Help printing routine */ -void usage(void); -/* computation function for DirScan */ -int do_ls(struct dirent * direntry); +void usage(void); /* Help printing routine */ +int do_ls(struct dirent * direntry); /* computation function for DirScan */ +/* + * Main program + */ 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 @@ -78,11 +82,22 @@ int main(int argc, char *argv[]) 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); } /* @@ -99,7 +114,7 @@ int do_ls(struct dirent * direntry) * 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");