dc34836dcd8567bfb4be52d8e32668b606c585d0
[util-vserver.git] / util-vserver / src / chroot-rm.c
1 // $Id$    --*- c++ -*--
2
3 // Copyright (C) 2003 Enrico Scholz <>
4 //  
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
8 //  
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //  
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "util.h"
24
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <stdio.h>
28
29 #define ENSC_WRAPPERS_UNISTD 1
30 #include <wrappers.h>
31
32 int     wrapper_exit_code = 1;
33
34 static void
35 showHelp(int fd, char const *cmd, int res)
36 {
37   WRITE_MSG(fd, "Usage:  ");
38   WRITE_STR(fd, cmd);
39   WRITE_MSG(fd,
40             " <files>+\n\n"
41             "This program removes <files> by assuming the current directory\n"
42             "as a chroot directory.\n\n"
43             "Please report bugs to " PACKAGE_BUGREPORT "\n");
44   exit(res);
45 }
46
47 static void
48 showVersion()
49 {
50   WRITE_MSG(1,
51             "chroot-rm " VERSION " -- removes files under current directory\n"
52             "This program is part of " PACKAGE_STRING "\n\n"
53             "Copyright (C) 2003 Enrico Scholz\n"
54             VERSION_COPYRIGHT_DISCLAIMER);
55   exit(0);
56 }
57
58 int main(int argc, char *argv[])
59 {
60   int           i;
61   int           res = EXIT_SUCCESS;
62   int           idx = 1;
63
64   if (argc==1) {
65     WRITE_MSG(2, "No files given; use '--help' for more information\n");
66     return EXIT_FAILURE;
67   }
68   if (strcmp(argv[1], "--help")   ==0) showHelp(1, argv[0], 0);
69   if (strcmp(argv[1], "--version")==0) showVersion();
70   if (strcmp(argv[1], "--")==0)        ++idx;
71
72   Echroot(".");
73   Echdir("/");
74   
75   for (i=idx; i<argc; ++i) {
76     if (unlink(argv[i])==-1) {
77       WRITE_STR(2, argv[i]);
78       perror("");
79       res = EXIT_FAILURE;
80     }
81   }
82
83   return res;
84 }