X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fsyscall-legacy.hc;h=26ecd39fd382caa619af2deba348425e74a4e87d;hb=95e2774070e989fe9cf9f48dae5fa054e55e2a3e;hp=4e36a338457fd10e5356ed4b909f7a1dbf04b8c1;hpb=06e1018272502e1d15d6d8f32b80fa96420785b8;p=util-vserver.git diff --git a/lib/syscall-legacy.hc b/lib/syscall-legacy.hc index 4e36a33..26ecd39 100644 --- a/lib/syscall-legacy.hc +++ b/lib/syscall-legacy.hc @@ -1,4 +1,4 @@ -// $Id: syscall-legacy.hc,v 1.1.4.6 2004/02/05 03:52:45 ensc Exp $ --*- c -*-- +// $Id: syscall-legacy.hc 2076 2005-05-02 21:42:05Z ensc $ --*- c -*-- // Copyright (C) 2003 Enrico Scholz // based on syscall.cc by Jacques Gelinas @@ -31,12 +31,13 @@ */ #include "safechroot-internal.hc" -#include #include #include #include -#include #include +#include + +#include "syscall-wrap.h" // Here is the trick. We keep a copy of the define, then undef it // and then later, we try to locate the value reading /proc/self/status @@ -51,6 +52,10 @@ static int __NR_set_ipv4root_rev3; static int rev_ipv4root=0; #ifdef ENSC_SYSCALL_TRADITIONAL +# if defined __dietlibc__ +extern long int syscall (long int __sysno, ...); +# endif + inline static int set_ipv4root_rev0(unsigned long ip) { @@ -75,83 +80,101 @@ set_ipv4root_rev3(unsigned long *ip, int nb, unsigned long bcast, unsigned long return syscall(__NR_set_ipv4root_rev3, ip, nb, bcast, mask); } -#else +#else // ENSC_SYSCALL_TRADITIONAL inline static _syscall1(int, set_ipv4root_rev0, unsigned long, ip) inline static _syscall2(int, set_ipv4root_rev1, unsigned long, ip, unsigned long, bcast) inline static _syscall3(int, set_ipv4root_rev2, unsigned long *, ip, int, nb, unsigned long, bcast) inline static _syscall4(int, set_ipv4root_rev3, unsigned long *, ip, int, nb, unsigned long, bcast, unsigned long *, mask) -#endif +#endif // ENSC_SYSCALL_TRADITIONAL static int def_NR_new_s_context = 273; #undef __NR_new_s_context static int __NR_new_s_context_rev0; - //static int __NR_new_s_context_rev1; static int rev_s_context=0; + #ifdef ENSC_SYSCALL_TRADITIONAL -inline static int +inline static xid_t new_s_context_rev0(int newctx, int remove_cap, int flags) { return syscall(__NR_new_s_context_rev0, newctx, remove_cap, flags); } -#else +#else // ENSC_SYSCALL_TRADITIONAL inline static _syscall3(int, new_s_context_rev0, int, newctx, int, remove_cap, int, flags) - //static _syscall4(int, new_s_context_rev1, int, nbctx, int *, ctxs, int, remove_cap, int, flags) -#endif +#endif // ENSC_SYSCALL_TRADITIONAL + -#if 0 -#undef __NR_set_ctxlimit -static int __NR_set_ctxlimit=-1; -static int rev_set_ctxlimit=-1; +static bool is_init = false; -static _syscall2 (int, set_ctxlimit, int, resource, long, limit) +#include "utils-legacy.h" + +#ifndef WRITE_MSG +# define WRITE_MSG(FD,X) (void)(write(FD,X,sizeof(X)-1)) #endif + +static bool +getNumRevPair(char const *str, int *num, int *rev) +{ + char const * blank_pos = strchr(str, ' '); + char const * eol_pos = strchr(str, '\n'); + + *num = atoi(str); + if (*num==0) return false; + + if (blank_pos!=0 && eol_pos!=0 && blank_pos=2){ - if (strcmp(title,"__NR_set_ipv4root:")==0){ - __NR_set_ipv4root_rev0 = num; - __NR_set_ipv4root_rev1 = num; - __NR_set_ipv4root_rev2 = num; - __NR_set_ipv4root_rev3 = num; - if (strncmp(rev,"rev",3)==0){ - rev_ipv4root = atoi(rev+3); - } -#if 0 - }else if (strcmp(title,"__NR_set_ctxlimit:")==0){ - __NR_set_ctxlimit = num; - if (strncmp(rev,"rev",3)==0){ - rev_set_ctxlimit = atoi(rev+3); - } -#endif - }else if (strcmp(title,"__NR_new_s_context:")==0){ - __NR_new_s_context_rev0 = num; - //__NR_new_s_context_rev1 = num; - if (strncmp(rev,"rev",3)==0){ - rev_s_context = atoi(rev+3); - } - } - } - } - fclose (fin); - } - is_init = 1; + + while (!init_internal() && errno==EAGAIN) {} + + is_init = true; } } @@ -160,16 +183,31 @@ void vc_init_legacy() init(); } -static ALWAYSINLINE int +void vc_init_internal_legacy(int ctx_rev, int ctx_number, + int ipv4_rev, int ipv4_number) +{ + rev_s_context = ctx_rev; + __NR_new_s_context_rev0 = ctx_number; + + rev_ipv4root = ipv4_rev; + __NR_set_ipv4root_rev0 = ipv4_number; + __NR_set_ipv4root_rev1 = ipv4_number; + __NR_set_ipv4root_rev2 = ipv4_number; + __NR_set_ipv4root_rev3 = ipv4_number; + + is_init = true; +} + +static ALWAYSINLINE xid_t vc_new_s_context_legacy(int ctx, int remove_cap, int flags) { - int ret = -1; + xid_t ret = -1; init(); if (rev_s_context == 0){ return new_s_context_rev0(ctx, remove_cap, flags); }else{ errno = -ENOSYS; - ret = -1; + ret = VC_NOCTX; } return ret; } @@ -184,12 +222,12 @@ vc_set_ipv4root_legacy_internal ( init(); if (rev_ipv4root == 0){ if (nb > 1){ - fprintf (stderr,"set_ipv4root: Several IP number specified, but this kernel only supports one. Ignored\n"); + WRITE_MSG(2,"set_ipv4root: Several IP number specified, but this kernel only supports one. Ignored\n"); } return set_ipv4root_rev0 (ip[0]); }else if (rev_ipv4root == 1){ if (nb > 1){ - fprintf (stderr,"set_ipv4root: Several IP number specified, but this kernel only supports one. Ignored\n"); + WRITE_MSG(2,"set_ipv4root: Several IP number specified, but this kernel only supports one. Ignored\n"); } return set_ipv4root_rev1 (ip[0],bcast); }else if (rev_ipv4root == 2){ @@ -206,7 +244,7 @@ vc_set_ipv4root_legacy(uint32_t bcast, size_t nb, struct vc_ip_mask_pair const { unsigned long ip[nb]; unsigned long mask[nb]; - size_t i; + size_t i; for (i=0; i