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;
}
#include "interface.h"
#include <lib_internal/util.h>
+#include <lib_internal/filecfg.h>
#include <ensc_vector/vector.h>
#include <lib/internal.h>
{
*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));
}
#include <stdbool.h>
+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);
}
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 ");
#ifndef H_UTIL_VSERVER_VSERVER_START_INTERFACE_H
#define H_UTIL_VSERVER_VSERVER_START_INTERFACE_H
-#include <lib_internal/util-cast.h>
+#include "configuration.h"
-#include <lib/vserver.h>
+#include <lib_internal/util-cast.h>
#include <lib_internal/pathinfo.h>
+#include <lib/vserver.h>
#include <stdbool.h>
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 *);
#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 <ensc_wrappers/wrappers.h>
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);
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;
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);
}
}
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