static void mysection_mycategory_properties_get(struct ctx_mysection *cm, s64 mysection_start) { void *string_property="not found"; u32 integer_property=0; s64 line_start=mysection_start; while(1){ if((u64)line_start>=cm->c.sz){ POUTC("no more mycategory properties:line start not in file\n"); break; } s64 line_end=line_end_reach(&cm->c,line_start); s64 key_start=blanks_skip(&cm->c,line_start,line_end); //finished:beginning of next section reached ("[key]") if(*(u8*)(cm->c.m+key_start)=='[') break; s64 val_start=key_skip_to_val(&cm->c,key_start,line_end); if(val_start==KEY_SKIP_TO_VAL_NO_VAL){ POUTC("no value\n"); }else{ if(IS_KEY(STRING_PROPERTY)) string_property=string_property_get(cm,val_start,line_end); else if(IS_KEY(INTEGER_PROPERTY)) integer_property=integer_property_get(cm,val_start,line_end); //add more properties in mycategory here } line_start=line_end+1; } POUT("CONF:string_property=%s integer_property=%d\n",string_property, integer_property); }
static void dout(struct dirent64 *d) { POUT("%20lu %20ld %2u ",d->ino,d->off,d->type); s64 j=depth; while(j--) POUTC(" "); POUT("%s\n",d->name); }
static s8 match(struct ctx_mysection *cm,s64 mysection_start) { //XXX:in the meantime we match all the time (void)cm;(void)mysection_start; POUTC("unimplemented->we always match the first mysection\n"); return MATCH; }
static void preclone_cnx_do(void) { preclone_cnx_get(); POUTC("PRE-CLONE:DOING SOME WORK!\n"); l r; do r=close(0); while(r==-EINTR); do r=close(1); while(r==-EINTR); if(preclone_runs) if(!--preclone_runs) exit(0);//time to die atomic_u8_set(preclones_states+preclone_slot,PRECLONE_AVAILABLE); }
static s64 mysection_lookup(struct ctx_mysection *cm) { s64 mysection_start=0; while(1){ mysection_start=next(cm,mysection_start); if(mysection_start==NO_MORE_MYSECTIONS){ POUTC("no matching mysection was found\n"); return LOOKUP_NOT_FOUND; } s8 r=match(cm,mysection_start); if(r==MATCH){ POUTC("a matching mysection was found\n"); return mysection_start; } if(r==MATCH_ERR){ return LOOKUP_ERR; } } }
static void usage(void) { POUTC("-inet <x.x.x.x IPv4 address to listen to>\n" "-port <TCP port to listen to>\n" "-psmax <max number of non precloned processes\n" " default in 0, max is 65536>\n" "-preclones <number of precloned processes\n" " default is 0, max is 65535>\n" " -runs <number of runs a preclones does before dying\n" " default is infinite,max is 65535>\n" "-allows <coma separated list of IPv4 adresses, x0.x0.x0.x0,x1.x1.x1.x1...\n" " default is all ipv4 addresses accepted>\n" "-help display this text\n"); }
//****************************************************************************** //parse section properties static void *string_property_get(struct ctx_mysection *cm,s64 val_start, s64 line_end) { POUTC("string property found\n"); void *r="not valid value"; s64 val_end=non_blanks_skip(&cm->c,val_start,line_end); if((val_end-val_start)==cs_n("value0")&&!strncmp(cm->c.m+val_start,"value0", val_end-val_start)) r="value0"; else if((val_end-val_start)==cs_n("value1")&&!strncmp(cm->c.m+val_start, "value1",val_end-val_start)) r="value1"; return r; }
static s8 file_close(struct ctx *c) { s8 r0=CONF_INI_OK; l r=munmap(c->m,c->sz); if(ISERR(r)){ PERR("file:error(%ld):unable to munmap conf file\n",r); r0=CONF_INI_ERR;goto exit; } do r=close(c->fd); while(r==-EINTR); if(ISERR(r)){ PERR("file:error(%ld):closing conf file gone wrong\n",r); r0=CONF_INI_ERR;goto exit; } POUTC("file:conf file unmapped and closed\n"); exit: return r0; }
static s32 integer_property_get(struct ctx_mysection *cm,s64 val_start, s64 line_end) { POUTC("integer property found\n"); s32 r0=0; s64 val_end=non_blanks_skip(&cm->c,val_start,line_end); u32 integer; u8 r1=dec2u32_blk(&integer,cm->c.m+val_start,cm->c.m+val_end-1); if(!r1){ PERRC("integer not a valid number\n"); goto exit; } if(integer>0x7fffffff){ PERR("integer(%u) above max(%u)\n",integer,0x7fffffff); goto exit; } r0=(s32)integer; exit: return r0; }
static void clone_cnx_do(void) { POUTC("CLONE:DOING SOME WORK!\n"); l r; do r=close(cnx_sock); while(r==-EINTR); }