+#define WHITESPACE(buffer,index,len) \
+ while(isspace((int)buffer[index])) \
+ if (index < len) index++; else goto out;
+
+struct resources {
+ char *name;
+ int *limit;
+};
+
+#define VSERVERCONF "/etc/vservers/"
+static void get_limits(char *context, int *cpu, int *mem, int *task) {
+ FILE *fb;
+ size_t len = strlen(VSERVERCONF) + strlen(context) + strlen(".conf") + NULLBYTE_SIZE;
+ char *conf = (char *)malloc(len);
+ struct resources list[] =
+ {{"MEMLIMIT", mem},
+ {"CPULIMIT", cpu},
+ {"TASKLIMIT", task},
+ {0,0}};
+ struct resources *r;
+
+ sprintf(conf, "%s%s.conf", VSERVERCONF, context);
+
+ /* open the conf file for reading */
+ fb = fopen(conf,"r");
+ if (fb != NULL) {
+ size_t index;
+ char *buffer = malloc(1000);
+ char *p;
+
+ /* the conf file exist */
+ while((p=fgets(buffer,1000-1,fb))!=NULL) {
+ index = 0;
+ len = strnlen(buffer,1000);
+ WHITESPACE(buffer,index,len);
+ if (buffer[index] == '#')
+ continue;
+
+ for (r=list; r->name; r++)
+ if ((p=strstr(&buffer[index],r->name))!=NULL) {
+ /* adjust index into buffer */
+ index+= (p-&buffer[index])+strlen(r->name);
+
+ /* skip over whitespace */
+ WHITESPACE(buffer,index,len);
+
+ /* expecting to see = sign */
+ if (buffer[index++]!='=') goto out;
+
+ /* skip over whitespace */
+ WHITESPACE(buffer,index,len);
+
+ /* expecting to see a digit for number */
+ if (!isdigit((int)buffer[index])) goto out;
+
+ *r->limit = atoi(&buffer[index]);
+ break;
+ }
+ }
+ out:
+ free(buffer);
+ } else {
+ fprintf(stderr,"cannot open %s\n",conf);
+ }
+ free(conf);
+}
+
+
+static int sandbox_processes(xid_t xid, char *context)