X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fvserver-start%2Fconfiguration.c;h=bba7ab40cc27728ba4f5a142c72c5ff3701f7cde;hb=3eb1b2279739d0f16391a3724a9897c686f030d3;hp=435c9ea57693912229d00d4fb92707419cce619a;hpb=e3be43e3ee2157a63ea175463629c2433f595854;p=util-vserver.git diff --git a/util-vserver/vserver-start/configuration.c b/util-vserver/vserver-start/configuration.c index 435c9ea..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 @@ -47,10 +48,10 @@ getSingleInterface(struct Interface *res, } static inline bool -getInterfaces(struct Configuration *c, PathInfo const *cfgdir) +getInterfaces(struct Configuration *cfg) { ENSC_PI_DECLARE(iface_subdir, "interfaces"); - PathInfo ifacepath = *cfgdir; + PathInfo ifacepath = cfg->cfgdir; char path_buf[ENSC_PI_APPSZ(ifacepath, iface_subdir)]; struct Interface iface_default; DIR *dir; @@ -78,7 +79,7 @@ getInterfaces(struct Configuration *c, PathInfo const *cfgdir) if (!getSingleInterface(&iface, &iface_default, &ifacepath, ent->d_name)) rc = false; else if (iface.addr.ipv4.ip!=0) { // HACK: non-directory entries would return true also - struct Interface *new_iface = Vector_pushback(&c->interfaces); + struct Interface *new_iface = Vector_pushback(&cfg->interfaces); *new_iface = iface; } } @@ -89,8 +90,75 @@ getInterfaces(struct Configuration *c, PathInfo const *cfgdir) return rc; } +static bool +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\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 *c, PathInfo const *cfgdir) +getConfiguration(struct Configuration *cfg, PathInfo const *cfgdir) { - return getInterfaces(c, 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)); }