vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

wrappers-unistd.hc (5146B)


      1 // $Id$    --*- c -*--
      2 
      3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
      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 #ifndef H_ENSC_IN_WRAPPERS_H
     19 #  error wrappers_handler.hc can not be used in this way
     20 #endif
     21 
     22 // for initgroups()
     23 #include <sys/types.h>
     24 #include <grp.h>
     25 
     26 inline static WRAPPER_DECL void
     27 Eclose(int s)
     28 {
     29   FatalErrnoError(close(s)==-1, "close()");
     30 }
     31 
     32 inline static WRAPPER_DECL void
     33 Echdir(char const path[])
     34 {
     35   FatalErrnoError(chdir(path)==-1, "chdir()");
     36 }
     37 
     38 inline static WRAPPER_DECL void
     39 Efchdir(int fd)
     40 {
     41   FatalErrnoError(fchdir(fd)==-1, "fchdir()");
     42 }
     43 
     44 inline static WRAPPER_DECL void
     45 Echroot(char const path[])
     46 {
     47   FatalErrnoError(chroot(path)==-1, "chroot()");
     48 }
     49 
     50 inline static WRAPPER_DECL NORETURN void
     51 Eexecv(char const *path, char *argv[])
     52 {
     53   execv(path,argv);
     54   FatalErrnoErrorFail("execv()");
     55 }
     56 
     57 inline static WRAPPER_DECL NORETURN void
     58 Eexecvp(char const *path, char *argv[])
     59 {
     60   execvp(path,argv);
     61   FatalErrnoErrorFail("execvp()");
     62 }
     63 
     64 inline static WRAPPER_DECL NORETURN void
     65 EexecvpD(char const *path, char *argv[])
     66 {
     67   execvp(path,argv);
     68   {
     69     ENSC_DETAIL1(msg, "execvp", path, 1);
     70     FatalErrnoErrorFail(msg);
     71   }
     72 }
     73 
     74 inline static WRAPPER_DECL void
     75 Epipe(int filedes[2])
     76 {
     77   FatalErrnoError(pipe(filedes)==-1, "pipe()");
     78 }
     79 
     80 inline static WRAPPER_DECL pid_t
     81 Efork()
     82 {
     83   pid_t		res;
     84   res = fork();
     85   FatalErrnoError(res==-1, "fork()");
     86   return res;
     87 }
     88 
     89 inline static WRAPPER_DECL size_t
     90 Eread(int fd, void *ptr, size_t len)
     91 {
     92   ssize_t	res = read(fd, ptr, len);
     93   FatalErrnoError(res==-1, "read()");
     94 
     95   return res;
     96 }
     97 
     98 inline static WRAPPER_DECL size_t
     99 Ewrite(int fd, void const *ptr, size_t len)
    100 {
    101   ssize_t	res = write(fd, ptr, len);
    102   FatalErrnoError(res==-1, "write()");
    103 
    104   return res;
    105 }
    106 
    107 inline static WRAPPER_DECL size_t
    108 Ereadlink(const char *path, char *buf, size_t bufsiz)
    109 {
    110   ssize_t	res = readlink(path, buf, bufsiz);
    111   FatalErrnoError(res==-1, "readlink()");
    112 
    113   return res;
    114 }
    115 
    116 inline static WRAPPER_DECL size_t
    117 EreadlinkD(const char *path, char *buf, size_t bufsiz)
    118 {
    119   ssize_t	res = readlink(path, buf, bufsiz);
    120   ENSC_DETAIL1(msg, "readlink", path, 1);
    121   FatalErrnoError((ssize_t)(res)==-1, msg);
    122 
    123   return res;
    124 }
    125 
    126 inline static WRAPPER_DECL void
    127 Esymlink(const char *oldpath, const char *newpath)
    128 {
    129   FatalErrnoError(symlink(oldpath, newpath)==-1, "symlink()");
    130 }
    131 
    132 inline static WRAPPER_DECL void
    133 EsymlinkD(const char *oldpath, const char *newpath)
    134 {
    135   ENSC_DETAIL2(msg, "symlink", oldpath, newpath, 1, 1);
    136   FatalErrnoError(symlink(oldpath, newpath)==-1, msg);
    137 }
    138 
    139 inline static WRAPPER_DECL void
    140 Eunlink(char const *pathname)
    141 {
    142   FatalErrnoError(unlink(pathname)==-1, "unlink()");
    143 }
    144 
    145 inline static WRAPPER_DECL void
    146 Elink(char const *oldpath, char const *newpath)
    147 {
    148   FatalErrnoError(link(oldpath, newpath)==-1, "link()");
    149 }
    150 
    151 inline static void
    152 Esetuid(uid_t uid)
    153 {
    154   FatalErrnoError(setuid(uid)==-1, "setuid()");
    155 }
    156 
    157 inline static void
    158 Esetgid(gid_t gid)
    159 {
    160   FatalErrnoError(setgid(gid)==-1, "setgid()");
    161 }
    162 
    163 // #if defined(_GRP_H) && (defined(__USE_BSD) || defined(_DEFAULT_SOURCE) || defined(__dietlibc__))
    164 inline static void
    165 Esetgroups(size_t size, const gid_t *list)
    166 {
    167   FatalErrnoError(setgroups(size, list)==-1, "setgroups()");
    168 }
    169 
    170 inline static void
    171 Einitgroups(const char *user, gid_t group)
    172 {
    173   FatalErrnoError(initgroups(user, group)==-1, "initgroups()");
    174 }
    175 // #endif
    176 
    177 inline static WRAPPER_DECL int
    178 Edup2(int oldfd, int newfd)
    179 {
    180   register int          res = dup2(oldfd, newfd);
    181   FatalErrnoError(res==-1, "dup2()");
    182 
    183   return res;
    184 }
    185 
    186 inline static WRAPPER_DECL int
    187 Edup(int fd)
    188 {
    189   register int          res = dup(fd);
    190   FatalErrnoError(res==-1, "dup()");
    191 
    192   return res;
    193 }
    194 
    195 inline static WRAPPER_DECL pid_t
    196 Esetsid()
    197 {
    198   register pid_t const  res = setsid();
    199   FatalErrnoError(res==-1, "setsid()");
    200 
    201   return res;
    202 }
    203 
    204 inline static WRAPPER_DECL int
    205 Emkstemp(char *template)
    206 {
    207   int		res = mkstemp(template);
    208   FatalErrnoError(res==-1, "mkstemp()");
    209   return res;
    210 }
    211 
    212 inline static WRAPPER_DECL off_t
    213 Elseek(int fildes, off_t offset, int whence)
    214 {
    215   off_t         res = lseek(fildes, offset, whence);
    216   FatalErrnoError(res==(off_t)-1, "lseek()");
    217   return res;
    218 }
    219 
    220 inline static WRAPPER_DECL void
    221 Enice(int n)
    222 {
    223   FatalErrnoError(nice(n)==-1, "nice()");
    224 }
    225 
    226 inline static WRAPPER_DECL void
    227 Etruncate(const char *path, off_t length)
    228 {
    229   FatalErrnoError(truncate(path,length)==-1, "truncate()");
    230 }
    231 
    232 inline static WRAPPER_DECL void
    233 Eftruncate(int fd, off_t length)
    234 {
    235   FatalErrnoError(ftruncate(fd,length)==-1, "ftruncate()");
    236 }