# define MS_MOVE 8192
#endif
-#ifndef HAVE_CTX_T
+#ifndef HAVE_XID_T
#include <stdint.h>
-typedef uint32_t ctx_t;
+typedef uint32_t xid_t;
#endif
#if defined(__dietlibc__)
#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);
#include <errno.h>
#include <sys/types.h>
-static ctx_t
+static xid_t
vc_X_getctx_legacy_internal(pid_t pid)
{
size_t bufsize = utilvserver_getProcEntryBufsize();
else return VC_NOCTX;
}
-static ctx_t
+static xid_t
vc_X_getctx_legacy(pid_t pid)
{
- ctx_t res;
+ xid_t res;
do {
res = vc_X_getctx_legacy_internal(pid);
} while (res==VC_NOCTX && errno==EAGAIN);
#include <sys/types.h>
-ctx_t
+xid_t
vc_X_getctx(pid_t pid)
{
CALL_VC(CALL_VC_COMPAT(vc_X_getctx, pid),
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-#include "compat.h"
#include "vserver-internal.h"
static inline ALWAYSINLINE UNUSED 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
int
vc_get_version(int cat)
{
- return vc_get_version(cat);
+ return vc_get_version_internal(cat);
}
#include <unistd.h>
char *
-vc_getVserverByCtx(ctx_t ctx, vcCfgStyle *style, char const *revdir)
+vc_getVserverByCtx(xid_t ctx, vcCfgStyle *style, char const *revdir)
{
if (revdir==0) revdir = DEFAULT_PKGSTATEREVDIR;
#include <string.h>
#include <unistd.h>
-static ctx_t
+static xid_t
getCtxFromFile(char const *pathname)
{
int fd;
BS;
char buf[len+1];
char *errptr;
- ctx_t res;
+ xid_t res;
if (TEMP_FAILURE_RETRY(read(fd, buf, len+1))!=len)
return VC_NOCTX;
BE;
}
-ctx_t
+xid_t
vc_getVserverCtx(char const *id, vcCfgStyle style)
{
size_t l1 = strlen(id);
#include <unistd.h>
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
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
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);
+}
-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_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);
+}
+
+#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
//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
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 bool is_init = false;
#include "utils-legacy.h"
__NR_set_ipv4root_rev3 = num;
}
-#if 0
- SET_TAG_POS("\n__NR_set_ctxlimit: ");
- if ( pos!=0 && getNumRevPair(pos, &num, &rev_set_ctxlimit) )
- __NR_set_ctxlimit = num;
-#endif
-
- SET_TAG_POS("\n__NR_chrootsafe: ");
- if ( pos!=0 && getNumRevPair(pos, &num, &rev_chrootsafe) )
- __NR_chrootsafe = num;
-
SET_TAG_POS("\n__NR_new_s_context: ");
if ( pos!=0 && getNumRevPair(pos, &num, &rev_s_context) )
__NR_new_s_context_rev0 = num;
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{
- WRITE_MSG(2, "chrootsafe: kernel supports wrong version, application expects version 0\n");
- }
- errno = EINVAL;
- return -1;
-}
#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));
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
((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);
}
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;
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 UNUSED tmp, struct vc_rlimit_mask *lim)
+vc_get_rlimit_mask_v11(xid_t ctx, int UNUSED tmp, struct vc_rlimit_mask *lim)
{
struct vcmd_ctx_rlimit_v0 vc_lim;
int rc;
- 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;
#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));
}
#ifndef _LINUX_VIRTUAL_H
#define _LINUX_VIRTUAL_H
+
+#define NB_IPV4ROOT 16
+
+
#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
#define VC_VERSION(c) ((c) & 0xFFF)
/*
- Syscall Matrix V2.2
+ Syscall Matrix V2.3
|VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
|STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
*/
-#define VC_CAT_VERSION 0
+#define VC_CAT_VERSION 0
+#define VC_CAT_PROCTRL 12
+
#define VC_CAT_RLIMIT 60
#define VC_CAT_SYSTEST 61
-#define VC_CAT_COMPAT 63
+#define VC_CAT_COMPAT 63
/* interface version */
-#define VCI_VERSION 0x00010001
+#define VCI_VERSION 0x00010004
uint32_t flags;
};
-#define NB_IPV4ROOT 16
-
struct vcmd_set_ipv4root_v3 {
/* number of pairs in id */
uint32_t broadcast;
} 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 */
-#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
-#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
-#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
+#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
+#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
+#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
struct vcmd_ctx_rlimit_v0 {
- uint32_t id;
+ uint32_t id;
uint64_t minimum;
uint64_t softlimit;
uint64_t maximum;
uint32_t maximum;
};
-#define CRLIM_INFINITY (~0ULL)
-#define CRLIM_KEEP (~1ULL)
+#define CRLIM_INFINITY (~0ULL)
+#define CRLIM_KEEP (~1ULL)
#endif /* _LINUX_VIRTUAL_H */
#include <syscall.h>
#include <errno.h>
#include <stdint.h>
+#include <sys/syscall.h>
+#include <unistd.h>
-#ifndef __NR_sys_virtual_context
-# define __NR_sys_virtual_context 273
+#include "internal.h"
+
+#ifndef __NR_vserver
+# define __NR_vserver 273
#endif
#define VC_PREFIX 0)
#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) : \
#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)
+{
+#if defined __dietlibc__
+ extern long int syscall (long int __sysno, ...);
+#endif
+
+ 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
#endif // H_VSERVER_SYSCALL_INTERNAL_H
#include <sys/types.h>
/** 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)
/** Puts current process into context <ctx>, 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;
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);
/** Returns the pid of the 'init' process */
pid_t vc_X_getinitpid(pid_t pid);
/** Returns the ctx of the given vserver, or VC_NOCTX if vserver is not
* running */
- ctx_t vc_getVserverCtx(char const *id, vcCfgStyle style);
+ xid_t vc_getVserverCtx(char const *id, vcCfgStyle style);
/** Resolves the cfg-path of the vserver owning the given ctx. 'revdir' will
be used as the directory holding the mapping-links; when NULL, the
default value will be assumed. The result will be allocated and must be
freed by the caller. */
- char * vc_getVserverByCtx(ctx_t ctx, /*@null@*/vcCfgStyle *style,
+ char * vc_getVserverByCtx(xid_t ctx, /*@null@*/vcCfgStyle *style,
/*@null@*/char const *revdir);
#ifdef __cplusplus
scripts/vrpm-preload \
scripts/save_s_context \
scripts/vservers.grabinfo.sh \
- scripts/vsysvwrapper \
scripts/vps \
scripts/vpstree \
scripts/vserver-copy \
scripts/vserver-build \
scripts/vserver-legacy \
scripts/vserverkillall \
- scripts/vservers.grabinfo.sh \
- scripts/vsysvwrapper
+ scripts/vservers.grabinfo.sh
+scripts_legacy_src_SCRPTS =
+scripts_legacy_gen_SCRPTS =
scripts_sbin_src_PRGS = scripts/vapt-get \
scripts/vpstree \
scripts_sbin_PRGS = $(scripts_sbin_src_PRGS) $(scripts_sbin_gen_PRGS)
scripts_sbincfg_DTA = $(scripts_sbincfg_gen_DTA)
scripts_pkglib_SCRPTS = $(scripts_pkglib_src_SCRPTS)
+scripts_legacy_SCRPTS = $(scripts_legacy_src_SCRPTS) $(scripts_legacy_gen_SCRPTS)
scripts_pkglib_DTA = $(scripts_pkglib_src_DTA) $(scripts_pkglib_gen_DTA)
scripts_CLEANFILES = $(scripts_pkglib_gen_DTA) \
scripts_XTRAS = $(scripts_pkglib_src_DTA) \
$(scripts_pkglib_src_SCRPTS) \
+ $(scripts_legacy_src_SCRPTS) \
$(scripts_sbin_src_PRGS) \
$(scripts_subst_SRCS)
}
-if (! open PS, "ps $ARGV[0]|") {
+if (! open PS, "ps @ARGV|") {
print "Can not execute ps\n";
exit;
}
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()
STARTCMD="/etc/init.d/rc $INITDEFAULT"
elif [ -x $DEFAULT_VSERVERDIR/$1/usr/bin/emerge ] ; then
STARTCMD="/sbin/rc default"
+ elif [ -x $DEFAULT_VSERVERDIR/$1/etc/rc.d/rc.M ] ; then
+ STARTCMD="/etc/rc.d/rc.M"
fi
DISCONNECT=
STOPCMD="/etc/init.d/rc 6"
elif [ -x $DEFAULT_VSERVERDIR/$1/usr/bin/emerge ] ; then
STOPCMD="/sbin/rc shutdown"
+ elif [ -x $DEFAULT_VSERVERDIR/$1/etc/rc.d/rc.6 ] ; then
+ STOPCMD="/etc/rc.d/rc.6"
fi
for f in $S_FLAGS dummy
vcheck
vdu
vfiles
+vkill
vlimit
vreboot
vserver-stat
struct ArgInfo {
enum { tpUNSET, tpCTX, tpPID } type;
- ctx_t ctx;
+ xid_t ctx;
pid_t pid;
unsigned int interval;
bool shutdown;
return 0;
}
-static ctx_t
+static xid_t
determineContext(pid_t pid)
{
int fd[2];
pid_t chld;
- ctx_t res;
+ xid_t res;
Epipe(fd);
chld = Efork();
int wrapper_exit_code = 1;
struct ArgInfo {
- ctx_t ctx;
+ xid_t ctx;
uid_t uid;
gid_t gid;
bool do_fork;
#define DBG_VERBOSE2 (0x2000 | DBG_VERBOSE1)
static char const * ctx_s = 0;
-static ctx_t ctx = VC_NOCTX;
+static xid_t ctx = VC_NOCTX;
static uint32_t caps = ~0;
static int flags = 0;
static char const * mnts = 0;
char dstfile[PATH_MAX];
int fd;
char buf[sizeof(int)*3+2];
- ctx_t ctx;
+ xid_t ctx;
ssize_t len;
ssize_t len1 = strlen(argv[1]);
int set_mask = 0;
struct vc_rlimit limits[32];
bool show_all = false;
- ctx_t ctx = VC_SAMECTX;
+ xid_t ctx = VC_SAMECTX;
{
size_t i;
struct ArgInfo {
enum { tpUNSET, tpCTX, tpPID } type;
- ctx_t ctx;
+ xid_t ctx;
pid_t pid;
unsigned int interval;
bool shutdown;
#include <vserver.h>
inline static UNUSED void
-Evc_new_s_context(ctx_t ctx, unsigned int remove_cap, unsigned int flags)
+Evc_new_s_context(xid_t ctx, unsigned int remove_cap, unsigned int flags)
{
FatalErrnoError(vc_new_s_context(ctx,remove_cap,flags)==-1,
"vc_new_s_context()");
}
-inline static UNUSED ctx_t
+inline static UNUSED xid_t
Evc_X_getctx(pid_t pid)
{
- register ctx_t res = vc_X_getctx(pid);
+ register xid_t res = vc_X_getctx(pid);
FatalErrnoError(res==VC_NOCTX, "vc_X_getctx()");
return res;
}
int main(int argc, char *argv[])
{
char buf[sizeof(int)*3+2];
- ctx_t ctx;
+ xid_t ctx;
if (argc==1) ctx = vc_X_getctx(0);
else ctx = vc_X_getctx(atoi(argv[1]));