projects
/
gapil.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Aggiornamento note copyright
[gapil.git]
/
sources
/
mylschroot.c
diff --git
a/sources/mylschroot.c
b/sources/mylschroot.c
index 9d4d705af845483aa0cfbf06ef4b082c4d367f11..f82e2f99928212e434a089bc5b5631741b342dee 100644
(file)
--- a/
sources/mylschroot.c
+++ b/
sources/mylschroot.c
@@
-18,39
+18,43
@@
*/
/*****************************************************************************
*
*/
/*****************************************************************************
*
- * 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
*
*
* Author: S. Piccardi Mar. 2005
*
- * $Id$
- *
*****************************************************************************/
*****************************************************************************/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h> /* directory */
-#include <stdlib.h> /* C standard library */
-#include <unistd.h>
+/*
+ * Include needed headers
+ */
+#include <sys/types.h> /* primitive system data types */
+#include <sys/stat.h> /* file characteristics constants and functions */
+#include <dirent.h> /* directory operation constants and functions */
+#include <stdlib.h> /* C standard library */
+#include <unistd.h> /* unix standard library */
#include "Gapil.h"
#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 dir_scan */
+/*
+ * Main program
+ */
int main(int argc, char *argv[])
{
int i;
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
*/
opterr = 0; /* don't want writing to stderr */
/*
* Input section: decode command line parameters
* Use getopt function
*/
opterr = 0; /* don't want writing to stderr */
- while ( (i = getopt(argc, argv, "h
s:l:wrbf
")) != -1) {
+ while ( (i = getopt(argc, argv, "h")) != -1) {
switch (i) {
/*
* Handling options
switch (i) {
/*
* Handling options
@@
-78,15
+82,26
@@
int main(int argc, char *argv[])
printf("Wrong number of arguments %d\n", argc - optind);
usage();
}
printf("Wrong number of arguments %d\n", argc - optind);
usage();
}
+
printf("Chrooting to %s\n", argv[1]);
if (chroot(argv[1])) {
perror("Chroot fail");
}
printf("Chrooting to %s\n", argv[1]);
if (chroot(argv[1])) {
perror("Chroot fail");
}
- DirScan("/", do_ls);
+
+ 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);
+ }
+ dir_scan("/", do_ls);
+
exit(0);
}
/*
exit(0);
}
/*
- * Routine to print file name and size inside
DirS
can
+ * Routine to print file name and size inside
dir_s
can
*/
int do_ls(struct dirent * direntry)
{
*/
int do_ls(struct dirent * direntry)
{
@@
-99,7
+114,7
@@
int do_ls(struct dirent * direntry)
* routine to print usage info and exit
*/
void usage(void) {
* routine to print usage info and exit
*/
void usage(void) {
- printf("Program myls
: list file in a directory
\n");
+ printf("Program myls
chroot: chroot in a directory and list files
\n");
printf("Usage:\n");
printf(" myls [-h] dirname \n");
printf(" -h print this help\n");
printf("Usage:\n");
printf(" myls [-h] dirname \n");
printf(" -h print this help\n");