3 // Copyright (C) 2003 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.
19 #ifndef H_UTIL_VSERVER_SRC_WRAPPERS_H
20 #define H_UTIL_VSERVER_SRC_WRAPPERS_H
23 #include "compat-pivot_root.h"
32 #include <sys/types.h>
35 #include <sys/mount.h>
37 #define WRAPPER_DECL UNUSED ALWAYSINLINE
40 FatalErrnoError(bool condition, char const msg[]) /*@*/
42 if (!condition) return;
45 extern int wrapper_exit_code;
46 exit(wrapper_exit_code);
49 inline static WRAPPER_DECL void
52 FatalErrnoError(close(s)==-1, "close()");
55 inline static WRAPPER_DECL void
56 Echdir(char const path[])
58 FatalErrnoError(chdir(path)==-1, "chdir()");
61 inline static WRAPPER_DECL void
64 FatalErrnoError(fchdir(fd)==-1, "fchdir()");
67 inline static WRAPPER_DECL void
68 Echroot(char const path[])
70 FatalErrnoError(chroot(path)==-1, "chroot()");
73 inline static WRAPPER_DECL void
74 Eexecv(char const *path, char *argv[])
76 FatalErrnoError(execv(path,argv)==-1, "execv()");
79 inline static WRAPPER_DECL int
80 Eopen(char const *fname, int flags, mode_t mode)
82 int res = open(fname, flags, mode);
83 FatalErrnoError(res==-1, "open()");
88 inline static WRAPPER_DECL void
89 Eumount2(char const *path, int flag)
91 FatalErrnoError(umount2(path,flag)==-1, "umount2()");
94 inline static WRAPPER_DECL void
95 Emount(const char *source, const char *target,
96 const char *filesystemtype, unsigned long mountflags,
99 FatalErrnoError(mount(source, target, filesystemtype,
100 mountflags, data)==-1, "mount()");
103 inline static WRAPPER_DECL void
104 Emkdir(const char *pathname, mode_t mode)
106 FatalErrnoError(mkdir(pathname,mode)==-1, "mkdir()");
109 inline static WRAPPER_DECL void
110 Epivot_root(const char *new_root, const char *put_old)
112 FatalErrnoError(pivot_root(new_root, put_old)==-1, "pivot_root()");
115 inline static WRAPPER_DECL pid_t
116 Eclone(int (*fn)(void *), void *child_stack, int flags, void *arg)
120 res = clone(fn, child_stack, flags, arg);
122 res = clone((void*(*)(void*))(fn), child_stack, flags, arg);
124 FatalErrnoError(res==-1, "clone()");
129 inline static WRAPPER_DECL pid_t
130 Ewait4(pid_t pid, int *status, int options,
131 struct rusage *rusage)
134 res = wait4(pid, status, options, rusage);
135 FatalErrnoError(res==-1, "wait4()");
139 inline static WRAPPER_DECL void
140 Epipe(int filedes[2])
142 FatalErrnoError(pipe(filedes)==-1, "pipe()");
145 inline static WRAPPER_DECL pid_t
150 FatalErrnoError(res==-1, "fork()");
154 inline static WRAPPER_DECL size_t
155 Eread(int fd, void *ptr, size_t len)
157 size_t res = read(fd, ptr, len);
158 FatalErrnoError((ssize_t)(res)==-1, "read()");
163 inline static WRAPPER_DECL size_t
164 Ewrite(int fd, void const *ptr, size_t len)
166 size_t res = write(fd, ptr, len);
167 FatalErrnoError((ssize_t)(res)==-1, "write()");
172 inline static WRAPPER_DECL void
173 Ereadlink(const char *path, char *buf, size_t bufsiz)
175 FatalErrnoError(readlink(path, buf, bufsiz)==-1, "readlink()");
178 inline static WRAPPER_DECL void
179 Esymlink(const char *oldpath, const char *newpath)
181 FatalErrnoError(symlink(oldpath, newpath)==-1, "symlink()");
184 inline static WRAPPER_DECL void
185 Eunlink(char const *pathname)
187 FatalErrnoError(unlink(pathname)==-1, "unlink()");
192 #endif // H_UTIL_VSERVER_SRC_WRAPPERS_H