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 extern int wrapper_exit_code;
44 if (!condition) return;
47 exit(wrapper_exit_code);
50 inline static WRAPPER_DECL void
53 FatalErrnoError(close(s)==-1, "close()");
56 inline static WRAPPER_DECL void
57 Echdir(char const path[])
59 FatalErrnoError(chdir(path)==-1, "chdir()");
62 inline static WRAPPER_DECL void
65 FatalErrnoError(fchdir(fd)==-1, "fchdir()");
68 inline static WRAPPER_DECL void
69 Echroot(char const path[])
71 FatalErrnoError(chroot(path)==-1, "chroot()");
74 inline static WRAPPER_DECL void
75 Eexecv(char const *path, char *argv[])
77 FatalErrnoError(execv(path,argv)==-1, "execv()");
80 inline static WRAPPER_DECL int
81 Eopen(char const *fname, int flags, mode_t mode)
83 int res = open(fname, flags, mode);
84 FatalErrnoError(res==-1, "open()");
89 inline static WRAPPER_DECL void
90 Eumount2(char const *path, int flag)
92 FatalErrnoError(umount2(path,flag)==-1, "umount2()");
95 inline static WRAPPER_DECL void
96 Emount(const char *source, const char *target,
97 const char *filesystemtype, unsigned long mountflags,
100 FatalErrnoError(mount(source, target, filesystemtype,
101 mountflags, data)==-1, "mount()");
104 inline static WRAPPER_DECL void
105 Emkdir(const char *pathname, mode_t mode)
107 FatalErrnoError(mkdir(pathname,mode)==-1, "mkdir()");
110 inline static WRAPPER_DECL void
111 Epivot_root(const char *new_root, const char *put_old)
113 FatalErrnoError(pivot_root(new_root, put_old)==-1, "pivot_root()");
116 inline static WRAPPER_DECL pid_t
117 Eclone(int (*fn)(void *), void *child_stack, int flags, void *arg)
121 res = clone(fn, child_stack, flags, arg);
123 res = clone((void*(*)(void*))(fn), child_stack, flags, arg);
125 FatalErrnoError(res==-1, "clone()");
130 inline static WRAPPER_DECL pid_t
131 Ewait4(pid_t pid, int *status, int options,
132 struct rusage *rusage)
135 res = wait4(pid, status, options, rusage);
136 FatalErrnoError(res==-1, "wait4()");
140 inline static WRAPPER_DECL void
141 Epipe(int filedes[2])
143 FatalErrnoError(pipe(filedes)==-1, "pipe()");
146 inline static WRAPPER_DECL pid_t
151 FatalErrnoError(res==-1, "fork()");
155 inline static WRAPPER_DECL size_t
156 Eread(int fd, void *ptr, size_t len)
158 size_t res = read(fd, ptr, len);
159 FatalErrnoError((ssize_t)(res)==-1, "read()");
164 inline static WRAPPER_DECL size_t
165 Ewrite(int fd, void const *ptr, size_t len)
167 size_t res = write(fd, ptr, len);
168 FatalErrnoError((ssize_t)(res)==-1, "write()");
173 inline static WRAPPER_DECL void
174 Ereadlink(const char *path, char *buf, size_t bufsiz)
176 FatalErrnoError(readlink(path, buf, bufsiz)==-1, "readlink()");
179 inline static WRAPPER_DECL void
180 Esymlink(const char *oldpath, const char *newpath)
182 FatalErrnoError(symlink(oldpath, newpath)==-1, "symlink()");
185 inline static WRAPPER_DECL void
186 Eunlink(char const *pathname)
188 FatalErrnoError(unlink(pathname)==-1, "unlink()");
191 inline static WRAPPER_DECL void
192 Egetrlimit(int resource, struct rlimit *rlim)
194 FatalErrnoError(getrlimit(resource, rlim)==-1, "getrlimit()");
197 inline static WRAPPER_DECL void
198 Esetrlimit(int resource, struct rlimit const *rlim)
200 FatalErrnoError(setrlimit(resource, rlim)==-1, "setrlimit()");
206 #endif // H_UTIL_VSERVER_SRC_WRAPPERS_H