From 35beb69733795db31c422711ceabde45a2163ea7 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Thu, 11 Mar 2004 04:39:59 +0000 Subject: [PATCH] initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1207 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/lib/getvserverbyctx-compat.hc | 67 ++++++++++++++++++++++++++++++ util-vserver/lib/getvserverbyctx-v13.hc | 35 ++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 util-vserver/lib/getvserverbyctx-compat.hc create mode 100644 util-vserver/lib/getvserverbyctx-v13.hc diff --git a/util-vserver/lib/getvserverbyctx-compat.hc b/util-vserver/lib/getvserverbyctx-compat.hc new file mode 100644 index 0000000..9dcd49a --- /dev/null +++ b/util-vserver/lib/getvserverbyctx-compat.hc @@ -0,0 +1,67 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// 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 +#endif + +#include "vserver.h" +#include "internal.h" +#include "pathconfig.h" +#include "compat-c99.h" + +#include +#include + +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 index 0000000..7cd90a8 --- /dev/null +++ b/util-vserver/lib/getvserverbyctx-v13.hc @@ -0,0 +1,35 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#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; +} -- 1.8.1.5