added lots of new code
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 19 Oct 2004 21:11:10 +0000 (21:11 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 19 Oct 2004 21:11:10 +0000 (21:11 +0000)
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
util-vserver/vserver-start/configuration.c
util-vserver/vserver-start/configuration.h
util-vserver/vserver-start/interface.c
util-vserver/vserver-start/interface.h
util-vserver/vserver-start/main.c
util-vserver/vserver-start/scriptlets.c
util-vserver/vserver-start/vserver-start.h

index 74a7604..b3063ba 100644 (file)
 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;
 }
index 3ca1941..bba7ab4 100644 (file)
@@ -24,6 +24,7 @@
 #include "interface.h"
 
 #include <lib_internal/util.h>
+#include <lib_internal/filecfg.h>
 #include <ensc_vector/vector.h>
 #include <lib/internal.h>
 
@@ -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));
 }
index c027ba9..9c9bc12 100644 (file)
 
 #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);
index d6fd9f1..c3f3bb3 100644 (file)
@@ -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 ");
index bd0d8b0..3913c18 100644 (file)
 #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 {
@@ -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 *);
index deaebda..6da6b27 100644 (file)
@@ -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 <ensc_wrappers/wrappers.h>
@@ -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;
 
index c2375ae..3959187 100644 (file)
@@ -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);
   }
 }
index 67af782..74549e4 100644 (file)
@@ -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