3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "pathconfig.h"
26 #include <sys/types.h>
34 getCtxFromFile(char const *pathname)
39 fd = open(pathname, O_RDONLY);
42 (len=lseek(fd, 0, SEEK_END))==-1 ||
44 (lseek(fd, 0, SEEK_SET)==-1))
48 if (TEMP_FAILURE_RETRY(read(fd, buf, len+1))!=len)
54 res = strtol(buf, &errptr, 10);
55 if (*errptr!='\0' && *errptr!='\n') return VC_NOCTX;
61 vc_getVserverCtx(char const *id, vcCfgStyle style)
63 size_t l1 = strlen(id);
64 char buf[sizeof(CONFDIR "//") + l1 + sizeof("/run")];
66 if (style==vcCFG_NONE || style==vcCFG_AUTO)
67 style = vc_getVserverCfgStyle(id);
70 case vcCFG_NONE : return VC_NOCTX;
71 case vcCFG_LEGACY : return VC_NOCTX; // todo
72 case vcCFG_RECENT_SHORT :
73 case vcCFG_RECENT_FULL : {
75 if (style==vcCFG_RECENT_SHORT) {
76 memcpy(buf, CONFDIR "/", sizeof(CONFDIR "/")-1);
77 idx = sizeof(CONFDIR "/") - 1;
79 memcpy(buf+idx, id, l1); idx += l1;
80 memcpy(buf+idx, "/run", 4); idx += 4;
84 return getCtxFromFile(buf);
86 default : return VC_NOCTX;