From e6271c99250863f0654172e93f2817304030c3db Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Sun, 3 Jul 2005 17:40:15 +0000 Subject: [PATCH] implemented 'testfile' subcommand git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2125 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/src/chroot-sh.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/util-vserver/src/chroot-sh.c b/util-vserver/src/chroot-sh.c index 8576fb1..fcd2fc1 100644 --- a/util-vserver/src/chroot-sh.c +++ b/util-vserver/src/chroot-sh.c @@ -26,6 +26,7 @@ #include #include #include +#include #define ENSC_WRAPPERS_PREFIX "chroot-sh" #define ENSC_WRAPPERS_UNISTD 1 @@ -72,6 +73,22 @@ redirectFileInternal(int argc, char *argv[], return EXIT_SUCCESS; } +static mode_t +testInternal(int argc, char *argv[], char const *operation) +{ + struct stat st; + + if (argc<2) { + WRITE_MSG(2, "Not enough parameters for '"); + WRITE_STR(2, operation); + WRITE_MSG(2, "' operation; use '--help' for more information\n"); + return wrapper_exit_code; + } + + if (stat(argv[1], &st)==-1) return 0; + else return st.st_mode; +} + static int execCat(int argc, char *argv[]) { @@ -117,6 +134,15 @@ execRm(int argc, char *argv[]) return res; } +static int +execTestFile(int argc, char *argv[]) +{ + int res = testInternal(argc, argv, "testfile"); + + return res!=-1 && S_ISREG(res) ? EXIT_SUCCESS : EXIT_FAILURE; +} + + static struct Command { char const *cmd; int (*handler)(int argc, char *argv[]); @@ -124,6 +150,7 @@ static struct Command { { "cat", execCat }, { "append", execAppend }, { "truncate", execTruncate }, + { "testfile", execTestFile }, { "rm", execRm }, { 0,0 } }; -- 1.8.1.5