From: Enrico Scholz Date: Fri, 5 Mar 2004 03:12:18 +0000 (+0000) Subject: initial checkin X-Git-Tag: VERSION_0_10~504 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4df0e41e254d190fdbc8290ee38bfd31bd4342e8;p=util-vserver.git initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1067 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/ensc_wrappers/wrappers-socket.hc b/util-vserver/ensc_wrappers/wrappers-socket.hc new file mode 100644 index 0000000..8f3d027 --- /dev/null +++ b/util-vserver/ensc_wrappers/wrappers-socket.hc @@ -0,0 +1,78 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifndef H_ENSC_IN_WRAPPERS_H +# error wrappers-socket.hc can not be used in this way +#endif + +inline static WRAPPER_DECL int +Esocket(int domain, int type, int protocol) +{ + register int res = socket(domain, type, protocol); + FatalErrnoError(res==-1, "socket()"); + return res; +} + +inline static WRAPPER_DECL void +Econnect(int sockfd, void const *serv_addr, socklen_t addrlen) +{ + FatalErrnoError(connect(sockfd, serv_addr, addrlen)==-1, "connect()"); +} + +inline static WRAPPER_DECL void +Ebind(int sockfd, void *my_addr, socklen_t addrlen) +{ + FatalErrnoError(bind(sockfd, my_addr, addrlen)==-1, "bind()"); +} + +inline static WRAPPER_DECL int +Eaccept(int s, void *addr, socklen_t *addrlen) +{ + register int res = accept(s,addr,addrlen); + FatalErrnoError(res==-1, "accept()"); + return res; +} + +inline static WRAPPER_DECL void +Elisten(int sock, int backlog) +{ + FatalErrnoError(listen(sock, backlog)==-1, "bind()"); +} + +inline static WRAPPER_DECL void +Eshutdown(int s, int how) +{ + FatalErrnoError(shutdown(s,how)==-1, "shutdown()"); +} + +inline static WRAPPER_DECL ssize_t +Erecv(int s, void *buf, size_t len, int flags) +{ + register ssize_t res = recv(s,buf,len,flags); + FatalErrnoError(res==-1, "recv()"); + return res; +} + +inline static WRAPPER_DECL int +Eselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout) +{ + register int res = select(n, readfds,writefds,exceptfds, timeout); + FatalErrnoError(res==-1, "select()"); + return res; +} diff --git a/util-vserver/lib/flags-compat.c b/util-vserver/lib/flags-compat.c new file mode 100644 index 0000000..784e950 --- /dev/null +++ b/util-vserver/lib/flags-compat.c @@ -0,0 +1,70 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include +#include + +#define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } + +static struct { + char const * const id; + size_t len; + unsigned char val; +} const FLAGVALUES[] = { + DECL("lock", S_CTX_INFO_LOCK), + DECL("sched", S_CTX_INFO_SCHED), + DECL("nproc", S_CTX_INFO_NPROC), + DECL("private", S_CTX_INFO_PRIVATE), + DECL("fakeinit", S_CTX_INFO_INIT), + DECL("hideinfo", S_CTX_INFO_HIDEINFO), + DECL("ulimit", S_CTX_INFO_ULIMIT), + DECL("namespace", S_CTX_INFO_NAMESPACE), +}; + +uint_least32_t +vc_text2flag_compat(char const *str, size_t len) +{ + size_t i; + if (len==0) len=strlen(str); + + for (i=0; i0; i/=2, --idx) + if (val & i) return FLAGVALUES[idx].id; + + return 0; +} diff --git a/util-vserver/lib/flags-v13.c b/util-vserver/lib/flags-v13.c new file mode 100644 index 0000000..5b02a90 --- /dev/null +++ b/util-vserver/lib/flags-v13.c @@ -0,0 +1,65 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "lib_internal/util-dimof.h" + +#include +#include + +#define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } + +static struct { + char const * const id; + size_t len; + unsigned char val; +} const FLAGVALUES[] = { + DECL("fakeinit", S_CTX_INFO_INIT), +}; + +uint_least64_t +vc_text2flag(char const *str, size_t len) +{ + size_t i; + if (len==0) len=strlen(str); + + for (i=0; i0 && idx>0; i/=2) { + --idx; + if (val & i) return FLAGVALUES[idx].id; + } + + return 0; +} diff --git a/util-vserver/lib/flags_list-compat.c b/util-vserver/lib/flags_list-compat.c new file mode 100644 index 0000000..b881f8c --- /dev/null +++ b/util-vserver/lib/flags_list-compat.c @@ -0,0 +1,58 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz <> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include + +uint_least32_t +vc_list2flag_compat(char const *str, size_t len, + char const **err_ptr, size_t *err_len) +{ + uint32_t res = 0; + + if (len==0) len = strlen(str); + + for (;len>0;) { + char const *ptr = strchr(str, ','); + size_t cnt = ptr ? (size_t)(ptr-str) : len; + unsigned int tmp; + + if (cnt>=len) { cnt=len; len=0; } + else len-=(cnt+1); + + tmp = vc_text2flag_compat(str,cnt); + + if (tmp!=0) res |= tmp; + else { + if (err_ptr) *err_ptr = str; + if (err_len) *err_len = cnt; + return res; + } + + if (ptr==0) break; + str = ptr+1; + } + + if (err_ptr) *err_ptr = 0; + if (err_len) *err_len = 0; + return res; +} diff --git a/util-vserver/lib/flags_list-v13.c b/util-vserver/lib/flags_list-v13.c new file mode 100644 index 0000000..6b8fd35 --- /dev/null +++ b/util-vserver/lib/flags_list-v13.c @@ -0,0 +1,37 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz <> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "internal.h" + +#include + +int +vc_list2flag(char const *str, size_t len, + char const **err_ptr, size_t *err_len, + uint_least64_t *flag, + uint_least64_t *mask) +{ + return utilvserver_listparser_uint64(str, len, err_ptr, err_len, + flag, mask, + vc_text2flag); +} diff --git a/util-vserver/lib/issupportedstring.c b/util-vserver/lib/issupportedstring.c new file mode 100644 index 0000000..46d37c8 --- /dev/null +++ b/util-vserver/lib/issupportedstring.c @@ -0,0 +1,49 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "lib_internal/util-dimof.h" +#include + +#define DECL(F) \ + { vcFEATURE_ ## F, #F } + +static struct { + vcFeatureSet feature; + char const * name; +} FEATURES[] = { + DECL(VKILL), DECL(IATTR), DECL(RLIMIT), DECL(COMPAT), + DECL(MIGRATE), DECL(NAMESPACE), DECL(SCHED), DECL(VINFO), + DECL(VHI) +}; + +bool +vc_isSupportedString(char const *str) +{ + size_t i; + for (i=0; i +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#define LISTPARSER(TYPE,SHORT) \ + int \ + utilvserver_listparser_ ## SHORT(char const *str, size_t len, \ + char const **err_ptr, \ + size_t *err_len, \ + TYPE *flag, \ + TYPE *mask, \ + TYPE (*func)(char const *, size_t)) \ + { \ + if (len==0) len = strlen(str); \ + for (;len>0;) { \ + char const *ptr = strchr(str, ','); \ + size_t cnt = ptr ? (size_t)(ptr-str) : len; \ + TYPE tmp; \ + bool is_neg; \ + \ + is_neg = len>1 && (*str=='!' || *str=='~'); \ + if (is_neg) { \ + ++str; \ + --len; \ + } \ + \ + if (cnt>=len) { cnt=len; len=0; } \ + else len-=(cnt+1); \ + \ + tmp = (*func)(str,cnt); \ + \ + if (tmp!=0) { \ + if (!is_neg) *flag |= tmp; \ + *mask |= tmp; \ + } \ + else { \ + if (err_ptr) *err_ptr = str; \ + if (err_len) *err_len = cnt; \ + return -1; \ + } \ + \ + if (ptr==0) break; \ + str = ptr+1; \ + } \ + \ + if (err_ptr) *err_ptr = 0; \ + if (err_len) *err_len = 0; \ + return 0; \ + } diff --git a/util-vserver/lib/listparser_uint32.c b/util-vserver/lib/listparser_uint32.c new file mode 100644 index 0000000..b128dbd --- /dev/null +++ b/util-vserver/lib/listparser_uint32.c @@ -0,0 +1,26 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "internal.h" +#include "listparser.hc" + +LISTPARSER(uint_least32_t, uint32) diff --git a/util-vserver/lib/listparser_uint64.c b/util-vserver/lib/listparser_uint64.c new file mode 100644 index 0000000..97a8d02 --- /dev/null +++ b/util-vserver/lib/listparser_uint64.c @@ -0,0 +1,26 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "internal.h" +#include "listparser.hc" + +LISTPARSER(uint_least64_t, uint64)