/** * \return the const char-Value, which in the selected group and value */ const char* config::getChar(const char* ch_group, const char* value){ group=conf_get_group(&conf,ch_group); if(group!=NULL){ return group_get_value(group, value); }else{ return NULL; } }
/** * Set the data which is in the selected group and value */ void config::setDouble(const char* ch_group, const char* value, double data){ group=conf_get_group(&conf,ch_group); char buffer[16]; sprintf(buffer,"%lf", data); group_set_value(group, value, buffer); fp = fopen(myfilename, "w"); conf_write(&conf, fp); eprintf("Configuration saved\n"); fclose(fp); }
/** * \return the double-Value, which in the selected group and value */ double config::getDouble(const char* ch_group, const char* value){ float returnval; group=conf_get_group(&conf,ch_group); if(group!=NULL){ if (1!=sscanf(group_get_value(group, value), "%f", &returnval)) { return 0.0; }else{ return returnval; } }else{ return 0.0; } }
/** * \return the Integer-Value, which in the selected group and value */ int config::getInt(const char* ch_group, const char* value){ int returnval; group=conf_get_group(&conf,ch_group); if(group!=NULL){ if (1!=sscanf(group_get_value(group, value), "%d", &returnval)) { return 0; }else{ return returnval; } }else{ return 0; } }
int main(int argc, char *argv[]) { CREW crew; int i; int count = 0; int res; BOOLEAN result; char ** keys; void * statusp; C = new_conf(); parse_cmdline_cfg(C, argc, argv); parse_cfgfile(C); parse_cmdline(C, argc, argv); RUNNER R = new_runner(conf_get_user(C), conf_get_group(C)); runas(R); runner_destroy(R); sigmasker(); if (is_daemon(C)) { res = fork(); if (res == -1 ){ // ERRROR NOTIFY(FATAL, "%s: [error] unable to run in the background\n", program_name); } else if (res == 0) { // CHILD PID P = new_pid(conf_get_pidfile(C)); HASH H = conf_get_items(C); count = conf_get_count(C); keys = hash_get_keys_delim(H, ':'); if ((crew = new_crew(count, count, FALSE)) == NULL) { NOTIFY(FATAL, "%s: [error] unable to allocate memory for %d log files", program_name, count); } set_pid(P, getpid()); pid_destroy(P); for (i = 0; i < count && crew_get_shutdown(crew) != TRUE; i++) { FIDO F = new_fido(C, keys[i]); result = crew_add(crew, (void*)start, F); if (result == FALSE) { NOTIFY(FATAL, "%s: [error] unable to spawn additional threads", program_name); } } crew_join(crew, TRUE, &statusp); conf_destroy(C); } else { // PARENT } } else { HASH H = conf_get_items(C); count = conf_get_count(C); keys = hash_get_keys_delim(H, ':'); if ((crew = new_crew(count, count, FALSE)) == NULL) { NOTIFY(FATAL, "%s: [error] unable to allocate memory for %d log files", program_name, count); } for (i = 0; i < count && crew_get_shutdown(crew) != TRUE; i++) { FIDO F = new_fido(C, keys[i]); result = crew_add(crew, (void*)start, F); } crew_join(crew, TRUE, &statusp); conf_destroy(C); } exit(EXIT_SUCCESS); } /* end of int main **/