1 // $Id: mount.c 1679 2004-08-25 00:11:50Z ensc $ --*- c -*--
3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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.
24 #include "configuration.h"
27 #include <pathconfig.h>
29 #include <lib/internal.h>
30 #include <lib_internal/command.h>
38 #define ENSC_WRAPPERS_UNISTD 1
39 #define ENSC_WRAPPERS_FCNTL 1
40 #include <ensc_wrappers/wrappers.h>
43 findMtab(char const *vserver_mtab)
47 if (utilvserver_isFile(vserver_mtab, true)) return vserver_mtab;
49 tmp=CONFDIR "/.defaults/init/mtab";
50 if (utilvserver_isFile(tmp, true)) return tmp;
52 tmp=PKGLIBDEFAULTDIR "/mtab";
53 if (utilvserver_isFile(tmp, true)) return tmp;
59 initMtab(struct Configuration const *cfg)
61 ENSC_PI_DECLARE(mtab_subpath, "apps/init/mtab");
62 PathInfo mtab_path = cfg->cfgdir;
63 char mtab_buf[ENSC_PI_APPSZ(mtab_path, mtab_subpath)];
65 PathInfo_append(&mtab_path, &mtab_subpath, mtab_buf);
66 char const * mtab = findMtab(mtab_path.d);
79 int fd = Eopen("/etc/mtab", O_WRONLY|O_CREAT, 0644);
82 ssize_t len = TEMP_FAILURE_RETRY(read(p[0], buf, sizeof buf));
85 perror("vserver-start: initMtab/read():");
99 int fd = Eopen(mtab, O_RDONLY, 0644);
103 ssize_t len = TEMP_FAILURE_RETRY(read(fd, buf, sizeof buf));
106 perror("vserver-start: initMtab/read():");
110 Ewrite(p[1], buf, len);
119 TEMP_FAILURE_RETRY(wait4(pid, &status, 0,0));
121 if (!WIFEXITED(status) || WEXITSTATUS(status)!=0) {
128 mountVserverInternal(struct Configuration const *cfg,
129 PathInfo const *path, bool use_chbind)
131 if (!utilvserver_isFile(path->d,true)) return;
144 char const * argv[] = {
153 Command_setParams(&cmd, argv);
154 Command_exec(&cmd, false);
158 TEMP_FAILURE_RETRY(wait4(pid, &status, 0,0));
160 if (!WIFEXITED(status) || WEXITSTATUS(status)!=0)
166 mountVserver(struct Configuration const *cfg)
168 ENSC_PI_DECLARE(fstab_subpath, "fstab");
169 ENSC_PI_DECLARE(fstabl_subpath, "fstab.local");
171 PathInfo fstab_path = cfg->cfgdir;
172 char fstab_buf[ENSC_PI_APPSZ(fstab_path, fstab_subpath)];
174 PathInfo fstabl_path = cfg->cfgdir;
175 char fstabl_buf[ENSC_PI_APPSZ(fstabl_path, fstabl_subpath)];
178 PathInfo_append(&fstab_path, &fstab_subpath, fstab_buf);
179 PathInfo_append(&fstabl_path, &fstabl_subpath, fstabl_buf);
182 mountVserverInternal(cfg, &fstab_path, true);
183 mountVserverInternal(cfg, &fstabl_path, false);