int main(void){ int fd; init_users(); numberOfUsers=51; printf("%d\n",create_user(5,"HELLBOY")); fd=open_log(21,WRITE); write_log(fd,"Hello guys"); close_log(fd); fd=open_log(21,READ); read_log(fd); close_log(fd); return 0; }
int RegisterRobboTotalBases() { char DIR[1024]; Send("info string Registering TotalBases, please wait...\n"); #ifdef Log if (WriteLog) { log_file = fopen(log_filename, "a"); fprintf(log_file, "info string Registering TotalBases, please wait...\n"); close_log(); } #endif DeRegisterRobboTotalBases(); strcpy(TotalBaseDir, TotalDir); sprintf(DIR, "%s", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/3", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/4", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/5", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/6", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/51", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/42", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/33", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/Z", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/345Z", TotalBaseDir); GetTotalBase(DIR); sprintf(DIR, "%s/6Z", TotalBaseDir); GetTotalBase(DIR); Send("info string " "%d TotalBases registered\n", NumTotalBases); #ifdef Log if (WriteLog) { log_file = fopen(log_filename, "a"); fprintf(log_file, "info string " "%d TotalBases registered\n", NumTotalBases); close_log(); } #endif TotalBasesLoaded = true; return true; }
/* leave pluto, with status. * Once child is launched, parent must not exit this way because * the lock would be released. * * 0 OK * 1 general discomfort * 10 lock file exists */ void exit_pluto(int status) { reset_globals(); /* needed because we may be called in odd state */ free_preshared_secrets(); free_remembered_public_keys(); delete_every_connection(); /* free memory allocated by initialization routines. Please don't forget to do this. */ #ifdef HAVE_THREADS free_crl_fetch(); /* free chain of crl fetch requests */ #endif #ifdef HAVE_OCSP free_ocsp_fetch(); /* free chain of ocsp fetch requests */ #endif free_authcerts(); /* free chain of X.509 authority certificates */ free_crls(); /* free chain of X.509 CRLs */ free_acerts(); /* free chain of X.509 attribute certificates */ free_ocsp(); /* free ocsp cache */ free_ifaces(); /* free interface list from memory */ stop_adns(); /* Stop async DNS process (if running) */ free_md_pool(); /* free the md pool */ delete_lock(); /* delete any lock files */ #ifdef LEAK_DETECTIVE report_leaks(); /* report memory leaks now, after all free()s */ #endif /* LEAK_DETECTIVE */ close_log(); /* close the logfiles */ exit(status); /* exit, with our error code */ }
int main(int argc, const char *argv[]) { int i; if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log_monospace(); if (argc < 2) { for (i = 1; i < NUM_TESTS; i++) { log_printf("# t%d\n\n", i); all_tests[i](); log_printf("\n"); } } else { i = atoi(argv[1]); if (i > 0 && i < NUM_TESTS) { all_tests[i](); } } close_log(true); if (error) { exit(EXIT_FAILURE); } return 0; }
int main(int argc, char **argv) { int i; if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log_monospace(); log_printf("%-36s %-6s %8s %8s %8s %8s\n", "name", "flags", "ctime", "mtime", "atime", "size"); log_printf( "------------------------------------ " "------ " "-------- " "-------- " "-------- " "--------\n"); if (argc == 1) { ALLEGRO_FS_ENTRY *entry = al_create_fs_entry("data"); print_entry(entry); al_destroy_fs_entry(entry); } for (i = 1; i < argc; i++) { ALLEGRO_FS_ENTRY *entry = al_create_fs_entry(argv[i]); print_entry(entry); al_destroy_fs_entry(entry); } close_log(true); return 0; }
/* * Print error message and exit program. */ void fatal(unsigned int errnum, const char *fmt,...) { va_list args; list *l; session *s; va_start(args, fmt); fprintf(stderr, "imapfilter: "); vfprintf(stderr, fmt, args); va_end(args); if (logfp) { va_start(args, fmt); fprintf(logfp, "%s: ", log_time()); vfprintf(logfp, fmt, args); fflush(logfp); va_end(args); } for (l = sessions; l; l = l->next) { s = l->data; close_connection(s); } close_log(); close_debug(); exit(errnum); }
void acid_reload(const char *reason) { close_log(); init_log() ; info_log("Reload: %s\n",reason) ; read_user_data(); }
void log_rotate() { static char from[256]; static char to[256]; memset(from,0,256); memset(to,0,256); int i = LOG_ROTATE_NUMBER; while(i){ snprintf(from, 256, "%s.%d", DEBUG_LOG_FILE, i - 1); snprintf(to, 256, "%s.%d", DEBUG_LOG_FILE, i); rename(from, to); i--; } #ifdef __THREAD_SAFE__ //pthread_mutex_lock(&l_mutex); #endif close_log(); rename(DEBUG_LOG_FILE, from); open_log(); #ifdef __THREAD_SAFE__ //pthread_mutex_unlock(&l_mutex); #endif }
int main(int argc, char **argv) { int ret = EXIT_FAILURE; banner(); //verbose++; if (!parse_options(argc, argv)) return ret; check_root(); if (dump) { efivar_bootloader_dump(); printf("\n"); return EXIT_SUCCESS; } init_log(); /* insure current_version is set */ if (current_version == -1) current_version = read_version_from_subvol_file(""); ret = do_update_bootloader_pref(); close_log(ret, current_version, 0, log_bootloader_pref); return ret; }
int MyMultiPV(typePos *Position, int depth) { int Cnt, cnt, best_value, move_is_check, new_depth, v; typeRootMoveList *p, *q; typeDynamic *Pos0 = Position->Dyn; uint32 move; int cpu, rp; int extend, LMR, value; int to; int i, j, x, moveno; int Alpha = -ValueMate, Target, Delta, Alpha2, Lower; int GoodMoves = 0; uint64 Nodes, NodesStore, nodes, y; if (depth < 14) for (i = 0; i < 0x100; i++) MPV[i].move = MPV[i].Value = 0; if (DoOutput && DepthInfo) { Send("info depth %d\n", depth >> 1); #ifdef Log if (WriteLog) { log_file = fopen(log_filename, "a"); fprintf(log_file, "info depth %d\n", depth >> 1); close_log(); } #endif }
/* leave pluto, with status. * Once child is launched, parent must not exit this way because * the lock would be released. * * 0 OK * 1 general discomfort * 10 lock file exists */ void exit_pluto(int status) { reset_globals(); /* needed because we may be called in odd state */ free_preshared_secrets(); free_remembered_public_keys(); close_ha_iface(); delete_every_connection(); whack_attribute_finalize(); /* free in-memory pools */ fetch_finalize(); /* stop fetching thread */ free_crl_fetch(); /* free chain of crl fetch requests */ free_ocsp_fetch(); /* free chain of ocsp fetch requests */ free_authcerts(); /* free chain of X.509 authority certificates */ free_crls(); /* free chain of X.509 CRLs */ free_ca_infos(); /* free chain of X.509 CA information records */ free_ocsp(); /* free ocsp cache */ free_ifaces(); ac_finalize(); /* free X.509 attribute certificates */ scx_finalize(); /* finalize and unload PKCS #11 module */ stop_adns(); free_md_pool(); free_crypto(); free_myid(); /* free myids */ free_events(); /* free remaining events */ free_vendorid(); /* free all vendor id records */ free_builder(); delete_lock(); options->destroy(options); pluto_deinit(); lib->plugins->unload(lib->plugins); libhydra_deinit(); library_deinit(); close_log(); exit(status); }
/*! @brief Executed automaticaly at exit * * This function is executed whenever the program finished, so * its good to do some finalization code here. */ void f_atexit(void) { close_network(); fflush(stdout); write_log_fmt("Closing app\n"); close_log(); }
int main(int argc, TCHAR* argv[], TCHAR* envp[]) { HANDLE hProcess; //取当前进程的句柄 hProcess=GetCurrentProcess(); //设置当前进程的优先级 //REALTIME_PRIORITY_CLASS--指示该进程拥有可用的最高优先级。 if(!SetPriorityClass(hProcess,REALTIME_PRIORITY_CLASS)){ return 1; } // create the service-object CNetService serv; // RegisterService() checks the parameterlist for predefined switches // (such as -d or -i etc.; see NTService.h for possible switches) and // starts the services functionality. // You can use the return value from "RegisterService()" // as your exit-code. //2012-7-17 日志记录 logIsEnabled = __false;//__true为启动日志记录功能 open_log(); serv.RegisterService(argc, argv); close_log();//2012-7-17 关闭日志 return 1; }
int main(void) { if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log_monospace(); display = al_create_display(WIDTH, HEIGHT); if (!display) { abort_example("al_create_display failed\n"); } al_clear_to_color(al_map_rgb_f(0, 0, 0)); al_flip_display(); if (!al_install_keyboard()) { abort_example("al_install_keyboard failed\n"); } event_queue = al_create_event_queue(); if (!event_queue) { abort_example("al_create_event_queue failed\n"); } al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_display_event_source(display)); main_loop(); close_log(false); return 0; }
/** * SIGINT handler for main process */ void main_int_handler(int arg) { // Send SIGINT to threads, so they can close file descriptors pthread_kill(t_id[0], SIGINT); pthread_kill(t_id[1], SIGINT); close_log(); exit(0); }
int probe_modules_main(int argc, char *argv[]) { enum media_bus bus = BUS_ANY; char *module = NULL; char options[500] = ""; if (argc > 1) { if (streq(argv[1], "--usb")) { bus = BUS_USB; } else if (!ptr_begins_static_str(argv[1], "--")) { int i; module = argv[1]; for (i = 2; i < argc; i++) { strcat(options, argv[i]); strcat(options, " "); } } } open_log(); init_modules_insmoding(); if (module) { my_modprobe(module, ANY_DRIVER_TYPE, options); } else { find_media(bus); } close_log(); return 0; }
int main(void) { int i; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_install_keyboard(); open_log(); display = al_create_display(640, 100); if (!display) { abort_example("Could not create display.\n"); } if (!al_install_audio()) { abort_example("Could not init sound.\n"); } al_reserve_samples(N); al_set_mixer_postprocess_callback(al_get_default_mixer(), update_waveform, NULL); mainloop(); close_log(false); for (i = 0; i < N; i++) { al_destroy_audio_stream(stream[i]); } al_uninstall_audio(); return 0; }
int MyRootNode(typePos *Position, int Alpha, int Beta, int depth) { int cpu, rp; int Cnt, origAlpha, best_value, cnt, move_is_check, new_depth, v; typeRootMoveList *p, *q; typeDynamic *Pos0 = Position->Dyn; uint32 move; int extend, LMR; int to, value; uint64 Nodes, NodesStore, nodes; if (Beta > ValueMate) Beta = ValueMate; if (Alpha < -ValueMate) Alpha = -ValueMate; if (DoOutput && DepthInfo) { Send("info depth %d\n", depth >> 1); #ifdef Log if (WriteLog) { log_file = fopen(log_filename, "a"); fprintf(log_file, "info depth %d\n", depth >> 1); close_log(); } #endif }
void log_end_multiline(void) { assert(multiline != -1); multiline = -1; close_log(); }
int main(int argc, char *argv[]) { log_t *log; log = open_log(_T("-"), _T("json")); if(log == NULL) { puts("Failed."); } open_section(log, _T("compile")); open_item(log); add_value(log, _T("date"), _T(__DATE__)); add_value(log, _T("time"), _T(__TIME__)); close_item(log); open_item(log); add_value(log, _T("file"), _T(__FILE__)); add_value(log, _T("timestamp"), _T(__TIMESTAMP__)); close_item(log); close_section(log); open_section(log, _T("test")); open_item(log); add_value(log, _T("test"), _T("field")); close_item(log); close_section(log); close_log(log); return 0; }
static void on_sigterm(int signo) { log("Terminating: SIGTERM\n"); close_log(); exit(0); }
int main(int argc, char **argv) { // Register signal handler signal(SIGINT, main_int_handler); args = parse_args(argc, argv); // Create file for logging open_log(args.log); // Create threads for listening/sending int s1 = pthread_create(&(t_id[0]), NULL, &tunnel_6in4, NULL); int s2 = pthread_create(&(t_id[1]), NULL, &tunnel_4in6, NULL); if (s1 || s2) { perror("ERROR: Create thread"); exit(2); } // Wait for threads to finish pthread_join(t_id[0], NULL); pthread_join(t_id[1], NULL); // Close file for logging close_log(); return 0; }
/* * do_log: open or close a logfile * flag - 1 if the logfile should be opened * 0 if the logfile should be closed * logfile - The name of the logfile (only needed if flag == 1) * fp - A pointer to a (FILE *) which gets the result of fopen(). * Will be set to NULL if the file is not open (due to * error or flag == 0) */ FILE * do_log (int flag, const char *logfile, FILE **fp) { if (flag) return open_log(logfile, fp); else return close_log(fp); }
printf_arglist_function1(void log_add, logtype_t, typ, char *, format) { va_list argp; char *leader = NULL; char *xlated_fmt = gettext(format); char linebuf[STR_SIZE]; size_t n; static gboolean in_log_add = 0; /* avoid recursion */ if (in_log_add) return; /* format error message */ if((int)typ <= (int)L_BOGUS || (int)typ > (int)L_MARKER) typ = L_BOGUS; if(multiline > 0) { leader = stralloc(" "); /* continuation line */ } else { leader = vstralloc(logtype_str[(int)typ], " ", get_pname(), " ", NULL); } arglist_start(argp, format); /* use sizeof(linebuf)-2 to save space for a trailing newline */ g_vsnprintf(linebuf, SIZEOF(linebuf)-2, xlated_fmt, argp); /* -1 to allow for '\n' */ arglist_end(argp); /* avoid recursive call from error() */ in_log_add = 1; /* append message to the log file */ if(multiline == -1) open_log(); if (full_write(logfd, leader, strlen(leader)) < strlen(leader)) { error(_("log file write error: %s"), strerror(errno)); /*NOTREACHED*/ } amfree(leader); /* add a newline if necessary */ n = strlen(linebuf); if(n == 0 || linebuf[n-1] != '\n') linebuf[n++] = '\n'; linebuf[n] = '\0'; if (full_write(logfd, linebuf, n) < n) { error(_("log file write error: %s"), strerror(errno)); /*NOTREACHED*/ } if(multiline != -1) multiline++; else close_log(); in_log_add = 0; }
int main(int argc, char * argv[]) { ALLEGRO_CONFIG *config; ALLEGRO_EVENT event; unsigned buffer_count; unsigned samples; const char *s; initialize(); if (argc < 2) { log_printf("This example needs to be run from the command line.\nUsage: %s {audio_files}\n", argv[0]); goto done; } buffer_count = 0; samples = 0; config = al_load_config_file("ex_stream_seek.cfg"); if (config) { if ((s = al_get_config_value(config, "", "buffer_count"))) { buffer_count = atoi(s); } if ((s = al_get_config_value(config, "", "samples"))) { samples = atoi(s); } al_destroy_config(config); } if (buffer_count == 0) { buffer_count = 4; } if (samples == 0) { samples = 1024; } stream_filename = argv[1]; music_stream = al_load_audio_stream(stream_filename, buffer_count, samples); if (!music_stream) { abort_example("Stream error!\n"); } loop_start = 0.0; loop_end = al_get_audio_stream_length_secs(music_stream); al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end); al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer()); al_start_timer(timer); while (!exiting) { al_wait_for_event(queue, &event); event_handler(&event); } done: myexit(); al_destroy_display(display); close_log(true); return 0; }
int main(int argc, char **argv) { ALLEGRO_EVENT_SOURCE fake_src; ALLEGRO_EVENT_QUEUE *queue; ALLEGRO_EVENT fake_keydown_event, fake_joystick_event; ALLEGRO_EVENT event; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log(); /* register our 'fake' event source with the queue */ al_init_user_event_source(&fake_src); queue = al_create_event_queue(); al_register_event_source(queue, &fake_src); /* fake a joystick event */ fake_joystick_event.any.type = ALLEGRO_EVENT_JOYSTICK_AXIS; fake_joystick_event.joystick.stick = 1; fake_joystick_event.joystick.axis = 0; fake_joystick_event.joystick.pos = 0.5; al_emit_user_event(&fake_src, &fake_joystick_event, NULL); /* fake a keyboard event */ fake_keydown_event.any.type = ALLEGRO_EVENT_KEY_DOWN; fake_keydown_event.keyboard.keycode = ALLEGRO_KEY_ENTER; al_emit_user_event(&fake_src, &fake_keydown_event, NULL); /* poll for the events we injected */ while (!al_is_event_queue_empty(queue)) { al_wait_for_event(queue, &event); switch (event.type) { case ALLEGRO_EVENT_KEY_DOWN: ALLEGRO_ASSERT(event.user.source == &fake_src); log_printf("Got keydown: %d\n", event.keyboard.keycode); break; case ALLEGRO_EVENT_JOYSTICK_AXIS: ALLEGRO_ASSERT(event.user.source == &fake_src); log_printf("Got joystick axis: stick=%d axis=%d pos=%f\n", event.joystick.stick, event.joystick.axis, event.joystick.pos); break; } } al_destroy_user_event_source(&fake_src); al_destroy_event_queue(queue); log_printf("Done.\n"); close_log(true); return 0; }
int suite_grid(const char *xmldir) { suite_t suite; char logfile[256]; FILE *lf = NULL; /* Setup test suite */ strcpy(suite.suite_name, "suite_grid"); suite.num_tests = 4; suite.tests = malloc(suite.num_tests * sizeof(test_t)); if (suite.tests == NULL) { fprintf(stderr, "Failed to alloc test structure\n"); return(1); } test_get_time(&suite.exec_time); /* Setup test cases */ strcpy(suite.tests[0].test_name, "test_vx_grid"); suite.tests[0].test_func = &test_vx_grid; suite.tests[0].elapsed_time = 0.0; strcpy(suite.tests[1].test_name, "test_vx_lite_grid_emul"); suite.tests[1].test_func = &test_vx_lite_grid_emul; suite.tests[1].elapsed_time = 0.0; strcpy(suite.tests[2].test_name, "test_vx_lite_grid_depth"); suite.tests[2].test_func = &test_vx_lite_grid_depth; suite.tests[2].elapsed_time = 0.0; strcpy(suite.tests[3].test_name, "test_vx_lite_grid_offset"); suite.tests[3].test_func = &test_vx_lite_grid_offset; suite.tests[3].elapsed_time = 0.0; if (test_run_suite(&suite) != 0) { fprintf(stderr, "Failed to execute tests\n"); return(1); } if (xmldir != NULL) { sprintf(logfile, "%s/%s.xml", xmldir, suite.suite_name); lf = init_log(logfile); if (lf == NULL) { fprintf(stderr, "Failed to initialize logfile\n"); return(1); } if (write_log(lf, &suite) != 0) { fprintf(stderr, "Failed to write test log\n"); return(1); } close_log(lf); } free(suite.tests); return 0; }
/** * <b> LOG LEVELS INFO </b> * Use this function to change log level * Uses syslog to dump logs,default level is LOG_INFO * 1. LOG_EMERG 0 system is unusable * 2. LOG_ALERT 1 action must be taken immediately * 3. LOG_CRIT 2 critical conditions * 4. LOG_ERR 3 error conditions * 5. LOG_WARNING 4 warning conditions * 6. LOG_NOTICE 5 normal but significant condition * 7. LOG_INFO 6 informational * 8. <b>LOG_DEBUG 7 uses printf instead of syslog</b> * @param level log level as explained above */ void gecko_set_log_level(int level) { LOGGER(LOG_INFO,"\nbefore :%d",LOG_LEVEL); #undef LOG_LEVEL #define LOG_LEVEL level close_log(); init_log(); LOGGER(LOG_INFO,"\n after :%d\n",LOG_LEVEL); }
/** * Clean up function, which releases all the resources used by this library. * By default SIGINT signal is registered to call this function. * Resources freed in this function : * 1. Closes device file descriptor * 2. Free the mutex and locks * 3. Closes syslog * @warning fail to call this function, can result in memory leak. */ void gecko_clean_up() { // serial_write(tty_fd, stop_scan); close(tty_fd); stop_reader_thread(); destroy_serial_lock(); destroy_lock(); delete_all_node(); close_log(); }
void MainLine(typePos *Position) { typeDynamic *p; char String[16]; int va; MainLineIterate(Position); if (!RobboTotalBaseScore(Position, &va) || va == dBreak) { if (VerboseRobboBases) { Send("info string Failure in MainLine\n"); #ifdef Log if (WriteLog) { log_file = fopen(log_filename, "a"); fprintf(log_file, "info string Failure in MainLine\n"); close_log(); } #endif } return; } sprintf(String, "%d", va - dLoss); Send("mainline (%c%s): ", (va == dWin) ? 'W' :((va == dDraw) ? 'D' : 'L'), (va < dLoss) ? "" : String); for (p = Position->Dyn + 1; p->move; p++) Send("%s ", Notate(p->move & 0x7fff, String)); Send("\n"); #ifdef Log if (WriteLog) { log_file = fopen(log_filename, "a"); fprintf(log_file, "mainline (%c%s): ", (va == dWin) ? 'W' :((va == dDraw) ? 'D' : 'L'), (va < dLoss) ? "" : String); for (p = Position->Dyn + 1; p->move; p++) fprintf(log_file, "%s ", Notate(p->move & 0x7fff, String)); fprintf(log_file, "\n"); close_log(); } #endif }