From 328f35cbd18b219a593f75b2048f2b45ad65f912 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Tue, 19 Oct 2004 21:11:10 +0000 Subject: [PATCH] added lots of new code git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1746 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/vserver-start/configuration-init.c | 14 +++++++ util-vserver/vserver-start/configuration.c | 55 ++++++++++++++++++++++++- util-vserver/vserver-start/configuration.h | 10 ++++- util-vserver/vserver-start/interface.c | 6 +-- util-vserver/vserver-start/interface.h | 9 ++-- util-vserver/vserver-start/main.c | 24 ++++++++++- util-vserver/vserver-start/scriptlets.c | 7 ++-- util-vserver/vserver-start/vserver-start.h | 2 + 8 files changed, 113 insertions(+), 14 deletions(-) diff --git a/util-vserver/vserver-start/configuration-init.c b/util-vserver/vserver-start/configuration-init.c index 74a7604..b3063ba 100644 --- a/util-vserver/vserver-start/configuration-init.c +++ b/util-vserver/vserver-start/configuration-init.c @@ -25,8 +25,22 @@ void Cfg_init(struct Configuration *cfg) { + struct vc_ctx_caps const caps = { + .bcaps = 0, + .bmask = 0, + .ccaps = 0, + .cmask = 0 + }; + + struct vc_ctx_flags const flags = { + .flagword = 0, + .mask = 0 + }; + Vector_init(&cfg->interfaces, sizeof(struct Interface)); cfg->vdir = 0; cfg->xid = VC_DYNAMIC_XID; cfg->broadcast = 0; + cfg->ctx_caps = caps; + cfg->ctx_flags = flags; } diff --git a/util-vserver/vserver-start/configuration.c b/util-vserver/vserver-start/configuration.c index 3ca1941..bba7ab4 100644 --- a/util-vserver/vserver-start/configuration.c +++ b/util-vserver/vserver-start/configuration.c @@ -24,6 +24,7 @@ #include "interface.h" #include +#include #include #include @@ -94,18 +95,70 @@ initVdir(char const **vdir, PathInfo const *cfgdir) { *vdir = vc_getVserverVdir(cfgdir->d, vcCFG_RECENT_FULL, true); if (*vdir==0) { - WRITE_MSG(2, "Can not find root-directory of the vserver"); + WRITE_MSG(2, "Can not find root-directory of the vserver\n"); return false; } return true; } +static bool +setFlag(void *flags_v, char const *str, size_t len) +{ + struct vc_ctx_flags *flags = flags_v; + int rc = vc_list2cflag(str,len, 0,flags); + + return rc!=-1; +} + +static bool +setCCap(void *caps_v, char const *str, size_t len) +{ + struct vc_ctx_caps *caps = caps_v; + int rc = vc_list2ccap(str,len, 0,caps); + + return rc!=-1; +} + +static bool +setBCap(void *caps_v, char const *str, size_t len) +{ + struct vc_ctx_caps *caps = caps_v; + int rc = vc_list2bcap(str,len, 0,caps); + + return rc!=-1; +} + +static bool +readSomething(void *dest, PathInfo const *cfgdir, char const *item, + FileCfg_MultiLineHandler handler) +{ + char const *data = FileCfg_readEntryStr(cfgdir, item, true, 0); + bool res = false; + + if (!data) return true; + if (!FileCfg_iterateOverMultiLine(data, handler, dest)) { + WRITE_MSG(2, "Failed to parse '"); + WRITE_STR(2, item); + WRITE_MSG(2, "' configuration\n"); + goto finish; + } + + res = true; + finish: + free(const_cast(char *)(data)); + return res; +} + bool getConfiguration(struct Configuration *cfg, PathInfo const *cfgdir) { cfg->cfgdir = *cfgdir; + cfg->nice = FileCfg_readEntryStr(cfgdir, "nice", false, 0); return (initVdir(&cfg->vdir, cfgdir) && + readSomething(&cfg->ctx_flags, cfgdir, "flags", setFlag) && + readSomething(&cfg->ctx_caps, cfgdir, "ccapabilities", setCCap) && + readSomething(&cfg->ctx_caps, cfgdir, "bcapabilities", setBCap) && getInterfaces(cfg)); } diff --git a/util-vserver/vserver-start/configuration.h b/util-vserver/vserver-start/configuration.h index c027ba9..9c9bc12 100644 --- a/util-vserver/vserver-start/configuration.h +++ b/util-vserver/vserver-start/configuration.h @@ -25,15 +25,21 @@ #include +typedef struct Vector InterfaceList; + struct Configuration { PathInfo cfgdir; char const * vdir; xid_t xid; uint32_t broadcast; - struct Vector interfaces; + InterfaceList interfaces; + char const * nice; + + struct vc_ctx_caps ctx_caps; + struct vc_ctx_flags ctx_flags; }; -extern struct Configuration cfg; + //extern struct Configuration cfg; void Cfg_init(struct Configuration *); bool getConfiguration(struct Configuration *, PathInfo const *cfgdir); diff --git a/util-vserver/vserver-start/interface.c b/util-vserver/vserver-start/interface.c index d6fd9f1..c3f3bb3 100644 --- a/util-vserver/vserver-start/interface.c +++ b/util-vserver/vserver-start/interface.c @@ -35,12 +35,12 @@ Iface_removeWrapper(void const *iface) } void -activateInterfaces() +activateInterfaces(InterfaceList const *interfaces) { struct Interface const * iface; - for (iface=Vector_begin(&cfg.interfaces); - iface!=Vector_end(&cfg.interfaces); + for (iface=Vector_begin_const(interfaces); + iface!=Vector_end_const(interfaces); ++iface) { if (!Iface_add(iface)) { WRITE_MSG(2, "Failed to add interface "); diff --git a/util-vserver/vserver-start/interface.h b/util-vserver/vserver-start/interface.h index bd0d8b0..3913c18 100644 --- a/util-vserver/vserver-start/interface.h +++ b/util-vserver/vserver-start/interface.h @@ -19,10 +19,11 @@ #ifndef H_UTIL_VSERVER_VSERVER_START_INTERFACE_H #define H_UTIL_VSERVER_VSERVER_START_INTERFACE_H -#include +#include "configuration.h" -#include +#include #include +#include #include struct Interface { @@ -44,8 +45,8 @@ struct Interface { bool up; }; -void activateInterfaces(); -void deactivateInterfaces(); +void activateInterfaces(InterfaceList const *interfaces); +void deactivateInterfaces(InterfaceList const *interfaces); static void Iface_init(struct Interface *); static void Iface_free(struct Interface *); diff --git a/util-vserver/vserver-start/main.c b/util-vserver/vserver-start/main.c index deaebda..6da6b27 100644 --- a/util-vserver/vserver-start/main.c +++ b/util-vserver/vserver-start/main.c @@ -41,6 +41,7 @@ #define ENSC_WRAPPERS_VSERVER 1 #define ENSC_WRAPPERS_SOCKET 1 +#define ENSC_WRAPPERS_UNISTD 1 #define ENSC_WRAPPERS_FCNTL 1 #define ENSC_WRAPPERS_STDLIB 1 #include @@ -125,6 +126,17 @@ checkConstraints() Vshelper_doSanityCheck(); } +static void +setCFlag(xid_t xid, uint_least64_t value) +{ + struct vc_ctx_flags flags = { + .flagword = value, + .mask = value + }; + + Evc_set_cflags(xid, &flags); +} + int main(int argc, char *argv[]) { Cfg_init(&cfg); @@ -151,16 +163,26 @@ int main(int argc, char *argv[]) case 0 : Undo_init(); execScriptlets(&cfgdir, opts.VSERVER_NAME, "prepre-start"); - activateInterfaces(); + activateInterfaces(&cfg.interfaces); xid = Evc_ctx_create(cfg.xid); + setCFlag(xid, VC_VXF_INFO_NAMESPACE); + mountVserver(&cfg); // prepareInit(&cfg, &cfgdir); Esend(sync_fd[0], &xid, sizeof xid, MSG_NOSIGNAL); + // 'pre-start.parent' will be executed now in the parent-context Erecv(sync_fd[0], &c, 1, 0); execScriptlets(&cfgdir, opts.VSERVER_NAME, "pre-start"); + if (cfg.nice) + Enice(atoi(cfg.nice)); + if (opts.OPTION_DEFAULTTTY) + setDefaultTTY(&cfgdir, 0); + + + Undo_detach(); break; diff --git a/util-vserver/vserver-start/scriptlets.c b/util-vserver/vserver-start/scriptlets.c index c2375ae..3959187 100644 --- a/util-vserver/vserver-start/scriptlets.c +++ b/util-vserver/vserver-start/scriptlets.c @@ -157,14 +157,15 @@ execScriptlets(PathInfo const *cfgdir, char const *vname, char const *style) char * ptr; bool doit = true; - ptr = Xmemcpy(path_buf, cfgdir->d, cfgdir->l); - ptr = Xmemcpy(ptr, "/scripts/", sizeof("/scripts/")); + ptr = Xmemcpy(path_buf, cfgdir->d, cfgdir->l); + ptr = Xmemcpy(ptr, "/scripts/", sizeof("/scripts/")); basepath.l = ptr-path_buf-1; - doit = !visitPath(&basepath, vname, &styledir); + doit = !visitPath(&basepath, vname, &styledir); if (doit) { ptr = Xmemcpy(path_buf, CONFDIR "/.defaults/scripts/", sizeof(CONFDIR "/.defaults/scripts/")); + basepath.l = ptr-path_buf-1; doit = !visitPath(&basepath, vname, &styledir); } } diff --git a/util-vserver/vserver-start/vserver-start.h b/util-vserver/vserver-start/vserver-start.h index 67af782..74549e4 100644 --- a/util-vserver/vserver-start/vserver-start.h +++ b/util-vserver/vserver-start/vserver-start.h @@ -27,10 +27,12 @@ struct Options { char const * VSERVER_NAME; bool OPTION_DEBUG; bool OPTION_DEFAULTTTY; + bool OPTION_SECURE; }; extern struct Options opts; void execScriptlets(PathInfo const *cfgdir, char const *name, char const *style); +void setDefaultTTY(PathInfo const *cfgdir, char const *dflt); #endif // H_UTIL_VSERVER_VSERVER_START_VSERVER_START_H -- 1.8.1.5