X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Ftagopt2tag.c;fp=lib%2Ftagopt2tag.c;h=7f4b6aa708e4e6870e771f930b02226d7d8782ba;hb=a741f6faf2baae1e823d334012f6a09e6a1bda51;hp=0000000000000000000000000000000000000000;hpb=426a0d3a38995dc25a839aaa56d8642e6bdcbba5;p=util-vserver.git diff --git a/lib/tagopt2tag.c b/lib/tagopt2tag.c new file mode 100644 index 0000000..7f4b6aa --- /dev/null +++ b/lib/tagopt2tag.c @@ -0,0 +1,57 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// Copyright (C) 2007 Daniel Hokka Zakrisson +// +// 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 +#include + +static tag_t +getVserverTag(char const *id, bool honor_static, char const **err) +{ + *err = "vc_getVserverCtx"; + return vc_getVserverCtx(id, vcCFG_AUTO, honor_static, 0, vcCTX_TAG); +} + +tag_t +vc_tagopt2tag(char const *str, bool honor_static, char const **err_info) +{ + char const * err; + tag_t res = VC_NOCTX; + + err = "vc_task_tag()"; + if (strcmp(str,"self")==0) res = vc_get_task_tag(0); + else if (str[0]==':') res = getVserverTag(str+1, honor_static, &err); + else { + char * endptr; + tag_t tag = strtol(str, &endptr, 10); + + if (endptr!=str && (*endptr=='\0' || *endptr=='\n')) + res = tag; + else + res = getVserverTag(str, honor_static, &err); + } + + if (res==VC_NOCTX && err_info) *err_info = err; + + return res; +}