initial checkin
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Thu, 11 Mar 2004 04:39:59 +0000 (04:39 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Thu, 11 Mar 2004 04:39:59 +0000 (04:39 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1207 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/lib/getvserverbyctx-compat.hc [new file with mode: 0644]
util-vserver/lib/getvserverbyctx-v13.hc [new file with mode: 0644]

diff --git a/util-vserver/lib/getvserverbyctx-compat.hc b/util-vserver/lib/getvserverbyctx-compat.hc
new file mode 100644 (file)
index 0000000..9dcd49a
--- /dev/null
@@ -0,0 +1,67 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//  
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//  
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//  
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "vserver.h"
+#include "internal.h"
+#include "pathconfig.h"
+#include "compat-c99.h"
+
+#include <string.h>
+#include <unistd.h>
+
+static char *
+vc_getVserverByCtx_compat(xid_t ctx, vcCfgStyle *style, char const *revdir)
+{
+  if (revdir==0) revdir = DEFAULT_PKGSTATEREVDIR;
+
+  {
+  vcCfgStyle   cur_style = vcCFG_NONE;
+  size_t       l = strlen(revdir);
+  size_t       l1;
+  char         path[l + sizeof(unsigned int)*3 + 2 + sizeof("/name")];
+
+  strcpy(path, revdir);
+  path[l]      = '/';
+  l1 = utilvserver_fmt_uint(path+l+1, ctx);
+  path[l+1+l1] = '\0';
+
+  if (style==0 || *style==vcCFG_AUTO) {
+    if (access(path, F_OK)==0) cur_style = vcCFG_RECENT_FULL;
+      // TODO: handle legacy
+  }
+  else
+    cur_style = *style;
+
+  switch (cur_style) {
+    case vcCFG_RECENT_SHORT    :
+    case vcCFG_RECENT_FULL     :
+       // check if expected ctx == actual ctx
+      if (vc_getVserverCtx(path, vcCFG_RECENT_FULL, false, 0)!=ctx) return 0;
+
+      if (style) *style = vcCFG_RECENT_FULL;
+      return strdup(path);
+       // TODO: handle legacy
+    default            :
+      return 0;
+  }
+  }
+}
diff --git a/util-vserver/lib/getvserverbyctx-v13.hc b/util-vserver/lib/getvserverbyctx-v13.hc
new file mode 100644 (file)
index 0000000..7cd90a8
--- /dev/null
@@ -0,0 +1,35 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//  
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//  
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//  
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+static char *
+vc_getVserverByCtx_v13(xid_t ctx, vcCfgStyle *style, char const UNUSED *revdir)
+{
+  char         buf[128];
+
+  if (vc_get_vhi_name(ctx, vcVHI_CONTEXT, buf, sizeof buf)!=-1 &&
+      vc_getVserverCtx(buf, vcCFG_RECENT_FULL, false, 0)==ctx) {
+    if (style) *style = vcCFG_RECENT_FULL;
+    return strdup(buf);
+  }
+  else
+    return 0;
+}