/* * Called from the xml parser. * Here is where we begin parsing <application>... or <instance>... * or <adaptor>... */ static void createElement(XMLCDocument *document, const XMLCCharacter *name, const unsigned int length) { WOXMLEdits *config = (WOXMLEdits *)document; if (config->error != 0) /* would be nice to tell parser to stop */ return; config->errorLocation = name; if (length == 7 && strncasecmp(name, "adaptor", length) == 0) { /* do nothing; don't generate a warning */ } else if (length == 11 && strncasecmp(name, "application", length) == 0) { /* begin <application> */ if (config->current_element != NULL) { WOLog(WO_ERR,"Error parsing config: found unexpected <application> tag"); config->error = 1; return; } /* create new app settings dictionary, instance list, and set current_element to the app dictionary*/ config->current_app = st_new(8); wolist_add(config->new_apps, config->current_app); config->current_app_instances = wolist_new(8); wolist_add(config->new_app_instances, config->current_app_instances); config->current_element = config->current_app; } else if (length == 8 && strncasecmp(name, "instance", length) == 0) { /* begin <instance> */ if (config->current_element != config->current_app || config->current_app == NULL) { WOLog(WO_ERR,"Error parsing config: found unexpected <instance> tag"); config->error = 1; return; } /* create new instance settings dictionary and set current_element to point to it */ config->current_instance = st_new(8); wolist_add(config->current_app_instances, config->current_instance); config->current_element = config->current_instance; } else { /* Got something unexpected. Ignore the tag. */ char *buffer = WOMALLOC(length+1); strncpy(buffer,name,length); buffer[length] = '\0'; WOLog(WO_WARN,"Unknown tag in XML: \"%s\"",buffer); config->current_element = NULL; WOFREE(buffer); } return; }
HTTPResponse *resp_new(char *statusStr, WOInstanceHandle instHandle, WOConnection *instanceConnection) { HTTPResponse *resp; char *status = statusStr; /* * reformat the status line from * "HTTP/1.0 200 OK Apple WebObjects" to "OK Apple..." */ while (status && *status && !isspace((int)*status)) status++; while (*status && !isdigit((int)*status)) status++; if ( !(status && *status) ) { WOLog(WO_ERR,"Invalid response!"); return NULL; } resp = WOCALLOC(1,sizeof(HTTPResponse)); resp->status = atoi(status); resp->statusMsg = (char *)apple; if (strncmp(statusStr, "HTTP/1.", 7) == 0) { if (statusStr[7] == '0') resp->flags |= RESP_HTTP10; else if (statusStr[7] == '1') resp->flags |= RESP_HTTP11; } resp->headers = st_new(10); resp->instanceConnection = instanceConnection; resp->instHandle = instHandle; return resp; }
/* * common routing to add header called by both addHeader() */ inline static const char *req_AddHeader_common(HTTPRequest *req,const char *key,const char *value) { const char *customKey; const char *hdrkey; customKey = customHeaderFor(key); hdrkey = (customKey != NULL) ? customKey : key; if (req->headers == NULL) req->headers = st_new(HEADER_CNT); /* * we inspect the headers in line here to grab the content length */ if ((req->content_length == 0) && ((strcasecmp(key, CONTENT_LENGTH) == 0) || (strcasecmp(key, "content_length") == 0))) /* get content-length */ req->content_length = atol(value); #ifdef DEBUG WOLog(WO_DBG,"(req-hdr) %s: %s",key, value); #endif return hdrkey; }
void bootstrap() { process = malloc(sizeof(process_t)); process->cwd = st_new(MAX_PATH, st_enc_utf8); size_t size = 1027; int err = uv_cwd(process->cwd->value, &size); assert(err == 0); }
string* psr_file_to_string(const char* filename) { FILE* f = fopen(filename, "r"); if (!f) { fl_fatal_error("file cannot be opened: %s\n", filename); } fseek(f, 0, SEEK_END); size_t lSize = ftell(f); rewind(f); string* code = st_new(lSize + 2, st_enc_utf8); // copy the file into the buffer: size_t result = fread(code->value, 1, lSize, f); if (result != lSize) { fl_fatal_error("%s\n", "Reading error"); } // double null needed by flex/bison code->value[lSize] = '\0'; code->value[lSize + 1] = '\0'; code->used = result; code->length = st_utf8_length(code->value, 0); return code; }
strtbl *st_newWithString(const char *s) { strtbl *st = NULL; char key[MAXSTR], value[MAXSTR]; if ((s == NULL) || (*s != LEFTCURLY)) return NULL; /* * repeat over key = value pairs */ s++; while (*s != RIGHTCURLY) { s = _getstr(s, key); while (*s && isspace((int)*s)) s++; if (*s == EQUAL) s = _getstr(s+1, value); if (*key && *value) { if (st == NULL) st = st_new(0); st_add(st, key, value, STR_COPYKEY|STR_COPYVALUE); } while (*s && (isspace((int)*s) || (*s == SEMI))) s++; } return st; }
/* * Called during server init - * * the following keys can be specified in an Init line in the * obj.conf, like this: * * Init fn="WebObjects_init" config="path-to-config" \ * root="WebObjects-Doc-Root-Path" * * pb contains the "name=value" pairs from the Init line * sn = rq = NULL * */ NSAPI_PUBLIC int WebObjects_init(pblock *pb, Session *sn, Request *rq) { strtbl *dict; int i; WOLog_init(NULL, NULL, WOLogLevel[WO_DBG]); dump_pb(pb,"init.pb"); dict = st_new(10); /* * copy all the key/value pairs into our init table */ for (i=0; i < pb->hsize; i++) { struct pb_entry *entry = pb->ht[i]; while (entry != NULL) { pb_param *kvpair = entry->param; if (kvpair != NULL) { st_add(dict, kvpair->name, kvpair->value, STR_COPYKEY|STR_COPYVALUE); } entry = entry->next; } } adaptorEnabled = init_adaptor(dict)==0; if (adaptorEnabled) log_error(1,"WebObjects",NULL,NULL,"initialized"); return REQ_PROCEED; }
void* pool_realloc_fix_string(void* ptr, size_t bytes) { string* str = (string*)ptr; string* ret = st_new(bytes, st_enc_utf8); st_copy(&ret, str); pool_free(str); return ret; }
// ----------------------------------------------------------------------- struct st * st_copy(struct st *t) { if (!t) return NULL; struct st *sx = st_new(t->type, t->val, t->flo, t->str, NULL); return sx; }
/* * return a redirect response to 'path' */ HTTPResponse *resp_redirectedResponse(const char *path) { HTTPResponse *resp; resp = WOCALLOC(1,sizeof(HTTPResponse)); resp->status = 302; /* redirected */ resp->statusMsg = WOSTRDUP("OK Apple"); resp->headers = st_new(2); st_add(resp->headers, LOCATION, path, STR_COPYVALUE|STR_FREEVALUE); return resp; }
ast_t* psr_str_utf8(char* str) { st_size_t cap; string* code = st_new(cap + 2, st_enc_utf8); st_copyc(&code, str, st_enc_utf8); st_append_char(&code, 0); ast_t* root = __psr_parse(code, 0); ast_parent(root); return root; }
static strtbl *read_registry_config() { const regthing *info; strtbl *config; char value[MAX_VAL_LENGTH]; config = st_new(12); for (info=options; info->regKey != NULL; info++) { if (WOReadKeyFromConfiguration(info->regKey, value, MAX_VAL_LENGTH)) st_add(config,info->myKey,value,STR_COPYVALUE|STR_FREEVALUE); } return config; }
// ----------------------------------------------------------------------- struct st * st_arg(int type, ...) { va_list ap; struct st *stx, *s; stx = st_new(type, 0, 0, NULL, NULL); if (!stx) return NULL; va_start(ap, type); s = va_arg(ap, struct st*); while (s) { st_arg_app(stx, s); s = va_arg(ap, struct st*); } va_end(ap); return stx; }
HTTPResponse *resp_errorResponse(const char *msg, int status) { HTTPResponse *resp; char buf[12]; String *html_msg; resp = WOCALLOC(1,sizeof(HTTPResponse)); resp->status = status; resp->statusMsg = WOSTRDUP("Error WebObjects"); resp->headers = st_new(2); st_add(resp->headers, CONTENT_TYPE, DEFAULT_CONTENT, 0); html_msg = str_create(errorRespTextBegin, sizeof(errorRespTextBegin) + sizeof(errorRespTextEnd) + strlen(msg)); str_append(html_msg, msg); str_append(html_msg, errorRespTextEnd); resp->content_length = resp->content_valid = resp->content_read = html_msg->length; resp->content = html_msg->text; resp_addStringToResponse(resp, html_msg); resp->flags |= RESP_DONT_FREE_CONTENT; sprintf(buf,"%d",resp->content_length); st_add(resp->headers, CONTENT_LENGTH, buf, STR_COPYVALUE|STR_FREEVALUE); return resp; }
int main() { #ifdef PROFILE int i; #endif const char *config_url, *username, *password, *config_options; strtbl *options = NULL; int exit_status = 0; // install SIGUSR1, SIGPIPE, SIGTERM handler signal(SIGTERM, sig_handler); signal(SIGUSR1, sig_handler); signal(SIGPIPE, sig_handler); /* Provide a hook via an environment variable to define the config URL */ config_url = getenv(WO_CONFIG_URL); if (!config_url) { /* Flat file URL */ /* config_url = "file:///Local/Library/WebObjects/Configuration/WOConfig.xml"; */ /* Local wotaskd */ /* config_url = "http://localhost:1085"; */ /* Multicast URL */ config_url = CONFIG_URL; /* Actually "webobjects://239.128.14.2:1085"; */ } WOLog(WO_INFO,"<FastCGI> config url is %s", config_url); options = st_new(8); st_add(options, WOCONFIG, config_url, 0); /* * If your webserver is configured to pass these environment variables, we use them to * protect WOAdaptorInfo output. */ username = getenv(WO_ADAPTOR_INFO_USERNAME); if (username && strlen(username) != 0) { st_add(options, WOUSERNAME, username, 0); password = getenv(WO_ADAPTOR_INFO_PASSWORD); if(password && strlen(password) != 0) { st_add(options, WOPASSWORD, password, 0); } } config_options = getenv(WO_CONFIG_OPTIONS); if (config_options) st_add(options, WOOPTIONS, config_options, 0); /* * SECURITY ALERT * * To disable WOAdaptorInfo, uncomment the next line. * st_add(options, WOUSERNAME, "disabled", 0); * * To specify an WOAdaptorInfo username and password, uncomment the next two lines. * st_add(options, WOUSERNAME, "joe", 0); * st_add(options, WOPASSWORD, "secret", 0); * */ if (init_adaptor(options)) { WOLog( WO_ERR, "<FastCGI> Adaptor initialization failed."); exit(-1); } WOLog( WO_INFO,"<FastCGI> process started" ); while (!should_terminate) { HTTPRequest *req; HTTPResponse *resp = NULL; WOURLComponents wc = WOURLComponents_Initializer; const char *qs; unsigned int qs_len; char *url; const char *script_name, *path_info; const char *reqerr; WOURLError urlerr; FCGX_ParamArray hdrp_org; exit_status = FCGX_Accept(&in, &out, &err, &hdrp ); if ( exit_status < 0 ) { break; } #ifdef PROFILE for (i=0; i < 50000; i++) { #endif WOLog( WO_INFO,"<FastCGI> request accepted" ); #ifdef WIN32 _setmode(_fileno(stdout), _O_BINARY); _setmode(_fileno(stdin), _O_BINAR1Y); #endif script_name = FCGX_GetParam( CGI_SCRIPT_NAME, hdrp); path_info = FCGX_GetParam( CGI_PATH_INFO, hdrp); WOLog( WO_INFO,"<FastCGI> CGI_SCRIPT_NAME = %s", script_name ); WOLog( WO_INFO,"<FastCGI> CGI_PATH_INFO = %s", path_info ); if (script_name == NULL) { prepareAndSendErrorResponse(INV_SCRIPT, HTTP_NOT_FOUND); break; } else if (path_info == NULL) { path_info = "/"; } /* * extract WebObjects application name from URI */ url = WOMALLOC(strlen(path_info) + strlen(script_name) + 1); strcpy(url, script_name); strcat(url, path_info); WOLog(WO_INFO,"<FastCGI> new request: %s",url); urlerr = WOParseApplicationName(&wc, url); if (urlerr != WOURLOK) { const char *_urlerr; _urlerr = WOURLstrerror(urlerr); WOLog(WO_INFO,"<FastCGI> URL Parsing Error: %s", _urlerr); if (urlerr == WOURLInvalidApplicationName) { if (ac_authorizeAppListing(&wc)) { resp = WOAdaptorInfo(NULL, &wc); sendErrorResponse(resp); } else { prepareAndSendErrorResponse(_urlerr, HTTP_NOT_FOUND); } WOFREE(url); break; } prepareAndSendErrorResponse(_urlerr, HTTP_BAD_REQUEST); WOFREE(url); break; } /* * build the request... */ req = req_new( FCGX_GetParam("REQUEST_METHOD", hdrp), NULL); /* * validate the method */ reqerr = req_validateMethod(req); if (reqerr) { prepareAndSendErrorResponse(reqerr, HTTP_BAD_REQUEST); WOFREE(url); break; } /* * copy the headers. This looks wierd... all we're doing is copying * *every* environment variable into our headers. It may be beyond * the spec, but more information probably won't hurt. */ hdrp_org=hdrp; while (hdrp && *hdrp) { char *key, *value; /* copy env. line. */ key = WOSTRDUP(*hdrp); for (value = key; *value && !isspace((int)*value) && (*value != '='); value++) {} if (*value) { *value++ = '\0'; /* null terminate 'key' */ } while (*value && (isspace((int)*value) || (*value == '='))) { value++; } /* BEGIN Support for getting the client's certificate. */ if (strcmp((const char *)key, "SSL_CLIENT_CERTIFICATE") == 0 || strcmp((const char *)key, "SSL_SERVER_CERTIFICATE") == 0 ) { value = 0; WOLog(WO_INFO,"<FastCGI> DROPPING ENV VAR (DUPLICATE) = %s", key); } if (strcmp((const char *)key, "SSL_CLIENT_CERT") == 0 || strcmp((const char *)key, "SSL_SERVER_CERT") == 0) { value = make_cert_one_line(value); //WOLog(WO_INFO,"<FastCGI> PASSING %s = %s", key, value); } /* END Support for getting the client's certificate */ if (key && *key && value && *value) { /* must specify copy key and value because key translation might replace this key, and value lives in the same buffer */ req_addHeader(req, key, value, STR_COPYKEY|STR_COPYVALUE); } /* BEGIN Support for getting the client's certificate */ if (freeValueNeeded ) { free(value); freeValueNeeded=0; } /* END Support for getting the client's certificate */ WOFREE(key); hdrp++; /* next env variable */ } hdrp=hdrp_org; /* * get form data if any * assume that POSTs with content length will be reformatted to GETs later */ WOLog ( WO_INFO, "Getting request data, length: %d",req->content_length ); if (req->content_length > 0) { req_allocateContent(req, req->content_length, 1); req->getMoreContent = (req_getMoreContentCallback)readContentData; WOLog ( WO_INFO, "content_buffer_size: %d",req->content_buffer_size ); if (req->content_buffer_size == 0) { prepareAndSendErrorResponse(ALLOCATION_FAILURE, HTTP_SERVER_ERROR); WOFREE(url); break; } if (readContentData(req, req->content, req->content_buffer_size, 1) == -1) { prepareAndSendErrorResponse(WOURLstrerror(WOURLInvalidPostData), HTTP_BAD_REQUEST); WOFREE(url); break; } } /* Always get the query string */ qs = FCGX_GetParam("QUERY_STRING", hdrp); if (qs) { qs_len = strlen(qs); } else { qs_len = 0; } if (qs_len > 0) { wc.queryString.start = qs; wc.queryString.length = qs_len; WOLog(WO_INFO,"<FastCGI> new request with Query String: %s", qs); } /* * message the application & collect the response */ resp = tr_handleRequest(req, url, &wc, FCGX_GetParam(CGI_SERVER_PROTOCOL, hdrp), documentRoot()); if (resp != NULL) { sendResponse(resp); resp_free(resp); /* dump the response */ } WOFREE(url); req_free(req); #if defined(FINDLEAKS) showleaks(); #endif } #ifdef PROFILE } #endif st_free(options); WOLog( WO_INFO,"<FastCGI> process exiting" ); return exit_status; }
// ----------------------------------------------------------------------- struct st * st_float(int type, double flo) { return st_new(type, 0, flo, NULL, NULL); }
// ----------------------------------------------------------------------- struct st * st_str(int type, char *str) { return st_new(type, 0, 0, str, NULL); }
void main(int argc, char** argv) { int index = 0, numThreads, numDead = 0; int ch; SearchThread **threads; while ((ch = getopt(argc, argv, "j:i:h:s:f:p:t:D:w:n:A:bvlyqmcdu")) != EOF) switch (ch) { case 'h': hostname = optarg; break; case 's': suffix = optarg; break; case 'f': filter = optarg; break; case 'i': nameFile = optarg; break; case 'D': bindDN = optarg; break; case 'w': bindPW = optarg; break; case 'A': attrList = optarg; break; case 'p': port = atoi(optarg); break; case 'b': doBind = 1; break; case 'u': noUnBind = 1; break; case 'n': numeric = atoi(optarg); break; case 't': threadCount = atoi(optarg); break; case 'j': sampleInterval = atoi(optarg) * 1000; break; case 'v': verbose = 1; break; case 'q': quiet = 1; break; case 'l': logging = 1; break; case 'y': noDelay = 1; break; case 'm': opType = op_modify; break; case 'd': opType = op_delete; break; case 'c': opType = op_compare; break; case '?': usage(); exit(1); break; default: break; } argc -= optind; argv += optind; PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 0); ntable = nt_new(0); if (nameFile) { if (!nt_load(ntable, nameFile)) { printf("Failed to read name table\n"); exit(1); } } if (attrList) attrToReturn = string_to_list(attrList); /* a "vector" */ threads = (SearchThread **)malloc(threadCount * sizeof(SearchThread *)); while (threadCount--) { SearchThread *st; PRThread *thr; st = st_new(); thr = PR_CreateThread(PR_SYSTEM_THREAD, search_start, (void *)st, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0); st_setThread(st, thr, index+1); threads[index++] = st; } numThreads = index; printf("rsearch: %d threads launched.\n\n", numThreads); while (numThreads != numDead) { int x; PR_Sleep(PR_MillisecondsToInterval(sampleInterval)); /* now check for deadies */ for (x = 0; x < numThreads; x++) { if (!st_alive(threads[x])) { int y; PRThread *tid; printf("T%d DEAD.\n", st_getThread(threads[x], &tid)); PR_JoinThread(tid); for (y = x+1; y < numThreads; y++) threads[y-1] = threads[y]; numThreads--; numDead++; x--; } } /* print out stats */ if (!quiet) { PRUint32 total = 0; for (x = 0; x < numThreads; x++) { PRUint32 count, min, max; st_getCountMinMax(threads[x], &count, &min, &max); total += count; printf("T%d min=%4ums, max=%4ums, count = %u\n", st_getThread(threads[x], NULL), min, max, count); } if (numThreads > 1) printf("Average rate = %.2f\n", (double)total/(double)numThreads); } /* watchdogs were reset when we fetched the min/max counters */ } printf("All threads died. (?)\n"); exit(1); }
int main(int argc, char** argv) { int index = 0, numThreads, numDead = 0; int ch; int lifeTime; SearchThread **threads; PRUint32 total; double rate, val, cumrate; double sumVal; int counter; if (argc == 1) { usage(); exit(1); } while ((ch = getopt(argc, argv, "U:W:B:a:j:i:h:s:f:p:o:t:T:D:w:n:A:S:C:R:bvlyqmMcduNLHx?V")) != EOF) switch (ch) { case 'h': hostname = optarg; break; case 's': suffix = optarg; break; case 'f': filter = optarg; break; case 'i': nameFile = optarg; break; case 'B': if (optarg[0] == '?') { usage_B(); exit(1); } searchDatFile = optarg; break; case 'D': bindDN = optarg; break; case 'w': bindPW = optarg; break; case 'A': if (!attrFile) attrList = optarg; else usage(); break; case 'p': port = atoi(optarg); break; case 'S': myScope = atoi(optarg); if (myScope < LDAP_SCOPE_BASE || myScope > LDAP_SCOPE_SUBTREE) myScope = LDAP_SCOPE_SUBTREE; break; case 'C': countLimit = atoi(optarg); break; case 'b': doBind = 1; break; case 'u': noUnBind = 1; break; case 'L': setLinger = 1; break; case 'n': numeric = atoi(optarg); break; case 'o': searchTimelimit = atoi(optarg); break; case 't': threadCount = atoi(optarg); break; case 'j': sampleInterval = atoi(optarg) * 1000; break; case 'v': verbose = 1; break; case 'q': quiet = 1; break; case 'l': logging = 1; break; case 'y': noDelay = 1; break; case 'm': opType = op_modify; break; case 'M': opType = op_idxmodify; break; case 'd': opType = op_delete; break; case 'c': opType = op_compare; break; case 'N': noOp = 1; doBind = 1; /* no use w/o this */ break; case 'T': timeLimit = atoi(optarg); break; case 'V': showRunningAvg = 1; break; case 'R': reconnect = atoi(optarg); break; case 'x': useBFile = 1; break; case 'W': userPW = optarg; break; case 'U': uidFilter = optarg; break; case 'a': if (optarg[0] == '?') { usage_A(); exit(1); } if (!attrList) attrFile = optarg; else usage(); break; case '?': case 'H': default : usage(); } if ( !suffix || !filter || !bindDN || !bindPW ) { printf("rsearch: missing option\n"); usage(); } if ( timeLimit < 0 || threadCount <= 0 || sampleInterval <= 0 ) { printf("rsearch: invalid option value\n"); usage(); } argc -= optind; argv += optind; if (uidFilter && NULL == strstr(uidFilter, "%s")) { printf("rsearch: invalid UID filter - must contain %%s, eg, (uid=%%s)\n"); usage(); } PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 0); if (nameFile) { ntable = nt_new(0); if (!nt_load(ntable, nameFile)) { printf("Failed to read name table\n"); exit(1); } } attrTable = nt_new(0); if (attrFile) { if (!nt_load(attrTable , attrFile)) { printf ("Failed to read attr name table\n"); exit(1); } } sdattable = sdt_new(0); if (searchDatFile) { if (!sdt_load(sdattable, searchDatFile)) { printf("Failed to read search data table: %s\n", searchDatFile); exit(1); } } if (attrList) attrToReturn = string_to_list(attrList); /* a "vector" */ threads = (SearchThread **)malloc(threadCount * sizeof(SearchThread *)); while (threadCount--) { SearchThread *st; PRThread *thr; st = st_new(); thr = PR_CreateThread(PR_SYSTEM_THREAD, search_start, (void *)st, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0); st_setThread(st, thr, index+1); threads[index++] = st; } numThreads = index; printf("rsearch: %d threads launched.\n\n", numThreads); lifeTime = 0; counter = 0; sumVal = 0; cumrate = 0.0; while (numThreads) { int x, alive; PR_Sleep(PR_MillisecondsToInterval(sampleInterval)); counter++; lifeTime += sampleInterval/1000; /* now check for deadies */ for (x = 0; x < numThreads; x++) { alive = st_alive(threads[x]); if (alive < 1) { int limit = -1 * (searchTimelimit>timeLimit?searchTimelimit:timeLimit + 40) * 1000 / sampleInterval; int y; PRThread *tid; printf("T%d no heartbeat", st_getThread(threads[x], &tid)); if (alive <= limit) { printf(" -- Dead thread being reaped.\n"); PR_JoinThread(tid); for (y = x+1; y < numThreads; y++) threads[y-1] = threads[y]; numThreads--; numDead++; x--; } else printf(" (waiting)\n"); } } /* print out stats */ total = 0; for (x = 0; x < numThreads; x++) { PRUint32 count, min, max; st_getCountMinMax(threads[x], &count, &min, &max); total += count; if (!quiet && verbose) printf("T%d min=%4ums, max=%4ums, count = %u\n", st_getThread(threads[x], NULL), min, max, count); } rate = (double)total / (double)numThreads; val = 1000.0 * (double)total / (double)sampleInterval; cumrate += rate; if ((numThreads > 1) || (!verbose)) { if (!quiet) { char tbuf[18]; struct tm* now; time_t lt; time(<); now = localtime(<); strftime(tbuf, sizeof(tbuf), "%Y%m%d %H:%M:%S", now); if (showRunningAvg) printf("%s - Rate: %7.2f/thr (cumul rate: %7.2f/thr)\n", tbuf, rate, cumrate/(double)counter); else printf("%s - Rate: %7.2f/thr (%6.2f/sec =%7.4fms/op), " "total:%6u (%d thr)\n", tbuf, rate, val, (double)1000.0/val, total, numThreads); } } if (countLimit && (counter >= countLimit)) { printf("Thank you, and good night.\n"); exit(0); } if (timeLimit && (lifeTime >= timeLimit)) { double tmpv = (val + sumVal)/counter; if (verbose) printf("%d sec >= %d\n", lifeTime, timeLimit); printf("Final Average rate: " "%6.2f/sec = %6.4fmsec/op, total:%6u\n", tmpv, (double)1000.0/tmpv, total); exit(0); } sumVal += val; /* watchdogs were reset when we fetched the min/max counters */ } printf("All threads died. (?)\n"); exit(1); }
// ----------------------------------------------------------------------- struct st * st_int(int type, int val) { return st_new(type, val, 0, NULL, NULL); }