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"
25 #include "compat-c99.h"
27 #include <sys/types.h>
35 getCtxFromFile(char const *pathname)
40 fd = open(pathname, O_RDONLY);
43 (len=lseek(fd, 0, SEEK_END))==-1 ||
45 (lseek(fd, 0, SEEK_SET)==-1))
53 if (TEMP_FAILURE_RETRY(read(fd, buf, len+1))!=len)
56 res = strtol(buf, &errptr, 10);
57 if (*errptr!='\0' && *errptr!='\n') return VC_NOCTX;
64 vc_getVserverCtx(char const *id, vcCfgStyle style)
66 size_t l1 = strlen(id);
67 char buf[sizeof(CONFDIR "//") + l1 + sizeof("/run")];
69 if (style==vcCFG_NONE || style==vcCFG_AUTO)
70 style = vc_getVserverCfgStyle(id);
73 case vcCFG_NONE : return VC_NOCTX;
74 case vcCFG_LEGACY : return VC_NOCTX; // todo
75 case vcCFG_RECENT_SHORT :
76 case vcCFG_RECENT_FULL : {
78 if (style==vcCFG_RECENT_SHORT) {
79 memcpy(buf, CONFDIR "/", sizeof(CONFDIR "/")-1);
80 idx = sizeof(CONFDIR "/") - 1;
82 memcpy(buf+idx, id, l1); idx += l1;
83 memcpy(buf+idx, "/run", 4); idx += 4;
87 return getCtxFromFile(buf);
89 default : return VC_NOCTX;