3 // Copyright (C) 2008 Daniel Hokka Zakrisson
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.
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.
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.
31 #include <sys/mount.h>
34 #define ENSC_WRAPPERS_PREFIX "exec-remount: "
35 #define ENSC_WRAPPERS_MOUNT 1
36 #define ENSC_WRAPPERS_UNISTD 1
39 #define CMD_HELP 0x1000
40 #define CMD_VERSION 0x1001
41 #define CMD_MTAB 0x2001
44 #define MNT_DETACH 0x0002
47 static struct option const
49 { "help", no_argument, 0, CMD_HELP },
50 { "version", no_argument, 0, CMD_VERSION },
51 { "mtab", required_argument, 0, CMD_MTAB },
55 int wrapper_exit_code = 255;
58 showHelp(int fd, char const *cmd, int res)
60 WRITE_MSG(fd, "Usage:\n ");
62 WRITE_MSG(fd, " [--mtab <file>] <mount points>* -- <command> <args>*\n");
64 "Please report bugs to " PACKAGE_BUGREPORT "\n");
72 "exec-remount " VERSION " -- remounts specified mount points and executes a program\n"
73 "This program is part of " PACKAGE_STRING "\n\n"
74 "Copyright (c) 2008 Daniel Hokka Zakrisson\n"
75 VERSION_COPYRIGHT_DISCLAIMER);
80 do_remount(char const *mount)
82 /* FIXME: Read this from mtab */
83 if (strcmp(mount, "/proc") == 0)
84 Emount("proc", "proc", "proc", 0, NULL);
85 else if (strcmp(mount, "/sys") == 0)
86 Emount("sysfs", "sys", "sysfs", 0, NULL);
88 WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "unknown mount point: ");
94 int main(int argc, char *argv[])
97 char const *mtab = "/etc/mtab";
100 int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
104 case CMD_HELP : showHelp(1, argv[0], 0);
105 case CMD_VERSION : showVersion();
106 case CMD_MTAB : mtab = optarg; break;
107 default : showHelp(2, argv[0], 1);
111 for (i = optind; argv[i] != NULL && strcmp(argv[i], "--") != 0; i++) {
112 if (vc_isSupported(vcFEATURE_PIDSPACE)) {
113 /* + 1 to strip the leading / */
114 if (umount2(argv[i] + 1, MNT_DETACH) == 0)
120 showHelp(2, argv[0], 1);
123 EexecvpD(argv[i], argv+i);