Index: Makefile.am =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/Makefile.am,v retrieving revision 1.1.4.10 retrieving revision 1.1.4.11 diff -u -p -u -I$Id: -r1.1.4.10 -r1.1.4.11 --- Makefile.am 20 Nov 2003 00:46:18 -0000 1.1.4.10 +++ Makefile.am 3 Dec 2003 00:08:54 -0000 1.1.4.11 @@ -24,6 +24,7 @@ CVS2CL_ALLFLAGS := $(CVS2CL_AMFL sysvdir = $(sysconfdir)/init.d vservercfgdir = $(sysconfdir)/vservers +legacydir = $(pkglibdir)/legacy include_HEADERS = $(lib_HDRS) noinst_HEADERS = $(src_HDRS) $(lib_XHDRS) compat.h @@ -33,6 +34,8 @@ lib_LIBRARIES = $(lib_lib_LIBS) pkglib_SCRIPTS = $(distrib_SCRPTS) $(scripts_SCRPTS) $(src_pkglib_SCRPTS) pkglib_DATA = $(distrib_DAT) $(scriptscfg_DATA) pkglib_PROGRAMS = $(src_pkglib_PRGS) + +legacy_SCRIPTS = $(scripts_LEGSCRPTS) sbin_SCRIPTS = $(scripts_PRGS) $(linuxconf_SCRPTS) sbin_PROGRAMS = $(src_sbin_PRGS) Index: NEWS =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/NEWS,v retrieving revision 1.1.2.1.2.6 retrieving revision 1.1.2.1.2.7 diff -u -p -u -I$Id: -r1.1.2.1.2.6 -r1.1.2.1.2.7 --- NEWS 22 Nov 2003 02:14:04 -0000 1.1.2.1.2.6 +++ NEWS 30 Dec 2003 14:22:13 -0000 1.1.2.1.2.7 @@ -1,3 +1,39 @@ +Version 0.27 +============ + + - added new 'vkill' implementation which uses the syscall from + vserver 1.1.6+. + + - BUGFIX: fixed typo in vc_get_version() wrapper which caused an + infinite recursive call of this function; this should not have + affected any userspace program + + - BUGFIX: 'vps' accepts multiple arguments now (from Debian patch) + + - vc_ctx_kill() was added + + - chrootsafe() code was removed since such a functionality seems + to be impossible + + - use 'vserver' instead of 'virtual_context' as the syscall name; + this will fix problems with architectures where the syscall is not + at #273. + + - BUGFIX: fixed '--enable-apis' ./configure option; formerly, only + 'ALL' or none were possible + + - moved some old, unused programs/scripts into a seperate 'legacy'/ + directory + + - BUGFIX: /dev/pts will be mounted with correct options now + + - added support for Slackware's init-method (thanks to Stephen + Pearce for the patch) + + - API-CHANGE: followed kernel patches and renamed 'ctx_t' datatype + to 'xid_t'. + + Version 0.26 ============ @@ -13,6 +49,7 @@ Version 0.26 kernel version. The old Behavior can be restored with the '--disable-internal-headers' ./configure option + Version 0.25 ============ Index: compat.h =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/compat.h,v retrieving revision 1.1.4.2 retrieving revision 1.1.4.3 diff -u -p -u -I$Id: -r1.1.4.2 -r1.1.4.3 --- compat.h 17 Nov 2003 23:13:47 -0000 1.1.4.2 +++ compat.h 30 Dec 2003 13:47:56 -0000 1.1.4.3 @@ -38,9 +38,9 @@ # define MS_MOVE 8192 #endif -#ifndef HAVE_CTX_T +#ifndef HAVE_XID_T #include -typedef uint32_t ctx_t; +typedef uint32_t xid_t; #endif #endif // H_UTIL_VSERVER_COMPAT_H Index: configure.ac =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/configure.ac,v retrieving revision 1.1.2.1.2.19 retrieving revision 1.1.2.1.2.24 diff -u -p -u -I$Id: -r1.1.2.1.2.19 -r1.1.2.1.2.24 --- configure.ac 22 Nov 2003 02:14:04 -0000 1.1.2.1.2.19 +++ configure.ac 30 Dec 2003 19:38:29 -0000 1.1.2.1.2.24 @@ -25,7 +25,7 @@ dnl AC_PREREQ(2.57) -AC_INIT(util-vserver, 0.26, enrico.scholz@informatik.tu-chemnitz.de) +AC_INIT(util-vserver, 0.27, enrico.scholz@informatik.tu-chemnitz.de) AC_CONFIG_SRCDIR([src/capchroot.c]) AC_CONFIG_HEADER([config.h]) @@ -85,12 +85,12 @@ AC_ARG_ENABLE([apis], [AC_HELP_STRING([--enable-apis=APIS], [enable support for the given apis; possible values are: legacy,compat,v11,ALL (default: ALL)])], [], - [supported_apis=ALL]) + [enable_apis=ALL]) -test x"$supported_apis" != xALL || supported_apis='legacy,compat,v11' +test x"$enable_apis" != xALL || enable_apis='legacy,compat,v11' old_IFS=$IFS IFS=,; -for i in $supported_apis; do +for i in $enable_apis; do case "$i" in compat) AC_DEFINE(VC_ENABLE_API_COMPAT, 1, [Enable support for compatibily syscall API]);; legacy) AC_DEFINE(VC_ENABLE_API_LEGACY, 1, [Enable support for old, /proc parsing API]);; @@ -99,15 +99,17 @@ for i in $supported_apis; do esac done IFS=$old_IFS -AC_MSG_RESULT([$supported_apis]) +AC_MSG_RESULT([$enable_apis]) +AC_LANG_PUSH(C++) AC_CHECK_HEADERS([ext2fs/ext2fs.h], [], [AC_CHECK_HEADERS([linux/ext2_fs.h], [], [AC_MSG_ERROR([Sorry, do not know, how to include 'ext2fs.h'])])]) +AC_LANG_POP -AC_CHECK_FUNCS([sys_virtual_context]) +AC_CHECK_FUNCS([vserver]) AC_CHECK_DECLS(MS_MOVE,,,[#include ]) -AC_CHECK_TYPES(ctx_t,,,[#include ]) +AC_CHECK_TYPES(xid_t,,,[#include ]) AC_CONFIG_FILES([util-vserver.spec Makefile]) AC_OUTPUT Index: lib/Makefile-files =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/Makefile-files,v retrieving revision 1.1.4.4 retrieving revision 1.1.4.5 diff -u -p -u -I$Id: -r1.1.4.4 -r1.1.4.5 --- lib/Makefile-files 7 Nov 2003 23:04:28 -0000 1.1.4.4 +++ lib/Makefile-files 28 Nov 2003 23:25:49 -0000 1.1.4.5 @@ -19,6 +19,7 @@ lib_SRCS = lib/syscall.c \ lib/syscall_rlimit.c \ + lib/syscall_kill.c \ lib/checkversion.c \ lib/getctx.c \ lib/getversion.c \ @@ -29,6 +30,7 @@ lib_HDRS = lib/vserver.h lib_XHDRS = lib/syscall-compat.hc \ lib/syscall-legacy.hc \ lib/syscall_rlimit-v11.hc \ + lib/syscall_kill-v11.hc \ lib/getctx-compat.hc \ lib/getctx-legacy.hc \ lib/getversion-internal.hc \ Index: lib/getctx-compat.hc =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/getctx-compat.hc,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -p -u -I$Id: -r1.1.2.1 -r1.1.2.2 --- lib/getctx-compat.hc 14 Oct 2003 15:19:14 -0000 1.1.2.1 +++ lib/getctx-compat.hc 30 Dec 2003 13:45:57 -0000 1.1.2.2 @@ -21,7 +21,7 @@ #include "getctx-legacy.hc" -static inline ALWAYSINLINE ctx_t +static inline ALWAYSINLINE xid_t vc_X_getctx_compat(pid_t pid) { return vc_X_getctx_legacy(pid); Index: lib/getctx-legacy.hc =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/getctx-legacy.hc,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -p -u -I$Id: -r1.1.2.2 -r1.1.2.3 --- lib/getctx-legacy.hc 18 Oct 2003 01:48:29 -0000 1.1.2.2 +++ lib/getctx-legacy.hc 30 Dec 2003 13:45:57 -0000 1.1.2.3 @@ -33,7 +33,7 @@ #define CTX_TAG "\ns_context: " -static ctx_t +static xid_t vc_X_getctx_legacy(pid_t pid) { static volatile size_t bufsize=4097; Index: lib/getctx.c =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/getctx.c,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -p -u -I$Id: -r1.2.2.1 -r1.2.2.2 --- lib/getctx.c 14 Oct 2003 15:19:14 -0000 1.2.2.1 +++ lib/getctx.c 30 Dec 2003 13:45:57 -0000 1.2.2.2 @@ -33,7 +33,7 @@ #include -ctx_t +xid_t vc_X_getctx(pid_t pid) { CALL_VC(CALL_VC_COMPAT(vc_X_getctx, pid), Index: lib/getversion-internal.hc =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/getversion-internal.hc,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.3 diff -u -p -u -I$Id: -r1.1.2.1 -r1.1.2.3 --- lib/getversion-internal.hc 14 Oct 2003 15:19:14 -0000 1.1.2.1 +++ lib/getversion-internal.hc 26 Dec 2003 00:16:48 -0000 1.1.2.3 @@ -30,7 +30,7 @@ static inline ALWAYSINLINE int vc_get_version_internal(int cat) { - return sys_virtual_context(VC_CMD(VERSION, 0, 0), cat, 0); + return vserver(VC_CMD(VERSION, 0, 0), cat, 0); } #endif // H_UTIL_VSERVER_LIB_GETVERSION_INTERNAL_H Index: lib/getversion.c =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/getversion.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -p -u -I$Id: -r1.1.2.1 -r1.1.2.2 --- lib/getversion.c 14 Oct 2003 15:19:14 -0000 1.1.2.1 +++ lib/getversion.c 3 Dec 2003 00:08:21 -0000 1.1.2.2 @@ -26,5 +26,5 @@ int vc_get_version(int cat) { - return vc_get_version(cat); + return vc_get_version_internal(cat); } Index: lib/syscall-compat.hc =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/syscall-compat.hc,v retrieving revision 1.1.4.4 retrieving revision 1.1.4.7 diff -u -p -u -I$Id: -r1.1.4.4 -r1.1.4.7 --- lib/syscall-compat.hc 17 Nov 2003 23:11:12 -0000 1.1.4.4 +++ lib/syscall-compat.hc 30 Dec 2003 13:45:57 -0000 1.1.4.7 @@ -29,13 +29,13 @@ #include static inline ALWAYSINLINE int -vc_new_s_context_compat(ctx_t ctx, unsigned int remove_cap, unsigned int flags) +vc_new_s_context_compat(xid_t ctx, unsigned int remove_cap, unsigned int flags) { struct vcmd_new_s_context_v1 msg; msg.remove_cap = remove_cap; msg.flags = flags; - return sys_virtual_context(VC_CMD(COMPAT, 1, 1), CTX_USER2KERNEL(ctx), &msg); + return vserver(VC_CMD(COMPAT, 1, 1), CTX_USER2KERNEL(ctx), &msg); } static inline ALWAYSINLINE int @@ -56,7 +56,7 @@ vc_set_ipv4root_compat(uint32_t bcast, msg.ip_mask_pair[i].mask = ips[i].mask; } - return sys_virtual_context(VC_CMD(COMPAT, 2, 3), nb, &msg); + return vserver(VC_CMD(COMPAT, 2, 3), nb, &msg); } static inline ALWAYSINLINE int Index: lib/syscall-legacy.hc =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/syscall-legacy.hc,v retrieving revision 1.1.4.3 retrieving revision 1.1.4.5 diff -u -p -u -I$Id: -r1.1.4.3 -r1.1.4.5 --- lib/syscall-legacy.hc 14 Oct 2003 15:20:01 -0000 1.1.4.3 +++ lib/syscall-legacy.hc 23 Dec 2003 16:52:12 -0000 1.1.4.5 @@ -50,11 +50,37 @@ static int __NR_set_ipv4root_rev2; static int __NR_set_ipv4root_rev3; static int rev_ipv4root=0; +#if (defined(__pic__) && defined(__i386)) || defined(__hppa__) +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); +} + +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); +} -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) +#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 +88,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,12 +107,6 @@ 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 _syscall1 (int, chrootsafe, const char *, dir) - static void init() { static int is_init = 0; @@ -112,11 +140,6 @@ static void init() 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; @@ -192,48 +215,3 @@ vc_set_ipv4root_legacy(uint32_t bcast, 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 Index: lib/syscall.c =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/syscall.c,v retrieving revision 1.1.4.4 retrieving revision 1.1.4.6 diff -u -p -u -I$Id: -r1.1.4.4 -r1.1.4.6 --- lib/syscall.c 14 Oct 2003 15:20:43 -0000 1.1.4.4 +++ lib/syscall.c 30 Dec 2003 13:45:57 -0000 1.1.4.6 @@ -39,7 +39,7 @@ #if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY) int -vc_new_s_context(ctx_t ctx, unsigned int remove_cap, unsigned int flags) +vc_new_s_context(xid_t ctx, unsigned int remove_cap, unsigned int flags) { CALL_VC(CALL_VC_COMPAT(vc_new_s_context, ctx, remove_cap, flags), CALL_VC_LEGACY(vc_new_s_context, ctx, remove_cap, flags)); @@ -50,13 +50,6 @@ vc_set_ipv4root(uint32_t bcast, size_t { CALL_VC(CALL_VC_COMPAT(vc_set_ipv4root, bcast, nb, ips), CALL_VC_LEGACY(vc_set_ipv4root, bcast, nb, ips)); -} - -int -vc_chrootsafe(char const *dir) -{ - CALL_VC(CALL_VC_COMPAT(vc_chrootsafe, dir), - CALL_VC_LEGACY(vc_chrootsafe, dir)); } #endif Index: lib/syscall_kill-v11.hc =================================================================== RCS file: lib/syscall_kill-v11.hc diff -N lib/syscall_kill-v11.hc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/syscall_kill-v11.hc 30 Dec 2003 14:06:25 -0000 1.1.2.4 @@ -0,0 +1,31 @@ +// $Id: syscall_kill-v11.hc,v 1.1.2.4 2003/12/30 14:06:25 ensc Exp $ --*- c++ -*-- + +// Copyright (C) 2003 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 + +static inline ALWAYSINLINE int +vc_ctx_kill_v11(xid_t ctx, pid_t pid, int sig) +{ + struct vcmd_ctx_kill_v0 param = { 0 }; + param.pid = pid; + param.sig = sig; + + return vserver(VC_CMD(PROCTRL, 1, 0), ctx, ¶m); +} Index: lib/syscall_kill.c =================================================================== RCS file: lib/syscall_kill.c diff -N lib/syscall_kill.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/syscall_kill.c 30 Dec 2003 13:45:57 -0000 1.1.2.2 @@ -0,0 +1,39 @@ +// $Id: syscall_kill.c,v 1.1.2.2 2003/12/30 13:45:57 ensc Exp $ --*- c++ -*-- + +// Copyright (C) 2003 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 "compat.h" + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#ifdef VC_ENABLE_API_V11 +# include "syscall_kill-v11.hc" +#endif + +int +vc_ctx_kill(xid_t ctx, pid_t pid, int sig) +{ + CALL_VC(CALL_VC_V11(vc_ctx_kill, ctx, pid, sig)); +} + +#if defined (VC_ENABLE_API_V11) +#endif Index: lib/syscall_rlimit-v11.hc =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/syscall_rlimit-v11.hc,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.6 diff -u -p -u -I$Id: -r1.1.2.3 -r1.1.2.6 --- lib/syscall_rlimit-v11.hc 19 Nov 2003 00:22:58 -0000 1.1.2.3 +++ lib/syscall_rlimit-v11.hc 30 Dec 2003 13:45:57 -0000 1.1.2.6 @@ -29,13 +29,13 @@ ((LIMIT)==VC_LIM_KEEP) ? CRLIM_KEEP : (LIMIT)) static inline ALWAYSINLINE int -vc_get_rlimit_v11(ctx_t ctx, int resource, struct vc_rlimit *lim) +vc_get_rlimit_v11(xid_t ctx, int resource, struct vc_rlimit *lim) { struct vcmd_ctx_rlimit_v0 vc_lim; int rc; vc_lim.id = resource; - rc = sys_virtual_context(VC_CMD(RLIMIT, 1, 0), CTX_USER2KERNEL(ctx), &vc_lim); + rc = vserver(VC_CMD(RLIMIT, 1, 0), CTX_USER2KERNEL(ctx), &vc_lim); lim->min = KERN2USR(vc_lim.minimum); lim->soft = KERN2USR(vc_lim.softlimit); lim->hard = KERN2USR(vc_lim.maximum); @@ -44,7 +44,7 @@ vc_get_rlimit_v11(ctx_t ctx, int resourc } static inline ALWAYSINLINE int -vc_set_rlimit_v11(ctx_t ctx, int resource, struct vc_rlimit const *lim) +vc_set_rlimit_v11(xid_t ctx, int resource, struct vc_rlimit const *lim) { struct vcmd_ctx_rlimit_v0 vc_lim; @@ -53,18 +53,18 @@ vc_set_rlimit_v11(ctx_t ctx, int resourc vc_lim.softlimit = USR2KERN(lim->soft); vc_lim.maximum = USR2KERN(lim->hard); - return sys_virtual_context(VC_CMD(RLIMIT, 2, 0), CTX_USER2KERNEL(ctx), &vc_lim); + return vserver(VC_CMD(RLIMIT, 2, 0), CTX_USER2KERNEL(ctx), &vc_lim); } static inline ALWAYSINLINE int -vc_get_rlimit_mask_v11(ctx_t ctx, int tmp, struct vc_rlimit_mask *lim) +vc_get_rlimit_mask_v11(xid_t ctx, int tmp, struct vc_rlimit_mask *lim) { struct vcmd_ctx_rlimit_v0 vc_lim; int rc; (void)tmp; - rc = sys_virtual_context(VC_CMD(RLIMIT, 3, 0), CTX_USER2KERNEL(ctx), &vc_lim); + rc = vserver(VC_CMD(RLIMIT, 3, 0), CTX_USER2KERNEL(ctx), &vc_lim); lim->min = vc_lim.minimum; lim->soft = vc_lim.softlimit; lim->hard = vc_lim.maximum; Index: lib/syscall_rlimit.c =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/syscall_rlimit.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -p -u -I$Id: -r1.1.2.1 -r1.1.2.2 --- lib/syscall_rlimit.c 7 Nov 2003 23:04:29 -0000 1.1.2.1 +++ lib/syscall_rlimit.c 30 Dec 2003 13:45:56 -0000 1.1.2.2 @@ -32,19 +32,19 @@ #if defined (VC_ENABLE_API_V11) int -vc_get_rlimit(ctx_t ctx, int resource, struct vc_rlimit *lim) +vc_get_rlimit(xid_t ctx, int resource, struct vc_rlimit *lim) { CALL_VC(CALL_VC_V11(vc_get_rlimit, ctx, resource, lim)); } int -vc_set_rlimit(ctx_t ctx, int resource, struct vc_rlimit const *lim) +vc_set_rlimit(xid_t ctx, int resource, struct vc_rlimit const *lim) { CALL_VC(CALL_VC_V11(vc_set_rlimit, ctx, resource, lim)); } int -vc_get_rlimit_mask(ctx_t ctx, struct vc_rlimit_mask *lim) +vc_get_rlimit_mask(xid_t ctx, struct vc_rlimit_mask *lim) { CALL_VC(CALL_VC_V11(vc_get_rlimit_mask, ctx, 0, lim)); } Index: lib/virtual.h =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/virtual.h,v retrieving revision 1.1.4.2 retrieving revision 1.1.4.3 diff -u -p -u -I$Id: -r1.1.4.2 -r1.1.4.3 --- lib/virtual.h 7 Nov 2003 21:58:33 -0000 1.1.4.2 +++ lib/virtual.h 28 Nov 2003 23:22:50 -0000 1.1.4.3 @@ -44,7 +44,9 @@ */ #define VC_CAT_VERSION 0 - + +#define VC_CAT_PROCTRL 12 + #define VC_CAT_RLIMIT 60 #define VC_CAT_SYSTEST 61 @@ -84,6 +86,14 @@ struct vcmd_set_ipv4root_v3 { } ip_mask_pair[NB_IPV4ROOT]; }; +/* context signalling */ + +#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0) + +struct vcmd_ctx_kill_v0 { + int32_t pid; + int32_t sig; +}; /* rlimit vserver commands */ Index: lib/vserver-internal.h =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/vserver-internal.h,v retrieving revision 1.1.4.7 retrieving revision 1.1.4.11 diff -u -p -u -I$Id: -r1.1.4.7 -r1.1.4.11 --- lib/vserver-internal.h 18 Nov 2003 20:21:43 -0000 1.1.4.7 +++ lib/vserver-internal.h 30 Dec 2003 14:07:03 -0000 1.1.4.11 @@ -26,8 +26,8 @@ #include #include -#ifndef __NR_sys_virtual_context -# define __NR_sys_virtual_context 273 +#ifndef __NR_vserver +# define __NR_vserver 273 #endif #define VC_PREFIX 0) @@ -73,7 +73,7 @@ #if 1 # define CTX_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NOCTX : \ ((X)==(uint32_t)(-2)) ? VC_SAMECTX : \ - (ctx_t)(X)) + (xid_t)(X)) # define CTX_USER2KERNEL(X) (((X)==VC_RANDCTX) ? (uint32_t)(-1) : \ ((X)==VC_SAMECTX) ? (uint32_t)(-2) : \ @@ -87,10 +87,18 @@ extern "C" { #endif -#ifndef HAVE_SYS_VIRTUAL_CONTEXT -static UNUSED -_syscall3(int, sys_virtual_context, +#ifndef HAVE_VSERVER +#if defined(__pic__) && defined(__i386) +inline static UNUSED ALWAYSINLINE +int vserver(uint32_t cmd, uint32_t id, void *data) +{ + return syscall(__NR_vserver, cmd, id, data); +} +#else +inline static UNUSED ALWAYSINLINE +_syscall3(int, vserver, uint32_t, cmd, uint32_t, id, void *, data) +#endif #endif size_t utilvserver_uint2str(char *buf, size_t len, Index: lib/vserver.h =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/lib/vserver.h,v retrieving revision 1.1.4.8 retrieving revision 1.1.4.10 diff -u -p -u -I$Id: -r1.1.4.8 -r1.1.4.10 --- lib/vserver.h 18 Nov 2003 20:19:44 -0000 1.1.4.8 +++ lib/vserver.h 30 Dec 2003 13:45:56 -0000 1.1.4.10 @@ -25,11 +25,11 @@ #include /** the value which is returned in error-case (no ctx found) */ -#define VC_NOCTX ((ctx_t)(-1)) +#define VC_NOCTX ((xid_t)(-1)) /** the value which means a random (the next free) ctx */ -#define VC_RANDCTX ((ctx_t)(-1)) +#define VC_RANDCTX ((xid_t)(-1)) /** the value which means the current ctx */ -#define VC_SAMECTX ((ctx_t)(-2)) +#define VC_SAMECTX ((xid_t)(-2)) #define VC_LIM_INFINITY (~0ULL) #define VC_LIM_KEEP (~1ULL) @@ -49,17 +49,15 @@ extern "C" { /** Puts current process into context , removes the given caps and * sets flags. * Special values for ctx are - * - -2 which means the current context (just for changing caps and flags) - * - -1 which means the next free context; this value can be used by - * ordinary users also */ - int vc_new_s_context(ctx_t ctx, unsigned int remove_cap, unsigned int flags); + * - VC_SAMECTX which means the current context (just for changing caps and flags) + * - VC_RANDCTX which means the next free context; this value can be used by + * ordinary users also */ + int vc_new_s_context(xid_t ctx, unsigned int remove_cap, unsigned int flags); /** Sets the ipv4root information. * \precondition: nb<16 */ int vc_set_ipv4root(uint32_t bcast, size_t nb, struct vc_ip_mask_pair const *ips); - int vc_chrootsafe(char const *dir); - /* rlimit related functions */ typedef uint64_t vc_limit_t; @@ -78,12 +76,19 @@ extern "C" { uint32_t hard; }; - int vc_get_rlimit(ctx_t ctx, int resource, struct vc_rlimit *lim); - int vc_set_rlimit(ctx_t ctx, int resource, struct vc_rlimit const *lim); - int vc_get_rlimit_mask(ctx_t ctx, struct vc_rlimit_mask *lim); + int vc_get_rlimit(xid_t ctx, int resource, struct vc_rlimit *lim); + int vc_set_rlimit(xid_t ctx, int resource, struct vc_rlimit const *lim); + int vc_get_rlimit_mask(xid_t ctx, struct vc_rlimit_mask *lim); + + + /** sends a signal to a context/pid + Special values for pid are: + * -1 which means every process in ctx except the init-process + * 0 which means every process in ctx inclusive the init-process */ + int vc_ctx_kill(xid_t ctx, pid_t pid, int sig); /** Returns the context of the given process. pid==0 means the current process. */ - ctx_t vc_X_getctx(pid_t pid); + xid_t vc_X_getctx(pid_t pid); #ifdef __cplusplus } Index: scripts/Makefile-files =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/scripts/Makefile-files,v retrieving revision 1.1.4.2 retrieving revision 1.1.4.3 diff -u -p -u -I$Id: -r1.1.4.2 -r1.1.4.3 --- scripts/Makefile-files 30 Oct 2003 15:16:28 -0000 1.1.4.2 +++ scripts/Makefile-files 3 Dec 2003 00:06:37 -0000 1.1.4.3 @@ -25,30 +25,34 @@ scripts_src_SCRPTS = scripts/distrib-in scripts/vprofile \ scripts/vserverkillall \ scripts/vservers.grabinfo.sh \ - scripts/vsysvwrapper \ - scripts/vunify.old.sh + scripts/vsysvwrapper scripts_gen_SCRPTS = +scripts_src_LEGSCRPTS = scripts/vunify.sh +scripts_gen_LEGSCRPTS = scripts/vkill + + scripts_src_PRGS = scripts/vpstree \ scripts/vrpm \ scripts/vserver \ scripts/vserver-copy \ scripts/vtop -scripts_gen_PRGS = scripts/vkill \ - scripts/vps +scripts_gen_PRGS = scripts/vps scripts_PRGS = $(scripts_src_PRGS) $(scripts_gen_PRGS) - -scriptscfg_DATA = scripts/util-vserver-vars scripts_SCRPTS = $(scripts_src_SCRPTS) $(scripts_gen_SCRPTS) +scripts_LEGSCRPTS = $(scripts_src_LEGSCRPTS) $(scripts_gen_LEGSCRPTS) +scriptscfg_DATA = scripts/util-vserver-vars scripts_XTRAS = scripts/util-vserver-vars.subst \ scripts/vkill.subst \ scripts/vps.subst \ - $(scripts_src_SCRPTS) $(scripts_src_PRGS) + $(scripts_src_SCRPTS) $(scripts_src_PRGS) \ + $(scripts_src_LEGSCRPTS) scripts_GENSCRPTS = scripts/util-vserver-vars \ - $(scripts_gen_SCRPTS) $(scripts_gen_PRGS) + $(scripts_gen_SCRPTS) $(scripts_gen_PRGS) \ + $(scripts_gen_LEGSCRPTS) scripts/%: scripts/%.subst @mkdir -p $$(dirname '$@') Index: scripts/vps.subst =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/scripts/Attic/vps.subst,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -p -u -I$Id: -r1.1.2.1 -r1.1.2.2 --- scripts/vps.subst 30 Oct 2003 00:38:28 -0000 1.1.2.1 +++ scripts/vps.subst 28 Nov 2003 23:26:54 -0000 1.1.2.2 @@ -48,7 +48,7 @@ if ($context != 1) { } -if (! open PS, "ps $ARGV[0]|") { +if (! open PS, "ps @ARGV|") { print "Can not execute ps\n"; exit; } Index: scripts/vserver =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/scripts/vserver,v retrieving revision 1.1.2.1.2.4 retrieving revision 1.1.2.1.2.6 diff -u -p -u -I$Id: -r1.1.2.1.2.4 -r1.1.2.1.2.6 --- scripts/vserver 18 Nov 2003 20:18:47 -0000 1.1.2.1.2.4 +++ scripts/vserver 30 Dec 2003 13:50:31 -0000 1.1.2.1.2.6 @@ -47,7 +47,7 @@ mountproc() mkdir -p $1/proc $1/dev/pts if [ ! -d $1/proc/1 ] ; then mount -t proc none $1/proc - mount -t devpts none $1/dev/pts + mount -t devpts -o gid=5,mode=0620 none $1/dev/pts fi } umountproc() @@ -474,6 +474,8 @@ elif [ "$2" = "start" ] ; then STARTCMD="/etc/init.d/rc $INITDEFAULT" elif [ -x $VROOTDIR/$1/usr/bin/emerge ] ; then STARTCMD="/sbin/rc default" + elif [ -x $VROOTDIR/$1/etc/rc.d/rc.M ] ; then + STARTCMD="/etc/rc.d/rc.M" fi DISCONNECT= @@ -589,6 +591,8 @@ elif [ "$2" = "stop" ] ; then STOPCMD="/etc/init.d/rc 6" elif [ -x $VROOTDIR/$1/usr/bin/emerge ] ; then STOPCMD="/sbin/rc shutdown" + elif [ -x $VROOTDIR/$1/etc/rc.d/rc.6 ] ; then + STOPCMD="/etc/rc.d/rc.6" fi for f in $S_FLAGS dummy Index: scripts/vunify.old.sh =================================================================== RCS file: scripts/vunify.old.sh diff -N scripts/vunify.old.sh --- scripts/vunify.old.sh 30 Oct 2003 15:16:30 -0000 1.1.4.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,123 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2003 Enrico Scholz -# based on vunify by Jacques Gelinas -# -# 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; either version 2, or (at your option) -# any later version. -# -# 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. - -# This scripts is used to unify the disk space used by vservers -# It takes various RPM packages and hard link them together so all -# vservers are sharing the same exact copy of the files. -# After doing so, it set them immutable, so the vserver can't change them - -# This has the following advantages: -# -You save disk space. If you have 100 vservers, each using 500 megs -# (common linux server installation), you can unify 90% of that -# -Memory usage. Since the exact same binary are loaded, including -# the same shared object, you save some memory and this can increase -# performance, especially the memory cache usage. -# -# On the down side, you are loosing some flexibility. The vserver -# administrators can't upgrade package as they see fit, since the -# files are immutable. On the other end, just unifying glibc is probably -# a win. -: ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars} -test -e "$UTIL_VSERVER_VARS" || { - echo "Can not find util-vserver installation; aborting..." - exit 1 -} -. "$UTIL_VSERVER_VARS" - -if [ $# = 0 ] ; then - echo vunify [ --undo ] ref-vserver vservers -- packages -else - undo=0 - if [ "$1" == "--undo" ] ; then - undo=1 - shift - fi - ref=$1 - shift - servers= - while [ "$1" != "" -a "$1" != "--" ] - do - servers="$servers $1" - shift - done - if [ "$servers" = "" ] ; then - echo No vserver specified >&2 - exit 1 - elif [ "$1" != "--" ] ; then - echo Missing -- marker >&2 - exit 1 - else - shift - if [ $# = 0 ] ; then - echo No package specified >&2 - exit 1 - else - if [ ! -d $VROOTDIR/$ref/. ] ; then - echo No vserver $ref >&2 - exit 1 - else - #echo ref=$ref - #echo servers=$servers - #echo packages=$* - tmpfile=/var/run/vunifi.$$ - rm -f $tmpfile - echo Extracting list of file to unify in $tmpfile - for pkg in $* - do - $VROOTDIR/$ref/bin/rpm --root $VROOTDIR/$ref -ql --dump $pkg | \ - while read path size mtime md5 \ - mode owner group isconfig isdoc rdev symlink - do - if [ "$isconfig" = 0 ] ; then - echo $path >>$tmpfile - fi - done - done - for serv in $servers - do - if [ "$undo" = 0 ] ; then - echo Unifying server $serv - cat $tmpfile | while read file - do - if [ ! -d $VROOTDIR/$ref/$file -a ! -L $VROOTDIR/$ref/$file ] ; then - ln -f $VROOTDIR/$ref/$file $VROOTDIR/$serv/$file - fi - done - cat $tmpfile | while read file - do - chattr +i $VROOTDIR/$ref/$file - done - else - echo Differencing server $serv - cat $tmpfile | while read file - do - chattr -i $VROOTDIR/$ref/$file - if [ ! -d $VROOTDIR/$ref/$file ] ; then - rm -f $VROOTDIR/$serv/$file - cp -a $VROOTDIR/$ref/$file $VROOTDIR/$serv/$file - fi - done - fi - done - rm -f $tmpfile - fi - fi - fi -fi - Index: scripts/vunify.sh =================================================================== RCS file: scripts/vunify.sh diff -N scripts/vunify.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ scripts/vunify.sh 3 Dec 2003 00:05:54 -0000 1.1.2.1 @@ -0,0 +1,123 @@ +#!/bin/sh + +# Copyright (C) 2003 Enrico Scholz +# based on vunify by Jacques Gelinas +# +# 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; either version 2, or (at your option) +# any later version. +# +# 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. + +# This scripts is used to unify the disk space used by vservers +# It takes various RPM packages and hard link them together so all +# vservers are sharing the same exact copy of the files. +# After doing so, it set them immutable, so the vserver can't change them + +# This has the following advantages: +# -You save disk space. If you have 100 vservers, each using 500 megs +# (common linux server installation), you can unify 90% of that +# -Memory usage. Since the exact same binary are loaded, including +# the same shared object, you save some memory and this can increase +# performance, especially the memory cache usage. +# +# On the down side, you are loosing some flexibility. The vserver +# administrators can't upgrade package as they see fit, since the +# files are immutable. On the other end, just unifying glibc is probably +# a win. +: ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars} +test -e "$UTIL_VSERVER_VARS" || { + echo "Can not find util-vserver installation; aborting..." + exit 1 +} +. "$UTIL_VSERVER_VARS" + +if [ $# = 0 ] ; then + echo vunify [ --undo ] ref-vserver vservers -- packages +else + undo=0 + if [ "$1" == "--undo" ] ; then + undo=1 + shift + fi + ref=$1 + shift + servers= + while [ "$1" != "" -a "$1" != "--" ] + do + servers="$servers $1" + shift + done + if [ "$servers" = "" ] ; then + echo No vserver specified >&2 + exit 1 + elif [ "$1" != "--" ] ; then + echo Missing -- marker >&2 + exit 1 + else + shift + if [ $# = 0 ] ; then + echo No package specified >&2 + exit 1 + else + if [ ! -d $VROOTDIR/$ref/. ] ; then + echo No vserver $ref >&2 + exit 1 + else + #echo ref=$ref + #echo servers=$servers + #echo packages=$* + tmpfile=/var/run/vunifi.$$ + rm -f $tmpfile + echo Extracting list of file to unify in $tmpfile + for pkg in $* + do + $VROOTDIR/$ref/bin/rpm --root $VROOTDIR/$ref -ql --dump $pkg | \ + while read path size mtime md5 \ + mode owner group isconfig isdoc rdev symlink + do + if [ "$isconfig" = 0 ] ; then + echo $path >>$tmpfile + fi + done + done + for serv in $servers + do + if [ "$undo" = 0 ] ; then + echo Unifying server $serv + cat $tmpfile | while read file + do + if [ ! -d $VROOTDIR/$ref/$file -a ! -L $VROOTDIR/$ref/$file ] ; then + ln -f $VROOTDIR/$ref/$file $VROOTDIR/$serv/$file + fi + done + cat $tmpfile | while read file + do + chattr +i $VROOTDIR/$ref/$file + done + else + echo Differencing server $serv + cat $tmpfile | while read file + do + chattr -i $VROOTDIR/$ref/$file + if [ ! -d $VROOTDIR/$ref/$file ] ; then + rm -f $VROOTDIR/$serv/$file + cp -a $VROOTDIR/$ref/$file $VROOTDIR/$serv/$file + fi + done + fi + done + rm -f $tmpfile + fi + fi + fi +fi + Index: src/.cvsignore =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/src/.cvsignore,v retrieving revision 1.1.2.1.2.2 retrieving revision 1.1.2.1.2.3 diff -u -p -u -I$Id: -r1.1.2.1.2.2 -r1.1.2.1.2.3 --- src/.cvsignore 17 Nov 2003 23:54:48 -0000 1.1.2.1.2.2 +++ src/.cvsignore 3 Dec 2003 00:11:12 -0000 1.1.2.1.2.3 @@ -19,6 +19,7 @@ vbuild vcheck vdu vfiles +vkill vlimit vreboot vserver-stat Index: src/Makefile-files =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/src/Makefile-files,v retrieving revision 1.1.4.6 retrieving revision 1.1.4.7 diff -u -p -u -I$Id: -r1.1.4.6 -r1.1.4.7 --- src/Makefile-files 18 Nov 2003 22:31:29 -0000 1.1.4.6 +++ src/Makefile-files 3 Dec 2003 00:07:36 -0000 1.1.4.7 @@ -42,6 +42,7 @@ src_sbin_PRGS = src/chbind \ src/vlimit \ src/vdu \ src/vfiles \ + src/vkill \ src/vserver-stat src_capchroot_SOURCES = src/capchroot.c @@ -68,6 +69,10 @@ src_reducecap_LDADD = lib/libvserver.a src_vlimit_SOURCES = src/vlimit.c src_vlimit_LDADD = lib/libvserver.a + +src_vkill_SOURCES = src/vkill.c +src_vkill_LDADD = lib/libvserver.a +src_vkill_CPPFLAGS = $(AM_CPPFLAGS) -DLEGACYDIR=\"$(legacydir)\" src_showattr_SOURCES = src/showattr.c src_showperm_SOURCES = src/showperm.c Index: src/capchroot.c =================================================================== RCS file: /cvsroot/util-vserver/util-vserver/src/capchroot.c,v retrieving revision 1.1.4.1 retrieving revision 1.1.4.2 diff -u -p -u -I$Id: -r1.1.4.1 -r1.1.4.2 --- src/capchroot.c 14 Oct 2003 00:42:13 -0000 1.1.4.1 +++ src/capchroot.c 28 Nov 2003 23:08:43 -0000 1.1.4.2 @@ -73,7 +73,7 @@ int main (int argc, char *argv[]) // and also a security flaw. The shared objects in the vserver // may be tweaked to get control of the root server ... getpwnam ("root"); - if (vc_chrootsafe (argv[dir]) == -1){ + if (chroot(argv[dir]) == -1){ fprintf (stderr,"Can't chroot to directory %s (%s)\n",argv[dir] ,strerror(errno)); }else{ Index: src/vkill.c =================================================================== RCS file: src/vkill.c diff -N src/vkill.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/vkill.c 30 Dec 2003 13:49:17 -0000 1.1.2.2 @@ -0,0 +1,229 @@ +// $Id: vkill.c,v 1.1.2.2 2003/12/30 13:49:17 ensc Exp $ --*- c -*-- + +// Copyright (C) 2003 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 "compat.h" + +#include "vserver.h" +#include "linuxvirtual.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define VERSION_COPYRIGHT_DISCLAIMER + +#define CMD_HELP 0x8000 +#define CMD_VERSION 0x8001 + +#define WRITE_MSG(FD,X) (void)(write(FD,X,sizeof(X)-1)) +#define WRITE_STR(FD,X) writeStr(FD,X) + +static struct option const +CMDLINE_OPTIONS[] = { + { "help", no_argument, 0, CMD_HELP }, + { "version", no_argument, 0, CMD_VERSION }, + { 0,0,0,0 } +}; + +struct Arguments +{ + xid_t ctx; + int sig; +}; + +static char const * const SIGNALS[] = { + // 0 1 2 3 4 5 6 7 + "UNUSED", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "UNUSED", + "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM", + "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "IO", + "XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", + 0, +}; + +inline static void UNUSED +writeStr(int fd, char const *cmd) +{ + (void)write(fd, cmd, strlen(cmd)); +} + +static void +showHelp(int fd, char const *cmd, int res) +{ + WRITE_MSG(fd, "Usage: "); + WRITE_STR(fd, cmd); + WRITE_MSG(fd, + " [-c ] [-s ] [--] *\n" + "Please report bugs to " PACKAGE_BUGREPORT "\n"); + exit(res); +} + +static void +showVersion() +{ + WRITE_MSG(1, + "vkill " VERSION " -- sends signals to processes within other contexts\n" + "This program is part of " PACKAGE_STRING "\n\n" + "Copyright (C) 2003 Enrico Scholz\n" + VERSION_COPYRIGHT_DISCLAIMER); + exit(0); +} + +static int +str2sig(char const *str) +{ + char *errptr; + int res = strtol(str, &errptr, 10); + + if (*errptr!='\0') res=-1; + if (res==-1 && strncmp(str,"SIG",3)==0) str+=3; + if (res==-1) { + char const * const *ptr = SIGNALS; + for (;*ptr!=0; ++ptr) { + if (strcmp(*ptr,str)!=0) continue; + res = ptr-SIGNALS; + break; + } + } + + return res; +} + +#if defined(VC_ENABLE_API_LEGACY) +inline static ALWAYSINLINE int +kill_wrapper_legacy(xid_t ctx, char const *proc, int sig) +{ + pid_t pid = fork(); + if (pid==-1) { + perror("fork()"); + exit(1); + } + else if (pid==0) { + int status; + int res; + while ((res=wait4(pid, &status, 0,0))==-1 && + (errno==EAGAIN || errno==EINTR)) {} + + return (res==0 && WIFEXITED(status) && WEXITSTATUS(status)) ? 0 : 1; + } + + execl(LEGACYDIR "/vkill", "legacy/vkill", proc, (void *)(0)); + perror("execl()"); + exit(1); +} + +static int +kill_wrapper(xid_t ctx, char const *pid, int sig) +{ + //printf("kill_wrapper(%u, %s, %i)\n", ctx, pid, sig); + if (vc_ctx_kill(ctx,atoi(pid),sig)==-1) { + int err = errno; + if (vc_get_version(VC_CAT_COMPAT)==-1) + return kill_wrapper_legacy(ctx, pid, sig); + else { + errno = err; + perror("vc_ctx_kill()"); + return 1; + } + } + + return 0; +} +#else // VC_ENABLE_API_LEGACY +inline static int +kill_wrapper(xid_t ctx, char const *pid, int sig) +{ + if (vc_ctx_kill(ctx,atoi(pid),sig)==-1) { + perror("vc_ctx_kill()"); + return 1; + } + return 0; +} +#endif + + +int main(int argc, char *argv[]) +{ + int fail = 0; + struct Arguments args = { + .ctx = VC_NOCTX, + .sig = SIGTERM, + }; + + while (1) { + int c = getopt_long(argc, argv, "c:s:", CMDLINE_OPTIONS, 0); + if (c==-1) break; + + switch (c) { + case CMD_HELP : showHelp(1, argv[0], 0); + case CMD_VERSION : showVersion(); + case 'c' : args.ctx = atoi(optarg); break; + case 's' : args.sig = str2sig(optarg); break; + default : + WRITE_MSG(2, "Try '"); + WRITE_STR(2, argv[0]); + WRITE_MSG(2, " --help\" for more information.\n"); + return EXIT_FAILURE; + break; + } + } + + if (args.sig==-1) { + WRITE_MSG(2, "Invalid signal specified\n"); + return EXIT_FAILURE; + } + + if (args.ctx==VC_NOCTX && optind==argc) { + WRITE_MSG(2, "No pid specified\n"); + return EXIT_FAILURE; + } + + if (optind==argc) + fail += kill_wrapper(args.ctx, "0", args.sig); + else for (;optind -// based on tests/chrootsafe.cc by Jacques Gelinas -// -// 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; either version 2, or (at your option) -// any later version. -// -// 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. - -/* - Test the chrootsafe command. - Pass the path of a vserver as the only argument - - chrootsafe /vservers/test -*/ -#ifdef HAVE_CONFIG_H -# include -#endif -#include "compat.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "vserver.h" - -int main (int, char *argv[]) -{ - // This test must fail - int fd = open ("/",O_RDONLY); - if (fd != -1){ - if (vc_chrootsafe(argv[1])==-1){ - fprintf (stderr,"Ok, chrootsafe failed with one open directory errno=%s\n",strerror(errno)); - }else{ - fprintf (stderr,"Hum, chrootsafe succeed with one open directory\n"); - system ("/bin/sh"); - } - close (fd); - } - // Now it should work - if (vc_chrootsafe(argv[1])!=-1){ - fprintf (stderr,"Ok, chrootsafe worked\n"); - system ("/bin/sh"); - }else{ - fprintf (stderr,"chrootsafe failed errno=%s\n",strerror(errno)); - } - return 0; -} -