// set up a log context struct log_context* log_init( char const* http_server, int http_port, int sync_delay, int timeout, int max_lines, uint64_t methods, char const* log_path_salt, char const* log_path_dir ) { struct log_context* logctx = (struct log_context*)calloc( sizeof(struct log_context), 1 ); if( logctx == NULL ) { return NULL; } logctx->hostname = strdup( http_server ); logctx->log_path_salt = strdup( log_path_salt ); logctx->sync_buf = new log_sync_buf_t(); if( logctx->hostname == NULL || logctx->sync_buf == NULL || logctx->log_path_salt == NULL ) { // OOM log_free( logctx ); return NULL; } char* log_path = log_fullpath( log_path_dir, LOG_PATH_FMT, NULL ); if( log_path == NULL ) { // OOM log_free( logctx ); return NULL; } int tmpfd = -1; FILE* logfile_pipe = log_open( log_path, &tmpfd ); if( logfile_pipe == NULL ) { fprintf(stderr, "log_open(%s) failed\n", log_path ); free( log_path ); log_free( logctx ); return NULL; } logctx->logfile_pipe = logfile_pipe; logctx->logfile_path = log_path; logctx->portnum = http_port; logctx->sync_delay = sync_delay; logctx->running = 0; logctx->timeout = timeout; logctx->max_lines = max_lines; logctx->num_lines = 0; logctx->methods = methods; logctx->tmpfd = tmpfd; logctx->logfile_dir = strdup( log_path_dir ); logctx->logfile_path = log_path; pthread_rwlock_init( &logctx->lock, NULL ); sem_init( &logctx->sync_sem, 0, 0 ); sem_init( &logctx->rollover_sem, 0, 0 ); return logctx; }
int main( const int argc, const char* const* argv) { int exitCode = EXIT_FAILURE; if (-1 == openulog(basename(argv[0]), 0, LOG_LOCAL0, "-")) { (void)fprintf(stderr, "Couldn't initialize logging system\n"); } else { if (CUE_SUCCESS == CU_initialize_registry()) { CU_Suite* testSuite = CU_add_suite(__FILE__, setup, teardown); if (NULL != testSuite) { CU_ADD_TEST(testSuite, test_add_get); CU_ADD_TEST(testSuite, test_order); if (CU_basic_run_tests() == CUE_SUCCESS) exitCode = CU_get_number_of_failures(); } CU_cleanup_registry(); } /* CUnit registery allocated */ log_free(); } /* logging system initialized */ return exitCode; }
void raft_free(raft_server_t* me_) { raft_server_private_t* me = (void*)me_; log_free(me->log); free(me_); }
int main( const int argc, const char* const * argv) { int exitCode = 1; const char* progname = basename((char*) argv[0]); (void)log_init(progname); if (CUE_SUCCESS == CU_initialize_registry()) { CU_Suite* testSuite = CU_add_suite(__FILE__, setup, teardown); if (NULL != testSuite) { if (CU_ADD_TEST(testSuite, test_exe_new) && CU_ADD_TEST(testSuite, test_exe_submit) && CU_ADD_TEST(testSuite, test_exe_shutdown_empty) && CU_ADD_TEST(testSuite, test_exe_shutdown) && CU_ADD_TEST(testSuite, test_submit_while_shutdown) && CU_ADD_TEST(testSuite, test_exe_clear)) { CU_basic_set_mode(CU_BRM_VERBOSE); (void) CU_basic_run_tests(); } } exitCode = CU_get_number_of_tests_failed(); CU_cleanup_registry(); } log_free(); return exitCode; }
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) { if(dwReason == DLL_PROCESS_ATTACH) { // make sure advapi32 is loaded LoadLibrary("advapi32"); // there's a small list of processes which we don't want to inject if(is_ignored_process()) { return TRUE; } // hide our module from peb hide_module_from_peb(hModule); // obtain all protected pids int pids[MAX_PROTECTED_PIDS], length = sizeof(pids); pipe2(pids, &length, "GETPIDS"); for (int i = 0; i < length / sizeof(pids[0]); i++) { add_protected_pid(pids[i]); } // initialize file stuff file_init(); // read the config settings read_config(); g_pipe_name = g_config.pipe_name; // initialize the log file log_init(g_config.host_ip, g_config.host_port, 0); // initialize the Sleep() skipping stuff init_sleep_skip(g_config.first_process); // we skip a random given amount of milliseconds each run init_startup_time(g_config.startup_time); // disable the retaddr check if the user wants so if(g_config.retaddr_check == 0) { hook_disable_retaddr_check(); } // initialize all hooks set_hooks(); // notify analyzer.py that we've loaded char name[64]; sprintf(name, "CuckooEvent%d", GetCurrentProcessId()); HANDLE event_handle = OpenEvent(EVENT_ALL_ACCESS, FALSE, name); if(event_handle != NULL) { SetEvent(event_handle); CloseHandle(event_handle); } } else if(dwReason == DLL_PROCESS_DETACH) { log_free(); } return TRUE; }
static char* log_copy(uint32_t length, char *log) { char *buffer; log_free(log_pool.size); buffer = log_pointer(log_alloc(length)); strncpy(buffer, log, length); return buffer; }
struct log *log_new_fast(struct db *db, uint64_t log_number, struct dir *log_dir, struct dir *index_dir, struct bitmap *bitmap) { struct log *log = _log_new(db, log_number, log_dir, index_dir); if (log == NULL) { return NULL; } char *idx_file = idx_filename(log_number); struct hashdir *hdsets = hashdir_new_load(db, index_dir, idx_file); if (hdsets == NULL) { log_warn(db, "Can't find index file \"%s\".", idx_file); log_free(log); return NULL; /* log_warn(db, "Can't find index file \"%s\". Trying rebuild.", */ /* idx_file); */ /* hdsets = hashdir_new(db); */ /* struct hashdir *hdall = hashdir_new(db); */ /* _log_replay(log->reader, hdall, hdsets); */ /* hashdir_free(hdall); /\* not interested in deletions *\/ */ /* hashdir_freeze(hdsets); */ /* int r = hashdir_save(hdsets, index_dir, idx_file); */ /* if (r == -1) { */ /* log_error(db, "Can't save index file \"%s\".", idx_file); */ /* } */ } int s = 0; int i; int hpos_max = hashdir_size(hdsets); for (i=1; i < hpos_max; i++) { struct hashdir_item hi = hashdir_get(hdsets, i); if (bitmap_get(bitmap, hi.bitmap_pos) == 0) { /* add */ stddev_add(&log->used_size, hi.size); } else { /* delete */ int r = hashdir_del(hdsets, i); if (r != -1) { s += hashdir_del_last(hdsets); /* Visit this element once more. */ i--; } hpos_max--; } } log->hashdir = hdsets; if (s > 4) { int r = hashdir_save(log->hashdir, log->index_dir, idx_filename(log->log_number)); if (r == -1) { log_warn(log->db, "Unable to save index for " "log %llx.", (unsigned long long)log->log_number); } } return log; }
static void free_server_data() { log_free(data.log); if (NULL != data.config.servers) { free(data.config.servers); data.config.servers = NULL; } }
int main(int argc, char **argv) { struct sigaction sig_stop; struct sigaction sig_time; _main = main_init(argc, argv); _log = log_init(); _main->conf = conf_init(argc, argv); _main->work = work_init(); _main->tcp = tcp_init(); _main->node = node_init(); _main->mime = mime_init(); /* Check configuration */ conf_print(); /* Catch SIG INT */ unix_signal(&sig_stop, &sig_time); /* Fork daemon */ unix_fork(log_console(_log)); /* Increase limits */ unix_limits(_main->conf->cores, CONF_EPOLL_MAX_EVENTS); /* Load mime types */ mime_load(); mime_hash(); /* Prepare TCP daemon */ tcp_start(); /* Drop privileges */ unix_dropuid0(); /* Start worker threads */ work_start(); /* Stop worker threads */ work_stop(); /* Stop TCP daemon */ tcp_stop(); mime_free(); node_free(); tcp_free(); work_free(); conf_free(); log_free(_log); main_free(); return 0; }
/** * Clean up the srv instance. */ void TearDown( ) { if( srv != NULL ) { server_free( srv ); } log_free( ); status_counter_free( ); }
void index_free(struct index *idx) { _index_flush(idx); pthread_attr_destroy(&idx->attr); log_free(idx->log); close(idx->db_rfd); sst_free(idx->sst); free(idx->park); free(idx); }
/** Allocate a logger. * Create a new instance for a logging interface * @param logpath optional path to logfile * @param program name of the program, used to build logfile filename * @param levelname optional loglevel to use * @return new instance on success, NULL otherwise */ log_t * log_alloc (const char *logpath, const char *program, const char *levelname) /*{{{*/ { log_t *l; char *ptr; bool_t st; if (l = (log_t *) malloc (sizeof (log_t))) { l -> logfd = -1; l -> slprio = -1; l -> logpath = NULL; l -> program = NULL; gethostname (l -> hostname, sizeof (l -> hostname) - 1); l -> hostname[sizeof (l -> hostname) - 1] = '\0'; if (ptr = strchr (l -> hostname, '.')) *ptr = '\0'; l -> fname[0] = '\0'; l -> level = LV_ERROR; l -> use = 0; l -> last = 0; l -> lastday = -1; l -> diff = 0; l -> lfp = NULL; l -> idc = NULL; l -> slactive = false; l -> obuf = NULL; l -> collect = NULL; l -> clevel = LV_DEBUG; l -> suspend = NULL; if (levelname) st = log_level_set (l, levelname); else st = true; if (st) { # ifdef WIN32 st = (logpath && *logpath) ? log_path_set (l, logpath) : log_path_default (l); # else /* WIN32 */ st = (logpath && (*logpath == '/')) ? log_path_set (l, logpath) : log_path_default (l); # endif /* WIN32 */ } if (st && program) { const char *cptr; if (cptr = strrchr (program, PATH_SEP)) ++cptr; else cptr = program; if (! (l -> program = strdup (cptr))) st = false; } if (! st) l = log_free (l); } return l; }/*}}}*/
/** * Waits for a termination signal and then stops a downstream LDM-7. * * @param[in] arg Pointer to the downstream LDM-7 to be stopped upon receiving * a termination signal. */ static void* waitForTermSig( void* const arg) { int sig; (void)sigwait(getTermSigSet(), &sig); if (down7_stop((Down7*)arg)) log_log(LOG_ERR); log_free(); return NULL; }
/* Re-allocate memory */ void *memdbg_realloc(void *ptr, size_t size, char *filename, int line_nr) { void *result; if (ptr != NULL) { log_free(ptr, filename, line_nr); } if ((result = realloc(ptr, size)) != NULL) { log_alloc(result, size, filename, line_nr); } return result; }
static void cleanup_logging(system_data_t *sysdata) { assert(sysdata); assert(sysdata->logging); // normally before freeing the log, you would set it in direct mode to // ensure that it flushes any leftover entries out... but that would // already have been done. log_free(sysdata->logging); free(sysdata->logging); sysdata->logging = NULL; }
void nonfatal(char *p, ...) { va_list ap; fprintf(stderr, "ERROR: "); va_start(ap, p); vfprintf(stderr, p, ap); va_end(ap); fputc('\n', stderr); if (logctx) { log_free(logctx); logctx = NULL; } }
/*}}}*/ } priv_t; static char * xfree (char *s) /*{{{*/ { if (s) free (s); return NULL; }/*}}}*/ static bool_t xcopy (char **buf, const char *str) /*{{{*/ { if (*buf) free (*buf); *buf = str ? strdup (str) : NULL; return (! str) || *buf ? true : false; }/*}}}*/ static void priv_clear (priv_t *p) /*{{{*/ { if (p) { p -> x_agn = 0; p -> from = xfree (p -> from); p -> receiver = charc_free_all (p -> receiver); p -> prev = NULL; p -> info = xfree (p -> info); } }/*}}}*/ static priv_t * priv_free (priv_t *p) /*{{{*/ { if (p) { priv_clear (p); if (p -> lg) log_free (p -> lg); if (p -> cfg) cfg_free (p -> cfg); free (p); } return NULL; }/*}}}*/
void modalfatalbox(char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); va_start(ap, p); vfprintf(stderr, p, ap); va_end(ap); fputc('\n', stderr); if (logctx) { log_free(logctx); logctx = NULL; } cleanup_exit(1); }
void connection_fatal(void *frontend, char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); va_start(ap, p); vfprintf(stderr, p, ap); va_end(ap); fputc('\n', stderr); if (logctx) { log_free(logctx); logctx = NULL; } cleanup_exit(1); }
void nonfatal(char *p, ...) { struct termios cf; va_list ap; premsg(&cf); fprintf(stderr, "ERROR: "); va_start(ap, p); vfprintf(stderr, p, ap); va_end(ap); fputc('\n', stderr); postmsg(&cf); if (logctx) { log_free(logctx); logctx = NULL; } }
/** Remove and free the log entry <b>victim</b> from the linked-list * logfiles (it is probably present, but it might not be due to thread * racing issues). After this function is called, the caller shouldn't * refer to <b>victim</b> anymore. * * Long-term, we need to do something about races in the log subsystem * in general. See bug 222 for more details. */ static void delete_log(logfile_t *victim) { logfile_t *tmpl; if (victim == logfiles) logfiles = victim->next; else { for (tmpl = logfiles; tmpl && tmpl->next != victim; tmpl=tmpl->next) ; // tor_assert(tmpl); // tor_assert(tmpl->next == victim); if (!tmpl) return; tmpl->next = victim->next; } log_free(victim); }
VOID OnUnload(IN PDRIVER_OBJECT DriverObject) { UNICODE_STRING linkname; free_packet(); RtlInitUnicodeString(&linkname, L"\\??\\ip_fw"); IoDeleteSymbolicLink(&linkname); IoDeleteDevice(g_devcontrol); pfhook_free(); module_ipfw->modevent(g_driver_object, MOD_UNLOAD, NULL); iflist_free(); log_free(); }
void modalfatalbox(char *p, ...) { struct termios cf; va_list ap; premsg(&cf); fprintf(stderr, "FATAL ERROR: "); va_start(ap, p); vfprintf(stderr, p, ap); va_end(ap); fputc('\n', stderr); postmsg(&cf); if (logctx) { log_free(logctx); logctx = NULL; } cleanup_exit(1); }
void fatalbox(char *p, ...) { va_list ap; char *stuff, morestuff[100]; va_start(ap, p); stuff = dupvprintf(p, ap); va_end(ap); sprintf(morestuff, "%.70s Fatal Error", appname); MessageBox(GetParentHwnd(), stuff, morestuff, MB_ICONERROR | MB_OK); sfree(stuff); if (logctx) { log_free(logctx); logctx = NULL; } cleanup_exit(1); }
void connection_fatal(void *frontend, const char *p, ...) { struct termios cf; va_list ap; premsg(&cf); fprintf(stderr, "FATAL ERROR: "); va_start(ap, p); vfprintf(stderr, p, ap); va_end(ap); fputc('\n', stderr); postmsg(&cf); if (logctx) { log_free(logctx); logctx = NULL; } cleanup_exit(1); }
/** * Starts a receiver on the current thread. Called by `pthread_create()`. * * @param[in] arg Pointer to receiver object. * @retval &0 Success. */ static void* receiver_start( void* const arg) { Receiver* const receiver = (Receiver*)arg; static int status; status = down7_start(receiver->down7); CU_ASSERT_EQUAL(status, LDM7_SHUTDOWN); // setDoneCondition(); // Because at end of thread: done ? log_clear() : log_log(LOG_ERR); log_free(); return &status; }
/* ARGSUSED */ static int log_close(queue_t *q, int flag, cred_t *cr) { log_t *lp = (log_t *)q->q_ptr; qprocsoff(q); lp->log_inuse = 0; log_update(lp, NULL, 0, NULL); freemsg(lp->log_data); lp->log_data = NULL; if (lp->log_major == LOG_CONSMIN) log_free(lp); q->q_ptr = NULL; WR(q)->q_ptr = NULL; return (0); }
/** Close all open log files, and free other static memory. */ void logs_free_all(void) { logfile_t *victim, *next; LOCK_LOGS(); next = logfiles; logfiles = NULL; UNLOCK_LOGS(); while (next) { victim = next; next = next->next; close_log(victim); log_free(victim); } tor_free(appname); /* We _could_ destroy the log mutex here, but that would screw up any logs * that happened between here and the end of execution. */ }
void DestroySegmentList(Segments *segments) { #if !SLIM segments->data=UnmapFile(segments->data); #else segments->fd=SlimUnmapFile(segments->fd); #ifndef LIBROUTINO log_free(segments->cache); #endif DeleteSegmentCache(segments->cache); #endif free(segments); }
void server_free(server *s) { int i; /* shutdown worker threads */ for(i=0; i<s->cfg->workers; i++) { worker_free(s->w[i]); } /* free */ event_del(s->signal); event_free(s->signal); event_base_free(s->base); close(s->fd); free(s->w); conf_free(s->cfg); log_free(s->log); free(s); }