X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Fsyscall-legacy.hc;h=7ba077db39156f3c7b9b0e1d1a4e1c8c0b9ea580;hb=51890064608d408c64f736ab0cec78c37de19b87;hp=79dc78c1c060add42f1b2d57422d554f366e0035;hpb=9cde6b2e1f86d390b0730cb5339eb4920d631886;p=util-vserver.git diff --git a/util-vserver/lib/syscall-legacy.hc b/util-vserver/lib/syscall-legacy.hc index 79dc78c..7ba077d 100644 --- a/util-vserver/lib/syscall-legacy.hc +++ b/util-vserver/lib/syscall-legacy.hc @@ -31,12 +31,12 @@ */ #include "safechroot-internal.hc" -#include #include #include #include #include #include +#include // 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 @@ -50,11 +50,41 @@ static int __NR_set_ipv4root_rev2; static int __NR_set_ipv4root_rev3; static int rev_ipv4root=0; +#if (defined(__pic__) && defined(__i386)) || defined(__hppa__) +#if defined __dietlibc__ +extern long int syscall (long int __sysno, ...); +#endif + +inline static int +set_ipv4root_rev0(unsigned long ip) +{ + return syscall(__NR_set_ipv4root_rev0, ip); +} + +inline static int +set_ipv4root_rev1(unsigned long ip, unsigned long bcast) +{ + return syscall(__NR_set_ipv4root_rev1, ip, bcast); +} + +inline static int +set_ipv4root_rev2(unsigned long *ip, int nb, unsigned long bcast) +{ + return syscall(__NR_set_ipv4root_rev2, ip, nb, bcast); +} -static _syscall1(int, set_ipv4root_rev0, unsigned long, ip) -static _syscall2(int, set_ipv4root_rev1, unsigned long, ip, unsigned long, bcast) -static _syscall3(int, set_ipv4root_rev2, unsigned long *, ip, int, nb, unsigned long, bcast) -static _syscall4(int, set_ipv4root_rev3, unsigned long *, ip, int, nb, unsigned long, bcast, unsigned long *, mask) +inline static int +set_ipv4root_rev3(unsigned long *ip, int nb, unsigned long bcast, unsigned long * mask) +{ + return syscall(__NR_set_ipv4root_rev3, ip, nb, bcast, mask); +} + +#else +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 static int def_NR_new_s_context = 273; #undef __NR_new_s_context @@ -62,8 +92,16 @@ static int __NR_new_s_context_rev0; //static int __NR_new_s_context_rev1; static int rev_s_context=0; -static _syscall3(int, new_s_context_rev0, int, newctx, int, remove_cap, int, flags) +#if defined(__pic__) && defined(__i386) +inline static int +new_s_context_rev0(int newctx, int remove_cap, int flags) +{ + return syscall(__NR_new_s_context_rev0, newctx, remove_cap, flags); +} +#else +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 #if 0 #undef __NR_set_ctxlimit @@ -73,62 +111,77 @@ static int rev_set_ctxlimit=-1; static _syscall2 (int, set_ctxlimit, int, resource, long, limit) #endif -#undef __NR_chrootsafe -static int __NR_chrootsafe=-1; -static int rev_chrootsafe=-1; +static bool is_init = false; + +#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_chrootsafe:")==0){ - __NR_chrootsafe = num; - if (strncmp(rev,"rev",3)==0){ - rev_chrootsafe = atoi(rev+3); - } - }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; } } @@ -137,6 +190,21 @@ void vc_init_legacy() init(); } +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 int vc_new_s_context_legacy(int ctx, int remove_cap, int flags) { @@ -161,12 +229,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){ @@ -192,48 +260,3 @@ vc_set_ipv4root_legacy(uint32_t bcast, size_t nb, struct vc_ip_mask_pair const return vc_set_ipv4root_legacy_internal(ip, nb, bcast, mask); } - -static ALWAYSINLINE int -vc_chrootsafe_legacy (const char *dir) -{ - init(); - if (rev_chrootsafe == -1){ - vc_tell_unsafe_chroot(); - return chroot(dir); - }else if (rev_chrootsafe == 0){ - return chrootsafe (dir); - }else{ - fprintf (stderr,"chrootsafe: kernel support version %d, application expects version 0\n" - ,rev_chrootsafe); - } - errno = EINVAL; - return -1; -} - -#if 0 -/* - Return != 0 if chrootsafe is available -*/ -int has_chrootsafe() -{ - init(); - return rev_chrootsafe != -1; -} - -int call_set_ctxlimit (int res, long limit) -{ - init(); - if (rev_set_ctxlimit == -1){ - fprintf (stderr,"set_ctxlimit: Unsupported system call, update kernel\n"); - }else if (rev_set_ctxlimit == 0){ - return set_ctxlimit (res,limit); - }else{ - fprintf (stderr,"set_ctxlimit: kernel support version %d, application expects version 0\n" - ,rev_set_ctxlimit); - } - errno = EINVAL; - return -1; -} - - -#endif