--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// 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;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <ensc@delenn.intern.sigma-chemnitz.de>
+//
+// 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 <config.h>
+#endif
+
+#include "vserver.h"
+#include <string.h>
+#include <assert.h>
+
+#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; i<sizeof(FLAGVALUES)/sizeof(FLAGVALUES[0]); ++i)
+ if (len==FLAGVALUES[i].len &&
+ strncmp(FLAGVALUES[i].id, str, len)==0)
+ return FLAGVALUES[i].val;
+
+ return 0;
+}
+
+char const *
+vc_hiflag2text_compat(uint_least32_t val)
+{
+ size_t i;
+ size_t idx;
+
+ assert(S_CTX_INFO_ULIMIT==64);
+
+ for (i=S_CTX_INFO_ULIMIT, idx=6; i>0; i/=2, --idx)
+ if (val & i) return FLAGVALUES[idx].id;
+
+ return 0;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <ensc@delenn.intern.sigma-chemnitz.de>
+//
+// 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 <config.h>
+#endif
+
+#include "vserver.h"
+#include "lib_internal/util-dimof.h"
+
+#include <string.h>
+#include <assert.h>
+
+#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; i<sizeof(FLAGVALUES)/sizeof(FLAGVALUES[0]); ++i)
+ if (len==FLAGVALUES[i].len &&
+ strncmp(FLAGVALUES[i].id, str, len)==0)
+ return FLAGVALUES[i].val;
+
+ return 0;
+}
+
+char const *
+vc_hiflag2text(uint_least64_t val)
+{
+ size_t i;
+ size_t idx;
+
+ for (i=S_CTX_INFO_INIT, idx=DIM_OF(FLAGVALUES); i>0 && idx>0; i/=2) {
+ --idx;
+ if (val & i) return FLAGVALUES[idx].id;
+ }
+
+ return 0;
+}
--- /dev/null
+// $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 <config.h>
+#endif
+
+#include "vserver.h"
+#include <string.h>
+
+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;
+}
--- /dev/null
+// $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 <config.h>
+#endif
+
+#include "vserver.h"
+#include "internal.h"
+
+#include <string.h>
+
+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);
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// 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 <config.h>
+#endif
+
+#include "vserver.h"
+#include "lib_internal/util-dimof.h"
+#include <strings.h>
+
+#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<DIM_OF(FEATURES); ++i) {
+ if (strcasecmp(FEATURES[i].name, str)==0)
+ return vc_isSupported(FEATURES[i].feature);
+ }
+
+ return false;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// 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 <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#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; \
+ }
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// 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 <config.h>
+#endif
+
+#include "internal.h"
+#include "listparser.hc"
+
+LISTPARSER(uint_least32_t, uint32)
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// 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 <config.h>
+#endif
+
+#include "internal.h"
+#include "listparser.hc"
+
+LISTPARSER(uint_least64_t, uint64)