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>
32 getCtxFromFile(char const *pathname)
37 fd = open(pathname, O_RDONLY);
40 (len=lseek(fd, 0, SEEK_END))==-1 ||
42 (lseek(fd, 0, SEEK_SET)==-1))
46 if (TEMP_FAILURE_RETRY(read(fd, buf, len+1))!=len)
52 res = strtol(buf, &errptr, 10);
53 if (*errptr!='\0' && *errptr!='\n') return VC_NOCTX;
59 vc_getVserverCtx(char const *id, vcCfgStyle style)
61 size_t l1 = strlen(id);
62 char buf[sizeof(CONFDIR "//") + l1 + sizeof("/run")];
64 if (style==vcCFG_NONE || style==vcCFG_AUTO)
65 style = vc_getVserverCfgStyle(id);
68 case vcCFG_NONE : return VC_NOCTX;
69 case vcCFG_LEGACY : return VC_NOCTX; // todo
70 case vcCFG_RECENT_SHORT :
71 case vcCFG_RECENT_FULL : {
73 if (style==vcCFG_RECENT_SHORT) {
74 memcpy(buf, CONFDIR "/", sizeof(CONFDIR "/")-1);
75 idx = sizeof(CONFDIR "/") - 1;
77 memcpy(buf+idx, id, l1); idx += l1;
78 memcpy(buf+idx, "/run", 4); idx += 4;
82 return getCtxFromFile(buf);
84 default : return VC_NOCTX;