int proto_register (int tproto, char *name, char *descr, void *(*check) (), void *(*analyze) (), void *(*init) (), void *(*stat) ()) { if (PROTO_DEBUG) fprintf (fp_stderr, "proto: registering protocol[%d] (%s,%s) over %s with function (%p,%p,%p,%p)\n", ++proto_num, name, descr, proto_description (tproto), check, analyze, init, stat); struct proto *pproto = (struct proto *) MMmalloc (sizeof (struct proto), "proto_register"); pproto->next = proto_list_head; proto_list_head = pproto; /* The strdup() function returns a pointer to a new string which is a duplicate of the string s. Memory for the new string is obtained with malloc(3), and can be freed with free(3). */ pproto->name = strdup (name); pproto->descr = strdup (descr); pproto->check = check; pproto->analyze = analyze; pproto->init = init; pproto->stat = stat; pproto->tproto = tproto; // calling initialization routine if (init != NULL) pproto->init (); return 1; }
void dump_create_outdir(char * basedir) { char *buf; if (!dump_engine) return; if (threaded) pthread_mutex_lock(&dump_mutex); // store basedir to check when a new output directory is created if (log_basedir && strcmp(log_basedir, basedir) != 0) { dump_flush(TRUE); dir_counter = 0; } log_basedir = strdup(basedir); first_dump_tm.tv_sec = -1; first_dump_tm.tv_usec = -1; last_dump_tm.tv_sec = -1; last_dump_tm.tv_usec = -1; // compose the name of the directory... buf = sprintf_safe("%s/%s%02d", basedir, DUMP_DIR_BASENAME, dir_counter); if (outdir) free(outdir); outdir = MMmalloc(strlen(buf) + 1, "dump_create_outdir"); memcpy(outdir, buf, strlen(buf) + 1); if (mkdir(outdir, 0777) != 0) { fprintf(fp_stderr, "dump engine err: error creating '%s'\n", outdir); exit(1); } fprintf(fp_stdout, "(%s) Creating output dir %s\n", Timestamp(), outdir); // ... and dumping log file buf = sprintf_safe("%s/%s", outdir, DUMP_LOG_FNAME); fp_log = fopen(buf, "w"); if (fp_log == NULL) { fprintf(fp_stderr, "dump engine: error creating '%s'\n", buf); exit(1); } dir_counter++; if (threaded) pthread_mutex_unlock(&dump_mutex); }