int main(int argc,char *argv[]) { const char *desc[] = { "proptrj" }; t_manual man = { asize(desc),desc,0,NULL,NULL,0,NULL}; t_filenm fnm[] = { { efGRO, "-c", "aver",FALSE }, { efDAT, "-d", "eigenvec", FALSE }, { efTPX, NULL, NULL, FALSE }, { efDAT, "-pi","pinp", FALSE }, { efDAT, "-po","poutp", FALSE } }; #define NFILE asize(fnm) t_topology *top; t_pinp *p; CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME, NFILE,fnm,TRUE,&man); top=read_top(ftp2fn(efTPX,NFILE,fnm)); init_debug("proptim.dbg",0); snew(p,1); read_inp(opt2fn("-pi",NFILE,fnm),opt2fn("-po",NFILE,fnm),p); proptrj(ftp2fn(efGRO,NFILE,fnm),ftp2fn(efDAT,NFILE,fnm),top,p); thanx(stderr); return 0; }
/* * New interface provided by krb5's com_err library */ errcode_t remove_error_table(const struct error_table * et) { struct et_list *el; struct et_list *el2 = 0; if (et_list_lock() != 0) return ENOENT; el = _et_dynamic_list; init_debug(); while (el) { if (el->table->base == et->base) { if (el2) /* Not the beginning of the list */ el2->next = el->next; else _et_dynamic_list = el->next; (void) free(el); if (debug_mask & DEBUG_ADDREMOVE) fprintf(debug_f, "remove_error_table: %s (0x%p)\n", error_table_name(et->base), (const void *) et); et_list_unlock(); return 0; } el2 = el; el = el->next; } if (debug_mask & DEBUG_ADDREMOVE) fprintf(debug_f, "remove_error_table FAILED: %s (0x%p)\n", error_table_name(et->base), (const void *) et); et_list_unlock(); return ENOENT; }
int kern_entry() { init_debug(); console_clear(); printk_color(rc_black, rc_green, "Hello, OS kernel!\n"); //panic("test"); printk("kernel in memory start: 0x%08X\n", kern_start); printk("kernel in memory end: 0x%08X\n", kern_end); printk("kernel in memory used: %d KB\n\n", (kern_end - kern_start) / 1024); show_memory_map(); init_pmm(); printk_color(rc_black, rc_red, "\nThe Count of Physical Memory Page is: %u\n\n", phy_page_count); uint32_t allc_addr = NULL; printk_color(rc_black, rc_light_brown, "Test Physical Memory Alloc :\n"); allc_addr = pmm_alloc_page(); printk_color(rc_black, rc_light_brown, "Alloc Physical Addr: 0x%08X\n", allc_addr); allc_addr = pmm_alloc_page(); printk_color(rc_black, rc_light_brown, "Alloc Physical Addr: 0x%08X\n", allc_addr); allc_addr = pmm_alloc_page(); printk_color(rc_black, rc_light_brown, "Alloc Physical Addr: 0x%08X\n", allc_addr); allc_addr = pmm_alloc_page(); printk_color(rc_black, rc_light_brown, "Alloc Physical Addr: 0x%08X\n", allc_addr); return 0; }
/* * Examine user's PATH and print a reasonable MANPATH. */ int main (int argc, char *argv[]) { char *path_string; program_name = base_name (argv[0]); init_debug (); init_locale (); if (argp_parse (&argp, argc, argv, 0, 0, 0)) exit (FAIL); path_string = get_manpath (alt_system); if (global) { path_string = get_mandb_manpath (); if (!path_string) error (FAIL, 0, _("warning: no global manpaths set in " "config file %s"), CONFIG_FILE); } if (cat) path_string = cat_manpath (path_string); printf ("%s\n", path_string); exit (OK); }
int main(int argc, const char** argv) { MSG msg; init_debug(); status = parse_arguments(argc, argv); if (status) { if (status == 2) usage(); else fprintf(stderr, "Issue %s --help for usage.\n", *argv); return RC_INVALID_ARGUMENTS; } cxlog("Entering message loop. action=%d\n", g_action); if (g_timeout>0) SetTimer(NULL, 0, g_timeout, TimeoutProc); timer_id=SetTimer(NULL, 0, 100, FindWindowProc); status=RC_RUNNING; while (status==RC_RUNNING && GetMessage(&msg, NULL, 0, 0)!=0) { TranslateMessage(&msg); DispatchMessage(&msg); } return status; }
/* * New interface provided by krb5's com_err library */ errcode_t add_error_table(const struct error_table * et) { struct et_list *el; if (!(el = (struct et_list *) malloc(sizeof(struct et_list)))) return ENOMEM; if (et_list_lock() != 0) { free(el); return errno; } el->table = et; el->next = _et_dynamic_list; _et_dynamic_list = el; init_debug(); if (debug_mask & DEBUG_ADDREMOVE) fprintf(debug_f, "add_error_table: %s (0x%p)\n", error_table_name(et->base), (const void *) et); et_list_unlock(); return 0; }
/* * boot -- first routine called */ void boot(void *arg) { osInitialize(); #ifdef SN64 init_debug(); #endif handler = osCartRomInit(); osCreateThread(&mainThread, MAIN_ID, (void(*)(void *))mainproc, arg, (void *)(mainStack+STACKSIZE/8), (OSPri) MAIN_PRIORITY); osStartThread(&mainThread); } /* boot */
int main(multiboot_t * mbp) { cpu_state_t *cpu; // first is to save critical info from bootloader // and get symbol tables so we can print back traces mbootp = mbp; init_debug(mbp); // reset text-mode c80_clear(); printk_color(rc_black, rc_red, "\t\t\t\tRed Magic\n"); // init processors init_bootstrap_processor(); cpu = get_boot_processor(); ASSERT(cpu != NULL); // initialize descriptors init_global_descriptor_table(cpu); init_interrupt_descriptor_table(); init_io_apic(); // interrupt on local_irq_enable(); // memory management show_kernel_pos(); show_ARDS_from_multiboot(mbp); init_paging(); init_kheap(); // initialize devices and rootfs init_dev(); //init_root_fs(); // start all APs if (mpinfo.ismp) start_smp(); // start system clock if (!mpinfo.ismp) init_pit_timer(CLOCK_INT_HZ); else init_apic_timer(CLOCK_INT_HZ); // initialize kernel task and scheduling setup_init_task(); init_sched(); // All our initialisation calls will go in here. return 0xDEADBABA; }
int kern_entry() { init_debug(); console_clear(); printk_color(rc_black, rc_green, "Hello, OS kernel!\n"); panic("test"); return 0; }
int main(int argc, char **argv) { struct io_space *ios; struct list_head *pvs, *tmp; struct dm_pool *mem; init_log(stderr); init_debug(_LOG_INFO); if (!dev_cache_init()) { fprintf(stderr, "init of dev-cache failed\n"); exit(1); } if (!dev_cache_add_dir("/dev/loop")) { fprintf(stderr, "couldn't add /dev to dir-cache\n"); exit(1); } if (!(mem = dm_pool_create(10 * 1024))) { fprintf(stderr, "couldn't create pool\n"); exit(1); } ios = create_lvm1_format("/dev", mem, NULL); if (!ios) { fprintf(stderr, "failed to create io_space for format1\n"); exit(1); } pvs = ios->get_pvs(ios); if (!pvs) { fprintf(stderr, "couldn't read vg %s\n", argv[1]); exit(1); } list_for_each(tmp, pvs) { struct pv_list *pvl = list_entry(tmp, struct pv_list, list); dump_pv(&pvl->pv, stdout); } ios->destroy(ios); dm_pool_destroy(mem); dev_cache_exit(); dump_memory(); fin_log(); return 0; }
main (int argc, char *argv[]){ FileList f; Element_List *master; parse_util_args(argc = generic_args (argc, argv, &f), argv, &f); #ifdef DEBUG init_debug(); #endif setup (&f, &master); WriteMesh(master,f.out.fp); return 0; }
int kern_entry() { init_debug(); init_gdt(); init_idt(); console_clear(); printk_color(rc_black, rc_green, "Hello, OS kernel!\n"); init_timer(200); // 开启中断 asm volatile ("sti"); return 0; }
void boot(void) { /* * notice that you can't call osSyncPrintf() until you set * * up the rmon thread. */ osInitialize(); #ifdef SN64 init_debug(); #endif osCreateThread( &idleThread, 1, idle, (void *) 0, idleThreadStack + STACKSIZE / sizeof(u64), 10 ); osStartThread(&idleThread); }
int main() { init_debug(); Falcon<Test_Controller> falcon; if(!falcon.isInit()) { BOOST_LOG_TRIVIAL(debug) << "falcon error: " << falcon.getError(); return EXIT_FAILURE; } falcon.start(); boost::this_thread::sleep(boost::posix_time::seconds(100)); return EXIT_SUCCESS; }
int main (int argc, char ** argv) { text_splash(); init_debug(argv[0]); printf("\n"); printf("Documentation : %s \n","http://ert.nr.no"); printf("git commit : %s \n",ert_version_get_git_commit( )); printf("compile time : %s \n",ert_version_get_build_time( )); printf("site config : %s \n", site_config_get_location()); enkf_main_install_SIGNALS(); /* Signals common to both tui and gui. */ signal(SIGINT, util_abort_signal); /* Control C - tui only. */ if (argc < 2) { enkf_usage(); exit(1); } else { const char * model_config_file = argv[1]; stringlist_type * workflow_list = stringlist_alloc_new(); parse_workflows(argc, argv, workflow_list); if (!(util_entry_readable(model_config_file) && util_is_file(model_config_file))) util_exit("Can not read file %s - exiting \n", model_config_file); { char * abs_config = util_alloc_realpath(model_config_file); printf("model config : %s \n\n", abs_config); free(abs_config); } enkf_welcome(model_config_file); { res_config_type * res_config = res_config_alloc_load(model_config_file); util_chdir( res_config_get_config_directory( res_config )); { enkf_main_type * enkf_main = enkf_main_alloc(res_config, true, true); enkf_main_run_workflows(enkf_main, workflow_list); enkf_tui_main_menu(enkf_main); enkf_main_free(enkf_main); res_config_free(res_config); } } stringlist_free(workflow_list); util_abort_free_version_info(); /* No f*****g leaks ... */ } exit(0); }
int entry() { init_debug(); init_gdt(); init_idt(); char *string = "hello word!\n"; screen_clear(); printk("%s\n", string); init_timer(200); //sti是恢复中断。cli是关闭中断。 asm volatile ("sti"); asm volatile ("int $0x1"); return 0; }
static int batmon_probe(struct platform_device *pdev) { int i; struct sysedp_batmon_rbat_lut *rbat; if (pdev->dev.of_node) of_batmon_calc_get_pdata(pdev, &pdata); else pdata = pdev->dev.platform_data; if (!pdata) return -EINVAL; /* validate pdata->rbat_lut table */ rbat = pdata->rbat_lut; if (!rbat) return -EINVAL; for (i = 1; i < rbat->temp_size; i++) if (rbat->temp_axis[i] >= rbat->temp_axis[i-1]) return -EINVAL; for (i = 1; i < rbat->capacity_size; i++) if (rbat->capacity_axis[i] >= rbat->capacity_axis[i-1]) return -EINVAL; if (rbat->capacity_size * rbat->temp_size != rbat->data_size) return -EINVAL; psy = power_supply_get_by_name(pdata->power_supply); if (!psy) return -EFAULT; if (init_ocv_reader()) return -EFAULT; init_sysfs(); INIT_DEFERRABLE_WORK(&work, batmon_update); schedule_delayed_work(&work, 0); init_debug(); return 0; }
void kernel_init() { init_gdt(); init_idt(); init_debug(); init_mm(); init_vmm(); init_heap(); init_sched(); console_clear(); cprintk(rc_light_brown, "Welcome to SuperSong's OS, version: %s\n\n", "v0.1"); init_timer(200); cprintk(rc_light_cyan, "kernel in memory start: 0x%x\n", __kernel_mem_start); cprintk(rc_light_cyan, "kernel in memory end: 0x%x\n", __kernel_mem_end); cprintk(rc_light_cyan, "kernel in memory_used: %d KBs\n", (__kernel_mem_end - __kernel_mem_start + 1023) / 1024); show_memory_map(); cprintk(rc_red, "\nThe count of physical memory pages is: %d\n\n", phy_page_count); kthread_create(thread, NULL); enable_intr(); while (1) { cprintk(rc_red, "Thraed1\n"); } while (1) { __asm__ volatile ("hlt"); } }
int main(int argc, char *argv[]) { t_gameboy gb; g_gb = &gb; signal(SIGINT, &sighandler); /* ** First call the initializers to set the default values, ** then call the argument parser to modify them if needed. */ memset(&gb, 0, sizeof(gb)); init_debug(&gb); init_timing(&gb); init_gpu(&gb); if (get_args(argc, argv, &gb) || init_gameboy(&gb) || start_gpu(&gb)) return (EXIT_FAILURE); run_gameboy(&gb); SDL_Quit(); return (EXIT_SUCCESS); }
void application_main(void) { unsigned char toto[2][4]={{0x05,0x01,0x00,0xf0}, // 00000101, 00000001, 00000000, 11110000 {0x0A,0x02,0x00,0xf0}};// 00001010, 00000010, 00000000, 11110000 // Reset the Timer0 value TMR0H = 0; TMR0L = 1; setalim(); init_motors(); setup_adconversion(); init_servos(); init_digitals_in(); init_debug(); init_fdc(); set_fdc((unsigned char *)toto,2); SET_DEVICE_STATUS(REMOTE_WAKEUP_DIS); // Interruptions PIE2bits.USBIE = 0; // Interrupt USB off : on ne touche pas a la gestion de l'USB !! INTCONbits.PEIE = 1; // Interrupts peripheriques (usb, timer 1...) INTCONbits.GIE = 1; // Interrupts global while(usb_active_cfg > 2) { usb_sleep(); dispatch_usb_event(); } cutalim(); PINDEBUG = 0; verif_fdc(0); // clear_device_remote_wakeup(); }
void boot(void) { /* * notice that you can't call osSyncPrintf() until you set * up an idle thread. */ osInitialize(); #ifdef SN64 init_debug(); #endif handler = osCartRomInit(); osCreateThread(&idleThread, 1, idle, NULL, idleThreadStack + STACKSIZE / sizeof(u64), 10); osStartThread(&idleThread); /* * never reached */ }
void parse_common_args(int *argc,char *argv[],unsigned long Flags, int nfile,t_filenm fnm[],int npargs,t_pargs *pa, int ndesc,char **desc,int nbugs,char **bugs) { static bool bHelp=FALSE,bHidden=FALSE,bQuiet=FALSE; static char *manstr[] = { NULL, "no", "html", "tex", "nroff", "ascii", "completion", NULL }; static char *not_nicestr[] = { NULL, "0", "4", "10", "19", NULL }; static char *nicestr[] = { NULL, "19", "10", "4", "0", NULL }; static char *not_npristr[] = { NULL, "0", "128", "100", "200", "250", NULL }; static char *npristr[] = { NULL, "128", "250", "200", "100", "0", NULL }; static int nicelevel=0,mantp=0,npri=0; static bool bGUI=FALSE,bDebug=FALSE; static char *deffnm=NULL; FILE *fp; bool bPrint,bExit; int i,j,k,npall; char *ptr,*newdesc; char *envstr; t_pargs *all_pa=NULL; t_pargs motif_pa = { "-X", FALSE, etBOOL, {&bGUI}, "Use dialog box GUI to edit command line options" }; t_pargs npri_paX = { "-npri", FALSE, etENUM, {not_npristr}, "Set non blocking priority" }; t_pargs npri_pa = { "-npri", FALSE, etINT, {&npri}, "HIDDEN Set non blocking priority (try 128)" }; t_pargs nice_paX = { "-nice", FALSE, etENUM, {not_nicestr}, "Set the nicelevel" }; t_pargs nice_pa = { "-nice", FALSE, etINT, {&nicelevel}, "Set the nicelevel" }; t_pargs deffnm_pa = { "-deffnm", FALSE, etSTR, {&deffnm}, "Set the default filename for all file options" }; t_pargs begin_pa = { "-b", FALSE, etTIME, {&tbegin}, "First frame (%t) to read from trajectory" }; t_pargs end_pa = { "-e", FALSE, etTIME, {&tend}, "Last frame (%t) to read from trajectory" }; t_pargs dt_pa = { "-dt", FALSE, etTIME, {&tdelta}, "Only use frame when t MOD dt = first time (%t)" }; t_pargs view_pa = { "-w", FALSE, etBOOL, {&bView}, "View output xvg, xpm, eps and pdb files" }; t_pargs time_pa = { "-tu", FALSE, etENUM, {timestr}, "Time unit" }; t_pargs pca_pa[] = { { "-h", FALSE, etBOOL, {&bHelp}, "Print help info and quit" }, { "-hidden", FALSE, etBOOL, {&bHidden}, "HIDDENPrint hidden options" }, { "-quiet",FALSE, etBOOL, {&bQuiet}, "HIDDENDo not print help info" }, { "-man", FALSE, etENUM, {manstr}, "HIDDENWrite manual and quit" }, { "-debug",FALSE, etBOOL, {&bDebug}, "HIDDENWrite file with debug information" }, }; #define NPCA_PA asize(pca_pa) debug_gmx(); if (debug) { fprintf(debug,"PID=%d, argc = %d\n",gmx_node_id(),*argc); for(i=0; (i<*argc); i++) fprintf(debug,"PID=%d, argv[%d] = %s\n",gmx_node_id(),i,argv[i]); } /* Check for double arguments */ for (i=1; (i<*argc); i++) { if (argv[i] && (strlen(argv[i]) > 1) && (!isdigit(argv[i][1]))) { for (j=i+1; (j<*argc); j++) { if ( (argv[i][0]=='-') && (argv[j][0]=='-') && (strcmp(argv[i],argv[j])==0) ) { if (FF(PCA_NOEXIT_ON_ARGS)) fprintf(stderr,"Double command line argument %s\n",argv[i]); else fatal_error(0,"Double command line argument %s\n",argv[i]); } } } } debug_gmx(); /* Handle the flags argument, which is a bit field * The FF macro returns whether or not the bit is set */ uFlags = Flags; bPrint = !FF(PCA_SILENT); /* Check whether we should have GUI or not */ #ifdef HAVE_MOTIF bGUI = (getenv("GMXMOTIF") != NULL); for(i=1; (i<*argc); i++) { if (strcmp(argv[i],"-X") == 0) bGUI = TRUE; else if (strcmp(argv[i],"-noX") == 0) bGUI = FALSE; } if (bGUI) bQuiet = TRUE; #else bGUI = FALSE; #endif set_program_name(argv[0]); /* Check ALL the flags ... */ snew(all_pa,NPCA_PA+npargs); for(i=npall=0; (i<NPCA_PA); i++) npall = add_parg(npall,&(all_pa),&(pca_pa[i])); /* Motif options */ npall = add_parg(npall,&(all_pa),&motif_pa); #if (defined __sgi && !defined SPEC_CPU) envstr = getenv("GMXNPRIALL"); if (envstr) npri=atoi(envstr); if (FF(PCA_BE_NICE)) { envstr = getenv("GMXNPRI"); if (envstr) npri=atoi(envstr); } if (bGUI) { if (npri) npri_paX.u.c = npristr; npall = add_parg(npall,&(all_pa),&npri_paX); } else npall = add_parg(npall,&(all_pa),&npri_pa); #endif if (bGUI) { /* Automatic nice or scheduling options */ if (FF(PCA_BE_NICE)) nice_paX.u.c = nicestr; npall = add_parg(npall,&(all_pa),&nice_paX); } else { if (FF(PCA_BE_NICE)) nicelevel=19; npall = add_parg(npall,&(all_pa),&nice_pa); } if (FF(PCA_CAN_SET_DEFFNM)) npall = add_parg(npall,&(all_pa),&deffnm_pa); if (FF(PCA_CAN_BEGIN)) npall = add_parg(npall,&(all_pa),&begin_pa); if (FF(PCA_CAN_END)) npall = add_parg(npall,&(all_pa),&end_pa); if (FF(PCA_CAN_DT)) npall = add_parg(npall,&(all_pa),&dt_pa); #ifndef SPEC_CPU if (FF(PCA_TIME_UNIT)) { envstr = getenv("GMXTIMEUNIT"); if ( envstr == NULL ) envstr="ps"; set_default_time_unit(envstr); npall = add_parg(npall,&(all_pa),&time_pa); } else #endif set_default_time_unit("ps"); if (FF(PCA_CAN_VIEW)) npall = add_parg(npall,&(all_pa),&view_pa); /* Now append the program specific arguments */ for(i=0; (i<npargs); i++) npall = add_parg(npall,&(all_pa),&(pa[i])); /* set etENUM options to default */ for(i=0; (i<npall); i++) if (all_pa[i].type==etENUM) all_pa[i].u.c[0]=all_pa[i].u.c[1]; /* Now parse all the command-line options */ get_pargs(argc,argv,npall,all_pa,FF(PCA_KEEP_ARGS)); if (FF(PCA_CAN_SET_DEFFNM) && (deffnm!=NULL)) set_default_file_name(deffnm); /* Parse the file args */ parse_file_args(argc,argv,nfile,fnm,FF(PCA_KEEP_ARGS)); /* Open the debug file */ if (bDebug) { char buf[256]; if (gmx_node_num() > 1) sprintf(buf,"%s%d.log",ShortProgram(),gmx_node_id()); else sprintf(buf,"%s.log",ShortProgram()); init_debug(buf); fprintf(debug,"%s (this file) opened in file %s, line %d\n", buf,__FILE__,__LINE__); } /* Now we have parsed the command line arguments. If the user wants it * we can now plop up a GUI dialog box to edit options. */ if (bGUI) { #ifdef HAVE_MOTIF gmx_gui(argc,argv,nfile,fnm,npall,all_pa,ndesc,desc,nbugs,bugs); #else fatal_error(0,"GROMACS compiled without MOTIF support - can't use X interface"); #endif } /* Now copy the results back... */ for(i=0,k=npall-npargs; (i<npargs); i++,k++) memcpy(&(pa[i]),&(all_pa[k]),(size_t)sizeof(pa[i])); for(i=0; (i<npall); i++) all_pa[i].desc = mk_desc(&(all_pa[i]), time_unit() ); bExit = bHelp || (strcmp(manstr[0],"no") != 0); #if (defined __sgi && USE_SGI_FPE) doexceptions(); #endif /* Set the nice level */ #ifdef __sgi if (bGUI) if (npri) sscanf(npristr[0],"%d",&npri); else sscanf(not_npristr[0],"%d",&npri); if (npri != 0 && !bExit) { (void) schedctl(MPTS_RTPRI,0,npri); } else #endif #ifdef HAVE_UNISTD_H if (bGUI) { if (FF(PCA_BE_NICE)) sscanf(nicestr[0],"%d",&nicelevel); else sscanf(not_nicestr[0],"%d",&nicelevel); } if (nicelevel != 0 && !bExit) nice(nicelevel); #endif if (!(FF(PCA_QUIET) || bQuiet )) { if (bHelp) write_man(stderr,"help",program,ndesc,desc,nfile,fnm,npall,all_pa, nbugs,bugs,bHidden); else if (bPrint) { pr_fns(stderr,nfile,fnm); print_pargs(stderr,npall,all_pa); } } if (strcmp(manstr[0],"no") != 0) { if(!strcmp(manstr[0],"completion")) { /* one file each for csh, bash and zsh if we do completions */ fp=man_file(program,"completion-zsh"); write_man(fp,"completion-zsh",program,ndesc,desc,nfile,fnm,npall,all_pa,nbugs,bugs,bHidden); fclose(fp); fp=man_file(program,"completion-bash"); write_man(fp,"completion-bash",program,ndesc,desc,nfile,fnm,npall,all_pa,nbugs,bugs,bHidden); fclose(fp); fp=man_file(program,"completion-csh"); write_man(fp,"completion-csh",program,ndesc,desc,nfile,fnm,npall,all_pa,nbugs,bugs,bHidden); fclose(fp); } else { fp=man_file(program,manstr[0]); write_man(fp,manstr[0],program,ndesc,desc,nfile,fnm,npall,all_pa,nbugs,bugs,bHidden); fclose(fp); } } /* convert time options, must be done after printing! */ init_time_factor(); for(i=0; i<npall; i++) { if ((all_pa[i].type == etTIME) && (*all_pa[i].u.r >= 0)) { *all_pa[i].u.r /= timefactor; } } /* clear memory */ for(i=0; i<npall; i++) sfree(all_pa[i].desc); sfree(all_pa); if (!FF(PCA_NOEXIT_ON_ARGS)) { if (*argc > 1) { for(i=1; (i<*argc); i++) fprintf(stderr,"Unknown argument: %s\n",argv[i]); fatal_error(0,"Program %s halted",Program()); } } if (bExit) { #ifdef USE_MPI if (gmx_parallel) gmx_abort(gmx_node_id(),gmx_node_num(),0); #endif exit(0); } }
gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags, int nfile, t_filenm fnm[], int npargs, t_pargs *pa, int ndesc, const char **desc, int nbugs, const char **bugs, output_env_t *oenv) { /* This array should match the order of the enum in oenv.h */ const char *xvg_format[] = { NULL, "xmgrace", "xmgr", "none", NULL }; /* This array should match the order of the enum in oenv.h */ const char *time_units[] = { NULL, "fs", "ps", "ns", "us", "ms", "s", NULL }; int nicelevel = 0, debug_level = 0; char *deffnm = NULL; real tbegin = 0, tend = 0, tdelta = 0; gmx_bool bView = FALSE; t_pargs *all_pa = NULL; t_pargs nice_pa = { "-nice", FALSE, etINT, {&nicelevel}, "Set the nicelevel" }; t_pargs deffnm_pa = { "-deffnm", FALSE, etSTR, {&deffnm}, "Set the default filename for all file options" }; t_pargs begin_pa = { "-b", FALSE, etTIME, {&tbegin}, "First frame (%t) to read from trajectory" }; t_pargs end_pa = { "-e", FALSE, etTIME, {&tend}, "Last frame (%t) to read from trajectory" }; t_pargs dt_pa = { "-dt", FALSE, etTIME, {&tdelta}, "Only use frame when t MOD dt = first time (%t)" }; t_pargs view_pa = { "-w", FALSE, etBOOL, {&bView}, "View output [TT].xvg[tt], [TT].xpm[tt], [TT].eps[tt] and [TT].pdb[tt] files" }; t_pargs xvg_pa = { "-xvg", FALSE, etENUM, {xvg_format}, "xvg plot formatting" }; t_pargs time_pa = { "-tu", FALSE, etENUM, {time_units}, "Time unit" }; /* Maximum number of extra arguments */ #define EXTRA_PA 16 t_pargs pca_pa[] = { { "-debug", FALSE, etINT, {&debug_level}, "HIDDENWrite file with debug information, 1: short, 2: also x and f" }, }; #define NPCA_PA asize(pca_pa) gmx_bool bXvgr; int i, j, k, npall, max_pa; // Handle the flags argument, which is a bit field // The FF macro returns whether or not the bit is set #define FF(arg) ((Flags & arg) == arg) /* Check for double arguments */ for (i = 1; (i < *argc); i++) { if (argv[i] && (strlen(argv[i]) > 1) && (!std::isdigit(argv[i][1]))) { for (j = i+1; (j < *argc); j++) { if ( (argv[i][0] == '-') && (argv[j][0] == '-') && (strcmp(argv[i], argv[j]) == 0) ) { if (FF(PCA_NOEXIT_ON_ARGS)) { fprintf(stderr, "Double command line argument %s\n", argv[i]); } else { gmx_fatal(FARGS, "Double command line argument %s\n", argv[i]); } } } } } debug_gmx(); /* Check ALL the flags ... */ max_pa = NPCA_PA + EXTRA_PA + npargs+1; snew(all_pa, max_pa); for (i = npall = 0; (i < static_cast<int>(NPCA_PA)); i++) { npall = add_parg(npall, all_pa, &(pca_pa[i])); } if (FF(PCA_BE_NICE)) { nicelevel = 19; } npall = add_parg(npall, all_pa, &nice_pa); if (FF(PCA_CAN_SET_DEFFNM)) { npall = add_parg(npall, all_pa, &deffnm_pa); } if (FF(PCA_CAN_BEGIN)) { npall = add_parg(npall, all_pa, &begin_pa); } if (FF(PCA_CAN_END)) { npall = add_parg(npall, all_pa, &end_pa); } if (FF(PCA_CAN_DT)) { npall = add_parg(npall, all_pa, &dt_pa); } if (FF(PCA_TIME_UNIT)) { npall = add_parg(npall, all_pa, &time_pa); } if (FF(PCA_CAN_VIEW)) { npall = add_parg(npall, all_pa, &view_pa); } bXvgr = FALSE; for (i = 0; (i < nfile); i++) { bXvgr = bXvgr || (fnm[i].ftp == efXVG); } if (bXvgr) { npall = add_parg(npall, all_pa, &xvg_pa); } /* Now append the program specific arguments */ for (i = 0; (i < npargs); i++) { npall = add_parg(npall, all_pa, &(pa[i])); } /* set etENUM options to default */ for (i = 0; (i < npall); i++) { if (all_pa[i].type == etENUM) { all_pa[i].u.c[0] = all_pa[i].u.c[1]; } } set_default_time_unit(time_units, FF(PCA_TIME_UNIT)); set_default_xvg_format(xvg_format); /* Now parse all the command-line options */ get_pargs(argc, argv, npall, all_pa); /* set program name, command line, and default values for output options */ output_env_init(oenv, gmx::getProgramContext(), (time_unit_t)nenum(time_units), bView, (xvg_format_t)nenum(xvg_format), 0, debug_level); /* Parse the file args */ parse_file_args(argc, argv, nfile, fnm, deffnm, !FF(PCA_NOT_READ_NODE)); /* Open the debug file */ if (debug_level > 0) { char buf[256]; if (gmx_mpi_initialized()) { sprintf(buf, "%s%d.debug", output_env_get_short_program_name(*oenv), gmx_node_rank()); } else { sprintf(buf, "%s.debug", output_env_get_short_program_name(*oenv)); } init_debug(debug_level, buf); fprintf(stderr, "Opening debug file %s (src code file %s, line %d)\n", buf, __FILE__, __LINE__); } /* Now copy the results back... */ for (i = 0, k = npall-npargs; (i < npargs); i++, k++) { memcpy(&(pa[i]), &(all_pa[k]), (size_t)sizeof(pa[i])); } bool bExit = false; try { const gmx::CommandLineHelpContext *context = gmx::GlobalCommandLineHelpContext::get(); bExit = (context != NULL); if (context != NULL && !(FF(PCA_QUIET))) { gmx::Options options(NULL, NULL); options.setDescription(gmx::constArrayRefFromArray(desc, ndesc)); for (i = 0; i < nfile; i++) { gmx::filenmToOptions(&options, &fnm[i]); } for (i = 0; i < npall; i++) { gmx::pargsToOptions(&options, &all_pa[i]); } gmx::CommandLineHelpWriter(options) .setShowDescriptions(true) .setTimeUnitString(output_env_get_time_unit(*oenv)) .setKnownIssues(gmx::constArrayRefFromArray(bugs, nbugs)) .writeHelp(*context); } } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; /* Set the nice level */ #if defined(HAVE_UNISTD_H) && !defined(__MINGW32__) #ifndef GMX_NO_NICE /* The some system, e.g. the catamount kernel on cray xt3 do not have nice(2). */ if (nicelevel != 0 && !bExit) { static gmx_bool nice_set = FALSE; /* only set it once */ static tMPI_Thread_mutex_t init_mutex = TMPI_THREAD_MUTEX_INITIALIZER; tMPI_Thread_mutex_lock(&init_mutex); if (!nice_set) { if (nice(nicelevel) == -1) { /* Do nothing, but use the return value to avoid warnings. */ } nice_set = TRUE; } tMPI_Thread_mutex_unlock(&init_mutex); } #endif #endif /* convert time options, must be done after printing! */ for (i = 0; i < npall; i++) { if (all_pa[i].type == etTIME && all_pa[i].bSet) { *all_pa[i].u.r *= output_env_get_time_invfactor(*oenv); } } /* Extract Time info from arguments */ if (FF(PCA_CAN_BEGIN) && opt2parg_bSet("-b", npall, all_pa)) { setTimeValue(TBEGIN, opt2parg_real("-b", npall, all_pa)); } if (FF(PCA_CAN_END) && opt2parg_bSet("-e", npall, all_pa)) { setTimeValue(TEND, opt2parg_real("-e", npall, all_pa)); } if (FF(PCA_CAN_DT) && opt2parg_bSet("-dt", npall, all_pa)) { setTimeValue(TDELTA, opt2parg_real("-dt", npall, all_pa)); } /* clear memory */ sfree(all_pa); if (!FF(PCA_NOEXIT_ON_ARGS)) { if (*argc > 1) { gmx_cmd(argv[1]); } } return !bExit; #undef FF }
int main( int argc, char **argv ) { /* Print copyright notice */ fprintf( stderr, "Tux Rider World Challenge -- http://www.barlow-server.com\n" "a fork from:\n" "Tux Racer " VERSION " -- a Sunspire Studios Production " "(http://www.sunspirestudios.com)\n" "(c) 1999-2000 Jasmin F. Patry " "<*****@*****.**>\n" "\"Tux Racer\" is a trademark of Jasmin F. Patry\n" "Tux Rider World Challenge comes with ABSOLUTELY NO WARRANTY. " "This is free software,\nand you are welcome to redistribute " "it under certain conditions.\n" "See http://www.gnu.org/copyleft/gpl.html for details.\n\n" ); /* Init the game clock */ g_game.secs_since_start = 0; /* Seed the random number generator */ srand( time(NULL) ); /* * Set up the game configuration */ /* Don't support multiplayer, yet... */ g_game.num_players = 2; /* Create a Tcl interpreter */ g_game.tcl_interp = Tcl_CreateInterp(); if ( g_game.tcl_interp == NULL ) { handle_error( 1, "cannot create Tcl interpreter" ); } /* Setup the configuration variables and read the ~/.tuxracer/options file */ init_game_configuration(); read_config_file(); /* Set up the debugging modes */ init_debug(); /* Setup diagnostic log if requested */ if ( getparam_write_diagnostic_log() ) { setup_diagnostic_log(); } /* * Setup Tcl stdout and stderr channels to point to C stdout and stderr * streams */ setup_tcl_std_channels(); /* * Initialize rendering context, create window */ winsys_init( &argc, argv, WINDOW_TITLE, WINDOW_TITLE ); /* Ingore key-repeat messages */ winsys_enable_key_repeat(0); /* Set up a function to clean up when program exits */ winsys_atexit( cleanup ); /* * Initial OpenGL settings */ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); init_opengl_extensions(); /* Print OpenGL debugging information if requested */ if ( debug_mode_is_active( DEBUG_GL_INFO ) ) { print_debug( DEBUG_GL_INFO, "OpenGL information:" ); print_gl_info(); } /* * Load the game data and initialize game state */ register_game_config_callbacks( g_game.tcl_interp ); register_course_load_tcl_callbacks( g_game.tcl_interp ); register_key_frame_callbacks( g_game.tcl_interp ); register_fog_callbacks( g_game.tcl_interp ); register_course_light_callbacks( g_game.tcl_interp ); register_particle_callbacks( g_game.tcl_interp ); register_texture_callbacks( g_game.tcl_interp ); register_font_callbacks( g_game.tcl_interp ); register_sound_tcl_callbacks( g_game.tcl_interp ); register_sound_data_tcl_callbacks( g_game.tcl_interp ); register_course_manager_callbacks( g_game.tcl_interp ); init_saved_games(); load_tux(); init_textures(); init_fonts(); init_audio_data(); init_audio(); init_ui_manager(); init_course_manager(); init_joystick(); /* Read the tuxracer_init.tcl file */ read_game_init_script(); /* Need to set up an initial view position for select_course (quadtree simplification) */ //Player 0 = classic mode player ; Player 1 = Speed Only Mode Player g_game.player[0].view.pos = make_point( 0., 0., 0. ); g_game.player[1].view.pos = make_point( 0., 0., 0. ); /* Placeholder name until we give players way to enter name */ g_game.player[0].name = "noname"; g_game.player[1].name = "nonameSpeedOnly"; init_preview(); splash_screen_register(); intro_register(); racing_register(); game_over_register(); paused_register(); reset_register(); game_type_select_register(); racing_mode_select_register(); event_select_register(); race_select_register(); credits_register(); loading_register(); g_game.mode = NO_MODE; set_game_mode( SPLASH ); g_game.difficulty = DIFFICULTY_LEVEL_NORMAL; init_keyboard(); winsys_show_cursor( False ); /* We use this to "prime" the GLUT loop */ winsys_set_idle_func( main_loop ); /* * ...and off we go! */ winsys_process_events(); return 0; }
/** * Main loop, forks the children, bind to addresses, * handle signals. * \return don't return on sucess, -1 on error */ static int main_loop(void) { static int chd_rank; int* startup_done = NULL; chd_rank=0; if (init_debug() != 0) { LM_ERR("failed to init logging levels\n"); goto error; } if (dont_fork) { if (create_status_pipe() < 0) { LM_ERR("failed to create status pipe\n"); goto error; } if (udp_init_nofork() < 0) { LM_ERR("failed to init UDP for no fork mode\n"); goto error; } /* try to drop privileges */ if (do_suid(uid, gid)==-1) goto error; if (start_module_procs()!=0) { LM_ERR("failed to fork module processes\n"); goto error; } /* we need another process to act as the timer*/ if (start_timer_processes()!=0) { LM_CRIT("cannot start timer process(es)\n"); goto error; } is_main=1; udp_start_nofork(); /* udp_start_nofork() returns only if error */ /* in case of failed startup, behave as "attendant" to trigger * proper cleanup sequance (and proper signal handler !!!). * So, reset the dont_fork (as it will force inline signal handling)*/ dont_fork = 0; return -1; } else { /* don't fork */ if (trans_init_all_listeners()<0) { LM_ERR("failed to init all SIP listeners, aborting\n"); goto error; } /* all processes should have access to all the sockets (for sending) * so we open all first*/ if (do_suid(uid, gid)==-1) goto error; /* try to drop privileges */ if (start_module_procs()!=0) { LM_ERR("failed to fork module processes\n"); goto error; } if(startup_rlist.a) {/* if a startup route was defined */ startup_done = (int*)shm_malloc(sizeof(int)); if(startup_done == NULL) { LM_ERR("No more shared memory\n"); goto error; } *startup_done = 0; } if (fix_socket_list(&bin) != 0) { LM_ERR("failed to initialize binary interface socket list!\n"); goto error; } /* OpenSIPS <--> OpenSIPS communication interface */ if (bin && start_bin_receivers() != 0) { LM_CRIT("cannot start binary interface receiver processes!\n"); goto error; } /* fork for the timer process*/ if (start_timer_processes()!=0) { LM_CRIT("cannot start timer process(es)\n"); goto error; } /* fork all processes required by UDP network layer */ if (udp_start_processes( &chd_rank, startup_done)<0) { LM_CRIT("cannot start TCP processes\n"); goto error; } /* fork all processes required by TCP network layer */ if (tcp_start_processes( &chd_rank, startup_done)<0) { LM_CRIT("cannot start TCP processes\n"); goto error; } } /* this is the main process -> it shouldn't send anything */ bind_address=0; if (startup_done) { if (*startup_done==0) LM_CRIT("BUG: startup route defined, but not run :( \n"); shm_free(startup_done); } /* main process left */ is_main=1; set_proc_attrs("attendant"); if (init_child(PROC_MAIN) < 0) { LM_ERR("error in init_child for PROC_MAIN\n"); report_failure_status(); goto error; } report_conditional_status( (!no_daemon_mode), 0); for(;;) { handle_sigs(); pause(); } /*return 0; */ error: is_main=1; /* if we are here, we are the "main process", any forked children should exit with exit(-1) and not ever use return */ report_conditional_status( (!dont_fork), -1); return -1; }
int main(int argc, char *argv[]) { bool didhelp = false; feature_recorder::set_main_threadid(); #ifdef BROKEN std::cerr << "WARNING: YOU ARE USING AN EXPERIMENTAL VERSION OF TCPFLOW \n"; std::cerr << "THAT DOES NOT WORK PROPERLY. PLEASE USE A RELEASE DOWNLOADED\n"; std::cerr << "FROM http://digitalcorpora.org/downloads/tcpflow\n"; std::cerr << "\n"; #endif bool force_binary_output = false; const char *device = "<default>"; const char *lockname = 0; int need_usage = 0; std::string reportfilename; std::vector<std::string> Rfiles; // files for finishing std::vector<std::string> rfiles; // files to read tcpdemux &demux = *tcpdemux::getInstance(); // the demux object we will be using. std::string command_line = dfxml_writer::make_command_line(argc,argv); std::string opt_unk_packets; bool opt_quiet = false; /* Set up debug system */ progname = argv[0]; init_debug(progname,1); /* Make sure that the system was compiled properly */ if(sizeof(struct be13::ip4)!=20 || sizeof(struct be13::tcphdr)!=20){ fprintf(stderr,"COMPILE ERROR.\n"); fprintf(stderr," sizeof(struct ip)=%d; should be 20.\n", (int)sizeof(struct be13::ip4)); fprintf(stderr," sizeof(struct tcphdr)=%d; should be 20.\n", (int)sizeof(struct be13::tcphdr)); fprintf(stderr,"CANNOT CONTINUE\n"); exit(1); } bool trailing_input_list = false; int arg; while ((arg = getopt(argc, argv, "aA:Bb:cCd:DE:e:E:F:f:Hhi:JlL:m:o:pqR:r:S:sT:Vvw:x:X:Z")) != EOF) { switch (arg) { case 'a': demux.opt.post_processing = true; demux.opt.opt_md5 = true; be13::plugin::scanners_enable_all(); break; case 'A': fprintf(stderr,"-AH has been deprecated. Just use -a\n"); need_usage=true; break; case 'b': demux.opt.max_bytes_per_flow = atoi(optarg); if(debug > 1) { std::cout << "capturing max of " << demux.opt.max_bytes_per_flow << " bytes per flow." << std::endl; } break; case 'B': force_binary_output = true; demux.opt.output_strip_nonprint = false; DEBUG(10) ("converting non-printable characters to '.'"); break; case 'C': demux.opt.console_output = true; DEBUG(10) ("printing packets to console only"); demux.opt.suppress_header = 1; DEBUG(10) ("packet header dump suppressed"); break; case 'c': demux.opt.console_output = true; DEBUG(10) ("printing packets to console only"); break; case 'd': if ((debug = atoi(optarg)) < 0) { debug = DEFAULT_DEBUG_LEVEL; DEBUG(1) ("warning: -d flag with 0 debug level '%s'", optarg); } break; case 'D': demux.opt.output_hex = true;DEBUG(10) ("Console output in hex"); demux.opt.output_strip_nonprint = false; DEBUG(10) ("Will not convert non-printablesto '.'"); break; case 'E': be13::plugin::scanners_disable_all(); be13::plugin::scanners_enable(optarg); break; case 'e': be13::plugin::scanners_enable(optarg); demux.opt.post_processing = true; // enable post processing if anything is turned on break; case 'F': for(const char *cc=optarg;*cc;cc++){ switch(*cc){ case 'c': replace(flow::filename_template,"%c","%C"); break; case 'k': flow::filename_template = "%K/" + flow::filename_template; break; case 'm': flow::filename_template = "%M000-%M999/%M%K/" + flow::filename_template; break; case 'g': flow::filename_template = "%G000000-%G999999/%G%M000-%G%M999/%G%M%K/" + flow::filename_template; break; case 't': flow::filename_template = "%tT" + flow::filename_template; break; case 'T': flow::filename_template = "%T" + flow::filename_template; break; case 'X': demux.opt.store_output = false;break; case 'M': demux.opt.opt_md5 = true;break; default: fprintf(stderr,"-F invalid format specification '%c'\n",*cc); need_usage = true; } } break; case 'f': { int mnew = atoi(optarg); DEBUG(1)("changing max_fds from %d to %d",demux.max_fds,mnew); demux.max_fds = mnew; break; } case 'i': device = optarg; break; case 'J': demux.opt.use_color = 1; DEBUG(10) ("using colors"); break; case 'l': trailing_input_list = true; break; case 'L': lockname = optarg; break; case 'm': demux.opt.max_seek = atoi(optarg); DEBUG(10) ("max_seek set to %d",demux.opt.max_seek); break; case 'o': demux.outdir = optarg; flow::outdir = optarg; break; case 'p': opt_no_promisc = true; DEBUG(10) ("NOT turning on promiscuous mode"); break; case 'q': opt_quiet = true; break; case 'R': Rfiles.push_back(optarg); break; case 'r': rfiles.push_back(optarg); break; case 'S': { std::vector<std::string> params = split(optarg,'='); if(params.size()!=2){ std::cerr << "Invalid paramter: " << optarg << "\n"; exit(1); } be_config.namevals[params[0]] = params[1]; continue; } case 's': demux.opt.output_strip_nonprint = 1; DEBUG(10) ("converting non-printable characters to '.'"); break; case 'T': flow::filename_template = optarg; if(flow::filename_template.find("%c")==string::npos){ flow::filename_template += std::string("%C%c"); // append %C%c if not present } break; case 'V': std::cout << PACKAGE_NAME << " " << PACKAGE_VERSION << "\n"; exit (1); case 'v': debug = 10; break; case 'w': opt_unk_packets = optarg;break; case 'x': be13::plugin::scanners_disable(optarg);break; case 'X': reportfilename = optarg;break; case 'Z': demux.opt.gzip_decompress = 0; break; case 'H': be13::plugin::info_scanners(true,true,scanners_builtin,'e','x'); didhelp = true; break; case 'h': case '?': usage(); didhelp = true; break; default: DEBUG(1) ("error: unrecognized switch '%c'", arg); need_usage = 1; break; } } if(didhelp) exit(0); if(demux.opt.post_processing && !demux.opt.store_output){ std::cerr << "ERROR: post_processing currently requires storing output.\n"; exit(1); } argc -= optind; argv += optind; /* Load all the scanners and enable the ones we care about */ if(demux.opt.opt_md5) be13::plugin::scanners_enable("md5"); be13::plugin::load_scanners(scanners_builtin,be_config); be13::plugin::scanners_process_enable_disable_commands(); /* If there is no report filename, call it report.xml in the output directory */ if( reportfilename.size()==0 ){ reportfilename = demux.outdir + "/" + DEFAULT_REPORT_FILENAME; } /* print help and exit if there was an error in the arguments */ if (need_usage) { usage(); exit(1); } /* remaining arguments are either an input list (-l flag) or a pcap expression (default) */ std::string expression = ""; if(trailing_input_list) { for(int ii = 0; ii < argc; ii++) { rfiles.push_back(argv[ii]); } } else { /* get the user's expression out of remainder of the arg... */ for(int i=0;i<argc;i++){ if(expression.size()>0) expression+=" "; expression += argv[i]; } } /* More option processing */ /* was a semaphore provided for the lock? */ if(lockname){ #if defined(HAVE_SEMAPHORE_H) && defined(HAVE_PTHREAD) semlock = sem_open(lockname,O_CREAT,0777,1); // get the semaphore #else fprintf(stderr,"%s: attempt to create lock pthreads not present\n",argv[0]); exit(1); #endif } if(force_binary_output) demux.opt.output_strip_nonprint = false; /* make sure outdir is a directory. If it isn't, try to make it.*/ struct stat stbuf; if(stat(demux.outdir.c_str(),&stbuf)==0){ if(!S_ISDIR(stbuf.st_mode)){ std::cerr << "outdir is not a directory: " << demux.outdir << "\n"; exit(1); } } else { if(MKDIR(demux.outdir.c_str(),0777)){ std::cerr << "cannot create " << demux.outdir << ": " << strerror(errno) << "\n"; exit(1); } } std::string input_fname; if(rfiles.size() > 0) { input_fname = rfiles.at(0); if(rfiles.size() > 1) { input_fname += ssprintf(" + %d more", rfiles.size() - 1); } } /* report file specified? */ if(reportfilename.size()>0){ xreport = new dfxml_writer(reportfilename,false); dfxml_create(*xreport,command_line); demux.xreport = xreport; } if(opt_unk_packets.size()>0){ if(input_fname.size()==0){ std::cerr << "currently the -w option requires the -r option\n"; exit(1); } if(access(input_fname.c_str(),R_OK)) die("cannot read: %s: %s",input_fname.c_str(),strerror(errno)); demux.save_unk_packets(opt_unk_packets,input_fname); } scanner_info si; si.config = &be_config; /* Debug prefix set? */ std::string debug_prefix=progname; si.get_config("debug-prefix",&debug_prefix,"Prefix for debug output"); init_debug(debug_prefix.c_str(),0); argc -= optind; argv += optind; DEBUG(10) ("%s version %s ", PACKAGE_NAME, PACKAGE_VERSION); feature_file_names_t feature_file_names; be13::plugin::get_scanner_feature_file_names(feature_file_names); feature_recorder_set fs(0); fs.init(feature_file_names,input_fname.size()>0 ? input_fname : device,demux.outdir,0); the_fs = &fs; demux.fs = &fs; si.get_config("tdelta",&datalink_tdelta,"Time offset for packets"); if(demux.xreport) demux.xreport->xmlout("tdelta",datalink_tdelta); /* Process r files and R files */ if(rfiles.size()==0 && Rfiles.size()==0){ /* live capture */ #if defined(HAVE_SETUID) && defined(HAVE_GETUID) /* Since we don't need network access, drop root privileges */ if(setuid(getuid())){ perror("setuid"); } #endif demux.start_new_connections = true; process_infile(expression,device,""); input_fname = device; } else { /* first pick up the new connections with -r */ demux.start_new_connections = true; for(std::vector<std::string>::const_iterator it=rfiles.begin();it!=rfiles.end();it++){ process_infile(expression,device,*it); } /* now pick up the outstanding connection with -R, but don't start new connections */ demux.start_new_connections = false; for(std::vector<std::string>::const_iterator it=Rfiles.begin();it!=Rfiles.end();it++){ process_infile(expression,device,*it); } } /* -1 causes pcap_loop to loop forever, but it finished when the input file is exhausted. */ DEBUG(2)("Open FDs at end of processing: %d",(int)demux.open_flows.size()); DEBUG(2)("demux.max_open_flows: %d",(int)demux.max_open_flows); DEBUG(2)("Flow map size at end of processing: %d",(int)demux.flow_map.size()); DEBUG(2)("Flows seen: %d",(int)demux.flow_counter); demux.close_all_fd(); be13::plugin::phase_shutdown(fs); /* * Note: funny formats below are a result of mingw problems with PRId64. */ const std::string total_flow_processed("Total flows processed: %" PRId64); const std::string total_packets_processed("Total packets processed: %" PRId64); DEBUG(2)(total_flow_processed.c_str(),demux.flow_counter); DEBUG(2)(total_packets_processed.c_str(),demux.packet_counter); if(xreport){ demux.remove_all_flows(); // empty the map to capture the state xreport->add_rusage(); xreport->pop(); // bulk_extractor xreport->close(); delete xreport; } if(demux.flow_counter > tcpdemux::WARN_TOO_MANY_FILES){ if(!opt_quiet){ /* Start counting how many files we have in the output directory. * If we find more than 10,000, print the warning, and keep counting... */ uint64_t filecount=0; DIR *dirp = opendir(demux.outdir.c_str()); if(dirp){ struct dirent *dp=0; while((dp=readdir(dirp))!=NULL){ filecount++; if(filecount==10000){ std::cerr << "*** tcpflow WARNING:\n"; std::cerr << "*** Modern operating systems do not perform well \n"; std::cerr << "*** with more than 10,000 entries in a directory.\n"; std::cerr << "***\n"; } } closedir(dirp); } if(filecount>=10000){ std::cerr << "*** tcpflow created " << filecount << " files in output directory " << demux.outdir << "\n"; std::cerr << "***\n"; std::cerr << "*** Next time, specify command-line options: -Fk , -Fm , or -Fg \n"; std::cerr << "*** This will automatically bin output into subdirectories.\n"; std::cerr << "*** type 'tcpflow -hhh' for more information.\n"; } } } exit(0); // return(0) causes crash on Windows }
void init_all(int argc, char **argv) { cpu_info(); char *config = 0, *bpx = 0, *labels = 0; char opt; while ((opt = getopt(argc, argv, "i:l:b:")) != EOF) switch (opt) { case 'i': config = optarg; break; case 'b': bpx = optarg; break; case 'l': labels = optarg; } temp.Minimized = false; init_z80tables(); init_ie_help(); load_config(config); //make_samples(); #ifdef MOD_GS init_gs(); #endif init_leds(); init_tape(); init_hdd_cd(); start_dx(); init_debug(); applyconfig(); main_reset(); autoload(); init_bpx(bpx); init_labels(labels); temp.Gdiplus = GdiplusStartup(); if (!temp.Gdiplus) { color(CONSCLR_WARNING); printf("warning: gdiplus.dll was not loaded, only SCR and BMP screenshots available\n"); } if (comp.ts.vdac2) { if (!vdac2::open_ft8xx()) { color(CONSCLR_WARNING); printf("warning: ft8xx library was not loaded\n"); comp.ts.vdac2 = false; } } load_errors = 0; trd_toload = 0; *(DWORD*)trd_loaded = 0; // clear loaded flags, don't see autoload'ed images for (; optind < argc; optind++) { char fname[0x200], *temp; GetFullPathName(argv[optind], sizeof fname, fname, &temp); trd_toload = DefaultDrive; // auto-select if (!loadsnap(fname)) errmsg("error loading <%s>", argv[optind]), load_errors = 1; } if (load_errors) { int code = MessageBox(wnd, "Some files, specified in\r\ncommand line, failed to load\r\n\r\nContinue emulation?", "File loading error", MB_YESNO | MB_ICONWARNING); if (code != IDYES) exit(); } SetCurrentDirectory(conf.workdir); // timeBeginPeriod(1); InitializeCriticalSection(&tsu_toggle_cr); }
void kernel_main(unsigned long magic, unsigned long addr) { multiboot_info_t *mbi; terminal_initialize(); init_debug(); if (magic != 0x2BADB002) { panic("booted by non multiboot loader!"); } mbi = (multiboot_info_t *)addr; if (CHECK_FLAG (mbi->flags, 0)) { lower = mbi->mem_lower; upper = mbi->mem_upper; } if (CHECK_FLAG (mbi->flags, 1)) printklog ("[mboot diag] boot_device = 0x%x\n", (unsigned) mbi->boot_device); if (CHECK_FLAG (mbi->flags, 2)) printklog ("[mboot diag] cmdline = %s\n", (char *) mbi->cmdline); if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5)) { panic("[mboot diag] Both bits 4 and 5 are set.\n"); return; } printklog("\n"); if (CHECK_FLAG (mbi->flags, 0)) { mem_all = mbi->mem_lower + mbi->mem_upper + 512 + 1; printklog ("%u KB of memory detected\n", (unsigned) mem_all); } kprintf("start:\t addr: 0x100000\n"); kprintf("head:\tstart: 0x%x\tend: 0x%x\n", (uint32_t) multiboot_start, (uint32_t) multiboot_end); kprintf("text:\tstart: 0x%x\tend: 0x%x\n", (uint32_t) text_start, (uint32_t) text_end); kprintf("rodata:\tstart: 0x%x\tend: 0x%x\n", (uint32_t) rodata_start, (uint32_t) rodata_end); kprintf("data:\tstart: 0x%x\tend: 0x%x\n", (uint32_t) data_start, (uint32_t) data_end); kprintf("common:\tstart: 0x%x\tend: 0x%x\n", (uint32_t) common_start, (uint32_t) common_end); kprintf("bss:\tstart: 0x%x\tend: 0x%x\n", (uint32_t) bss_start, (uint32_t) bss_end); kprintf("stack:\tstart: 0x%x\tend: 0x%x\n", (uint32_t) bootstrap_stack_start, (uint32_t)bootstrap_stack_end); if (CHECK_FLAG (mbi->flags, 5)) { multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec); kprintf("elf:\tstart: 0x%x\tend: 0x%x\n", (uint32_t) multiboot_elf_sec->addr, (uint32_t) (multiboot_elf_sec->addr + multiboot_elf_sec->size)); elf_sec_end = multiboot_elf_sec->addr + multiboot_elf_sec->size; } if (CHECK_FLAG (mbi->flags, 3)) { multiboot_module_t *mod; mod = (multiboot_module_t *) mbi->mods_addr; for(uint32_t i=0;i<mbi->mods_count;i++) { kprintf ("m 0x%x:\tstart: 0x%x\tend: 0x%x\n",(uint32_t) (i+1), (uint32_t) mod->mod_start,(uint32_t) mod->mod_end); modules[i].start = (uint32_t) mod->mod_start; modules[i].end = (uint32_t) mod->mod_end; mod++; } } printklog("\n"); if(mbi->mods_count>0) { kprintf("end: \t addr: 0x%x\n", (uint32_t) modules[(mbi->mods_count)-1].end); kernel_end = modules[(mbi->mods_count)-1].end + 0x1000; } else { kprintf("end: \t addr: 0x%x\n", (uint32_t) elf_sec_end); kernel_end = elf_sec_end + 0x1000; } kernel_end = kernel_end - (kernel_end%0x1000); kprintf("kend: \t addr: 0x%x\n", (uint32_t) kernel_end); init_gdt(); irq_remap(); init_idt(); init_vmm(); asm ("cli"); asm ("sti"); }
/** * Main loop, forks the children, bind to addresses, * handle signals. * \return don't return on sucess, -1 on error */ static int main_loop(void) { static int chd_rank; int i,rc; pid_t pid; struct socket_info* si; int* startup_done = NULL; stat_var *load_p = NULL; chd_rank=0; if (init_debug() != 0) { LM_ERR("failed to init logging levels\n"); goto error; } if (dont_fork){ if (create_status_pipe() < 0) { LM_ERR("failed to create status pipe"); goto error; } if (udp_listen==0){ LM_ERR("no fork mode requires at least one" " udp listen address, exiting...\n"); goto error; } /* only one address, we ignore all the others */ if (udp_init(udp_listen)==-1) goto error; bind_address=udp_listen; sendipv4=bind_address; sendipv6=bind_address; /*FIXME*/ if (udp_listen->next){ LM_WARN("using only the first listen address (no fork)\n"); } /* try to drop privileges */ if (do_suid(uid, gid)==-1) goto error; if (start_module_procs()!=0) { LM_ERR("failed to fork module processes\n"); goto error; } /* we need another process to act as the timer*/ if (start_timer_processes()!=0) { LM_CRIT("cannot start timer process(es)\n"); goto error; } /* main process, receive loop */ set_proc_attrs("stand-alone SIP receiver %.*s", bind_address->sock_str.len, bind_address->sock_str.s ); /* We will call child_init even if we * do not fork - and it will be called with rank 1 because * in fact we behave like a child, not like main process */ if (init_child(1) < 0) { LM_ERR("init_child failed in don't fork\n"); goto error; } if (startup_rlist.a) run_startup_route(); is_main=1; if (register_udp_load_stat(&udp_listen->sock_str, &pt[process_no].load, 1)!=0) { LM_ERR("failed to init udp load statistics\n"); goto error; } clean_write_pipeend(); LM_DBG("waiting for status code from children\n"); rc = wait_for_all_children(); if (rc < 0) { LM_ERR("failed to succesfully init children\n"); return rc; } return udp_rcv_loop(); } else { /* don't fork */ for(si=udp_listen;si;si=si->next){ /* create the listening socket (for each address)*/ /* udp */ if (udp_init(si)==-1) goto error; /* get first ipv4/ipv6 socket*/ if ((si->address.af==AF_INET)&& ((sendipv4==0)||(sendipv4->flags&SI_IS_LO))) sendipv4=si; #ifdef USE_IPV6 if((sendipv6==0)&&(si->address.af==AF_INET6)) sendipv6=si; #endif } #ifdef USE_TCP if (!tcp_disable){ for(si=tcp_listen; si; si=si->next){ /* same thing for tcp */ if (tcp_init(si)==-1) goto error; /* get first ipv4/ipv6 socket*/ if ((si->address.af==AF_INET)& ((sendipv4_tcp==0)||(sendipv4_tcp->flags&SI_IS_LO))) sendipv4_tcp=si; #ifdef USE_IPV6 if((sendipv6_tcp==0)&&(si->address.af==AF_INET6)) sendipv6_tcp=si; #endif } } #ifdef USE_TLS if (!tls_disable){ for(si=tls_listen; si; si=si->next){ /* same as for tcp*/ if (tls_init(si)==-1) goto error; /* get first ipv4/ipv6 socket*/ if ((si->address.af==AF_INET)&& ((sendipv4_tls==0)||(sendipv4_tls->flags&SI_IS_LO))) sendipv4_tls=si; #ifdef USE_IPV6 if((sendipv6_tls==0)&&(si->address.af==AF_INET6)) sendipv6_tls=si; #endif } } #endif /* USE_TLS */ #endif /* USE_TCP */ #ifdef USE_SCTP if (!sctp_disable){ for(si=sctp_listen; si; si=si->next){ /* same thing for sctp */ if (sctp_server_init(si)==-1) goto error; /* get first ipv4/ipv6 socket*/ if ((si->address.af==AF_INET)&& ((sendipv4_sctp==0)||(sendipv4_sctp->flags&SI_IS_LO))) sendipv4_sctp=si; #ifdef USE_IPV6 if((sendipv6_sctp==0)&&(si->address.af==AF_INET6)) sendipv6_sctp=si; #endif } } #endif /* USE_SCTP */ /* all processes should have access to all the sockets (for sending) * so we open all first*/ if (do_suid(uid, gid)==-1) goto error; /* try to drop privileges */ if (start_module_procs()!=0) { LM_ERR("failed to fork module processes\n"); goto error; } if(startup_rlist.a) {/* if a startup route was defined */ startup_done = (int*)shm_malloc(sizeof(int)); if(startup_done == NULL) { LM_ERR("No more shared memory\n"); goto error; } *startup_done = 0; } if (fix_socket_list(&bin) != 0) { LM_ERR("failed to initialize binary interface socket list!\n"); goto error; } /* OpenSIPS <--> OpenSIPS communication interface */ if (bin && start_bin_receivers() != 0) { LM_CRIT("cannot start binary interface receiver processes!\n"); goto error; } /* udp processes */ for(si=udp_listen; si; si=si->next){ if(register_udp_load_stat(&si->sock_str,&load_p,si->children)!=0){ LM_ERR("failed to init load statistics\n"); goto error; } for(i=0;i<si->children;i++){ chd_rank++; if ( (pid=internal_fork( "UDP receiver"))<0 ) { LM_CRIT("cannot fork UDP process\n"); goto error; } else { if (pid==0) { /* new UDP process */ /* set a more detailed description */ set_proc_attrs("SIP receiver %.*s ", si->sock_str.len, si->sock_str.s); bind_address=si; /* shortcut */ if (init_child(chd_rank) < 0) { LM_ERR("init_child failed for UDP listener\n"); if (send_status_code(-1) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); if (chd_rank == 1 && startup_done) *startup_done = -1; exit(-1); } /* first UDP proc runs statup_route (if defined) */ if(chd_rank == 1 && startup_done!=NULL) { LM_DBG("runing startup for first UDP\n"); if(run_startup_route()< 0) { if (send_status_code(-1) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); *startup_done = -1; LM_ERR("Startup route processing failed\n"); exit(-1); } *startup_done = 1; } if (!no_daemon_mode && send_status_code(0) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); /* all UDP listeners on same interface * have same SHM load pointer */ pt[process_no].load = load_p; udp_rcv_loop(); exit(-1); } else { /* wait for first proc to finish the startup route */ if(chd_rank == 1 && startup_done!=NULL) while( !(*startup_done) ) {usleep(5);handle_sigs();} } } } /*parent*/ /*close(udp_sock)*/; /*if it's closed=>sendto invalid fd errors?*/ } } #ifdef USE_SCTP if(!sctp_disable){ for(si=sctp_listen; si; si=si->next){ for(i=0;i<si->children;i++){ chd_rank++; if ( (pid=internal_fork( "SCTP receiver"))<0 ) { LM_CRIT("cannot fork SCTP process\n"); goto error; } else if (pid==0){ /* new SCTP process */ /* set a more detailed description */ set_proc_attrs("SIP receiver %.*s ", si->sock_str.len, si->sock_str.s); bind_address=si; /* shortcut */ if (init_child(chd_rank) < 0) { LM_ERR("init_child failed\n"); if (send_status_code(-1) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); if( (si==sctp_listen && i==0) && startup_done) *startup_done = -1; exit(-1); } /* was startup route executed so far ? if not, run it only by the * first SCTP proc (first proc from first interface) */ if( (si==sctp_listen && i==0) && startup_done!=NULL && *startup_done==0) { LM_DBG("runing startup for first SCTP\n"); if(run_startup_route()< 0) { LM_ERR("Startup route processing failed\n"); if (send_status_code(-1) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); *startup_done = -1; exit(-1); } *startup_done = 1; } if (!no_daemon_mode && send_status_code(0) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); sctp_server_rcv_loop(); exit(-1); } else { /* wait for first proc to finish the startup route */ if( (si==sctp_listen && i==0) && startup_done!=NULL) while( !(*startup_done) ) {usleep(5);handle_sigs();} } } } } #endif /* USE_SCTP */ /* this is the main process -> it shouldn't send anything */ bind_address=0; /* fork for the timer process*/ if (start_timer_processes()!=0) { LM_CRIT("cannot start timer process(es)\n"); goto error; } #ifdef USE_TCP if (!tcp_disable){ /* start tcp & tls receivers */ if (tcp_init_children(&chd_rank, startup_done)<0) goto error; /* wait for the startup route to be executed */ if( startup_done!=NULL) while( !(*startup_done) ) {usleep(5);handle_sigs();} /* start tcp+tls master proc */ if ( (pid=internal_fork( "TCP main"))<0 ) { LM_CRIT("cannot fork tcp main process\n"); goto error; }else if (pid==0){ /* child */ /* close the TCP inter-process sockets */ close(unix_tcp_sock); unix_tcp_sock = -1; close(pt[process_no].unix_sock); pt[process_no].unix_sock = -1; /* init modules */ if (init_child(PROC_TCP_MAIN) < 0) { LM_ERR("error in init_child for tcp main\n"); if (send_status_code(-1) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); exit(-1); } if (!no_daemon_mode && send_status_code(0) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); tcp_main_loop(); exit(-1); } } #endif if (startup_done) { if (*startup_done==0) LM_CRIT("BUG: startup route defined, but not run :( \n"); shm_free(startup_done); } /* main process left */ is_main=1; set_proc_attrs("attendant"); if (init_child(PROC_MAIN) < 0) { if (send_status_code(-1) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); LM_ERR("error in init_child for PROC_MAIN\n"); goto error; } if (!no_daemon_mode && send_status_code(0) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); for(;;){ handle_sigs(); pause(); } /*return 0; */ error: is_main=1; /* if we are here, we are the "main process", any forked children should exit with exit(-1) and not ever use return */ if (!dont_fork && send_status_code(-1) < 0) LM_ERR("failed to send status code\n"); clean_write_pipeend(); return -1; }
static __devinit int depl_probe(struct platform_device *pdev) { struct depl_driver *drv; struct edp_manager *m; struct edp_client *c; int r = -EFAULT; if (!pdev->dev.platform_data) return -EINVAL; m = edp_get_manager("battery"); if (!m) { dev_err(&pdev->dev, "could not get EDP manager\n"); return -ENODEV; } drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); if (!drv) return -ENOMEM; drv->pdata = pdev->dev.platform_data; drv->manager = m; drv->psy = power_supply_get_by_name(drv->pdata->power_supply); if (!drv->psy) { if (!drv->pdata->ocv_lut) goto fail; drv->capacity = 100; drv->emulator_mode = true; } r = depl_init_ocv_reader(drv); if (r) goto fail; c = &drv->client; strncpy(c->name, "depletion", EDP_NAME_LEN - 1); c->name[EDP_NAME_LEN - 1] = 0; c->priority = EDP_MAX_PRIO; c->throttle = depl_edp_callback; c->notify_promotion = depl_edp_callback; c->states = drv->pdata->states; c->num_states = drv->pdata->num_states; c->e0_index = drv->pdata->e0_index; r = edp_register_client(m, c); if (r) { dev_err(&pdev->dev, "failed to register: %d\n", r); goto fail; } platform_set_drvdata(pdev, drv); INIT_DELAYED_WORK_DEFERRABLE(&drv->work, depl_update); schedule_delayed_work(&drv->work, 0); if (drv->emulator_mode) init_debug(drv); return 0; fail: devm_kfree(&pdev->dev, drv); return r; }