void load_conf_from_string(char *config) { char *err = NULL; int linenum = 0, tlines, i; sds *lines; lines = sdssplitlen(config, strlen(config), "\n", 1, &tlines); for(i = 0; i < tlines; i++) { sds *argv; int argc; linenum = i+1; log_debug(">> %0.3d %s", linenum, lines[i]); lines[i] = sdstrim(lines[i], " \t\r\n"); // skip comments and blank lines if(lines[i][0] == '#' || lines[i][0] == '\0') continue; argv = sdssplitargs(lines[i], &argc); if(argv == NULL) { err = "Unbalanced quotes in configuration line"; goto loaderr; } if(argc == 0) { sdsfreesplitres(argv, argc); continue; } sdstolower(argv[0]); if(!strcasecmp(argv[0], "name") && argc == 2) { server.name = sdsdup(argv[1]); }else if(!strcasecmp(argv[0], "bind") && argc >= 2) { server.bind_addr_count = argc-1; if((argc-1) > ZR_MAX_BIND_ADDR) { err = "Too many bind address specified."; goto loaderr; } int j; for(j = 0; j < server.bind_addr_count; j++) { server.bind_arr[j].addr_str = sdsnew(argv[j+1]); server.bind_arr[j].addr.sin_family = AF_INET; server.bind_arr[j].addr.sin_addr.s_addr = inet_addr(argv[j+1]); if(server.bind_arr[j].addr.sin_addr.s_addr == INADDR_NONE) { err = sdscatprintf(sdsempty(), "Wrong binding ip address: %s", argv[j+1]); goto loaderr; } } }else if(!strcasecmp(argv[0], "port") && argc == 2) { server.port = atoi(argv[1]); if (server.port < 0 || server.port > 65535) { err = "Invalid port"; goto loaderr; } }else if(!strcasecmp(argv[0], "req-log-uds") && argc == 2) { server.req_log_uds = sdsnew(argv[1]); }else if(!strcasecmp(argv[0], "client-max") && argc == 2) { server.client_max = atoi(argv[1]); if(server.client_max < 0) { err = "Invalid server-connection-max value."; goto loaderr; } } else if (!strcasecmp(argv[0],"tcp-backlog") && argc == 2) { server.tcp_backlog = atoi(argv[1]); if (server.tcp_backlog < 0) { err = "Invalid backlog value"; goto loaderr; } /* } else if (!strcasecmp(argv[0],"rr-counter-buffer") && argc == 2) { server.tcp_backlog = atoi(argv[1]); if (server.tcp_backlog < 0) { err = "Invalid rr-counter-buffer value"; goto loaderr; } */ }else if(!strcasecmp(argv[0], "log-level") && argc == 2) { server.log_level = log_get_level_str(argv[1]); }else if(!strcasecmp(argv[0], "log-file") && argc == 2) { server.log_file = sdsdup(argv[1]); if(!strcasecmp(argv[1], "stdout")) { log_set_out(stdout); }else if(!strcasecmp(argv[1], "stderr")) { log_set_out(stderr); }else { FILE *fd; fd = fopen(argv[1], "a"); if(fd == NULL) { err = sdscatprintf(sdsempty(), "Can't open the log file: %s", strerror(errno)); goto loaderr; } log_set_out(fd); } }else if(!strcasecmp(argv[0], "zookeeper-health-uri") && argc == 2) { struct z_conn_info *zcinfo = z_parse_conn_string(argv[1]); if(zcinfo == NULL) { err = "Invalid zookeeper-health-url(Zookeeper URI) value.\n" // "Zookeeper URI must be as below.\n" // " - zoo://[USER[:PASS]@]HOST_STRING/NODE/PATH\n" // " ex) zoo://192.168.1.2:2181/test/node\n" // " ex) zoo://[email protected]:2181,192.168.1.3:2181/test/node\n" // " ex) zoo://foo:[email protected]:2181,192.168.1.3:2181/test/node\n" ""; goto loaderr; } server.z_health_conn = zcinfo; }else if(!strcasecmp(argv[0], "zookeeper-timeout") && argc == 2) { server.zoo_timeout = atoi(argv[1]); if(server.zoo_timeout < 0) { err = "Invalid zookeeper-timeout value"; goto loaderr; } }else if(!strcasecmp(argv[0], "service") && argc == 3) { if(strlen(argv[1]) > ZR_MAX_SVC_NAME) { err = sdscatprintf(sdsempty(), "Service name is too long, first argument(service name) must be less then %d.", ZR_MAX_SVC_NAME); goto loaderr; } struct z_conn_info *cinfo = z_parse_conn_string(argv[2]); if(!cinfo) { err = "Invalid zookeeper-health-url(Zookeeper URI) value.\n" // "Zookeeper URI must be as below.\n" // " - zoo://[USER[:PASS]@]HOST_STRING/NODE/PATH\n" // " ex) zoo://192.168.1.2:2181/test/node\n" // " ex) zoo://[email protected]:2181,192.168.1.3:2181/test/node\n" // " ex) zoo://foo:[email protected]:2181,192.168.1.3:2181/test/node\n" ""; goto loaderr; } int j; for(j = 0; j < server.svc_count; j++) { struct svc *tsvc = server.svc_arr[j]; if(!sdscmp(argv[1], tsvc->name)) { err = sdscatprintf(sdsempty(), "\"%s\" service name already exists.", argv[1]); goto loaderr; } } struct svc *svc = svc_alloc(argv[1], strlen(argv[1]), server.svc_count); svc->z_conn = cinfo; server.svc_arr[server.svc_count] = svc; server.svc_count++; }else { err = "Bad config directive or wrong number of arguments"; goto loaderr; } sdsfreesplitres(argv,argc); } sdsfreesplitres(lines,tlines); return; loaderr: log_eerr("CONFIG FILE ERROR."); log_eerr("Reading configureation file, at line %d", linenum); log_eerr(">> '%s'", lines[i]); log_eerr("%s", err); exit(1); }
static int fnL42801894(struct OSImageScript *imgScript, void **bootAddrBuf, void **var6) { int fdesc = 0; int imgNo; int fileSize = 0; void *loadAddr; wlibc_uprintf("load kernel start\n"); for(imgNo = 0; imgNo < imgScript->segmentSectionCount; ++imgNo) { if(imgNo != 1) { loadAddr = imgScript->images[imgNo].baseAddr; } else { loadAddr = svc_alloc(65536); } if(loadAddr == 0) { wlibc_uprintf("img file %s base addres is NULL\n", loadAddr); return -1; } fdesc = svc_open(imgScript->images[imgNo].name, "rb"); if(fdesc == 0) { wlibc_uprintf("open img file %s failed\n", imgScript->images[imgNo].name); goto fail; } fileSize = svc_filesize(fdesc); if( fileSize > imgScript->images[imgNo].maxSize ) { wlibc_uprintf( "the img file %s length %d is larger than img max size %d\n", imgScript->images[imgNo].name, fileSize, imgScript->images[imgNo].maxSize); goto fail; } svc_read(loadAddr, 1, fileSize, fdesc); svc_close(fdesc); imgScript->images[imgNo].fileLen = fileSize; if(imgNo == 1) { do_boot_linux(imgScript->images[1].baseAddr, loadAddr, fileSize); svc_free(loadAddr); } loadAddr = 0; fdesc = 0; fileSize = 0; } loadAddr = imgScript->baseAddr; if(loadAddr == 0) { wlibc_uprintf("no script could be filed\n"); } else { /* 0x42F00000 - c:\script.bin contents */ memcpy(loadAddr, (const void*)0x42F00000, imgScript->maxSize); imgScript->param776 = imgScript->maxSize; } *bootAddrBuf = imgScript->images[0].baseAddr; *var6 = imgScript->images[1].baseAddr; wlibc_uprintf("load kernel successed\n"); return 0; fail: if(fdesc != 0) { svc_close(fdesc); } wlibc_uprintf("load kernel failed\n"); return -1; }