int main(){ /*uint8_t status = 1; CTRL ^= 3 << LEDFLASH_MODE; while(1){ sys_wdt_rst(0); nand_rst(); nand_set_ecc(1); sys_delay_ms(1); }*/ /*uint8_t tmpbuf[32], nullbuf[32]; uint32_t t; for(uint8_t i = 0; i < 32; i++) tmpbuf[i] = i, nullbuf[i] = 0; CTRL ^= LEDFLASH_MODE_MASK; while(1){ t = TIMER; for(uint8_t i = 0; i < 16; i++) spimem_write(0, 32, tmpbuf), spimem_write(0,32,nullbuf); //32 writes sys_uart_printdec(TIMER-t); sys_uart_write(' '); sys_wdt_rst(1); }*/ //sys_signal_startup(); sys_init(); sys_wdt_rst(0); sys_delay_ms(1000); sys_wdt_rst(1); sys_delay_ms(1000); sys_wdt_rst(1); /*CTRL |= ITIMER_MODE_MASK; ITIMER = 32766; set_interrupt_mask(IE_ITIMER_MASK | IE_LOW_BATT_MASK);*/ //set_interrupt_mask(IE_LOW_BATT_MASK); dock_on_start(); // if(SFLAG(WD_FLAG_MASK) && !SFLAG(LUP_FLAG_MASK)) sys_uart_printstr("WDr"); // if(SFLAG(WD_FLAG_MASK | LUP_FLAG_MASK)) sys_uart_printstr("LCKr"); jpeg_init(); sys_signal_startup(); //selftest(); //WARNING!!!!! //sys_failure(SYS_FAILURE_SENSOR_CHECK, 0); while(1){ exec_sign ^= 0x1; //action sensor_grab(1); frame_cnt++; if(diff_use() == 0) monitor_jpeg_to_dest(cur_mode.q_table, 2, 0), saved_frame_cnt++; else exec_sign ^= 0x1F00; //service stat_mode_on_loop(); stat_on_loop(); sys_wdt_rst(1); monitor_loop(); //delay sys_delay_fps(); sys_check_exec_signature(); } return 0; }
DWORD server_setup(SOCKET fd) { Remote *remote = NULL; DWORD res = 0; #ifdef _UNIX int local_error = 0; #endif // if hAppInstance is still == NULL it means that we havent been // reflectivly loaded so we must patch in the hAppInstance value // for use with loading server extensions later. InitAppInstance(); srand((unsigned int)time(NULL)); __try { do { if (!(remote = remote_allocate(fd))) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); break; } // Do not allow the file descriptor to be inherited by child // processes SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0); // Flush the socket handle dprintf("Flushing the socket handle..."); flush_socket(remote); // Initialize SSL on the socket dprintf("Negotiating SSL..."); negotiate_ssl(remote); // Register extension dispatch routines dprintf("Registering dispatch routines..."); register_dispatch_routines(); dprintf("Entering the monitor loop..."); // Keep processing commands res = monitor_loop(remote); dprintf("Deregistering dispatch routines..."); // Clean up our dispatch routines deregister_dispatch_routines(); } while (0); dprintf("Closing down SSL..."); SSL_free(remote->ssl); SSL_CTX_free(remote->ctx); if (remote) remote_deallocate(remote); } /* Invoke the fatal error handler */ __except(exceptionfilter(GetExceptionCode(), GetExceptionInformation())) { dprintf("*** exception triggered!"); ExitThread(0); } return res; }
int main (int argc, char **argv, char **env) { struct stat stat_buf; #else int main (int argc, char **argv) { #endif int sid, x; #ifdef EMBEDDEDPERL start_env=env; #endif last_time_increased = 0; /* store the original command line for later reloads */ store_original_comandline(argc, argv); /* * allocate options structure * and parse command line */ mod_gm_opt = gm_malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); if(parse_arguments(argc, argv) != GM_OK) { exit( EXIT_FAILURE ); } #ifdef EMBEDDEDPERL /* make sure the P1 file exists... */ if(p1_file==NULL){ gm_log(GM_LOG_ERROR,"Error: p1.pl file required for embedded Perl interpreter is not set!\n"); exit( EXIT_FAILURE ); } if(stat(p1_file,&stat_buf)!=0){ gm_log(GM_LOG_ERROR,"Error: p1.pl file required for embedded Perl interpreter is missing!\n"); perror("stat"); exit( EXIT_FAILURE ); } #endif /* fork into daemon mode? */ if(mod_gm_opt->daemon_mode == GM_ENABLED) { pid_t pid = fork(); /* an error occurred while trying to fork */ if(pid == -1) { perror("fork"); exit( EXIT_FAILURE ); } /* we are the child process */ else if(pid == 0) { gm_log( GM_LOG_INFO, "mod_gearman worker daemon started with pid %d\n", getpid()); /* Create a new SID for the child process */ sid = setsid(); if ( sid < 0 ) { mod_gm_free_opt(mod_gm_opt); exit( EXIT_FAILURE ); } /* Close out the standard file descriptors */ if(mod_gm_opt->debug_level <= 1) { close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); } } /* we are the parent. So forking into daemon mode worked */ else { mod_gm_free_opt(mod_gm_opt); exit( EXIT_SUCCESS ); } } else { gm_log( GM_LOG_INFO, "mod_gearman worker started with pid %d\n", getpid()); } /* print some version information */ gm_log( GM_LOG_DEBUG, "Version %s\n", GM_VERSION ); gm_log( GM_LOG_DEBUG, "running on libgearman %s\n", gearman_version() ); /* set signal handlers for a clean exit */ signal(SIGINT, clean_exit); signal(SIGTERM,clean_exit); signal(SIGHUP, reload_config); signal(SIGPIPE, SIG_IGN); /* check and write pid file */ if(write_pid_file() != GM_OK) { exit(EXIT_FAILURE); } /* init crypto functions */ if(mod_gm_opt->encryption == GM_ENABLED) { mod_gm_crypt_init(mod_gm_opt->crypt_key); } else { mod_gm_opt->transportmode = GM_ENCODE_ONLY; } gm_log( GM_LOG_DEBUG, "main process started\n"); /* start a single non forked standalone worker */ if(mod_gm_opt->debug_level >= 10) { gm_log( GM_LOG_TRACE, "starting standalone worker\n"); #ifdef EMBEDDEDPERL worker_client(GM_WORKER_STANDALONE, 1, shmid, start_env); #else worker_client(GM_WORKER_STANDALONE, 1, shmid); #endif exit(EXIT_SUCCESS); } /* setup shared memory */ setup_child_communicator(); /* start status worker */ make_new_child(GM_WORKER_STATUS); /* setup children */ for(x=0; x < mod_gm_opt->min_worker; x++) { make_new_child(GM_WORKER_MULTI); } /* maintain worker population */ monitor_loop(); gm_log( GM_LOG_ERROR, "worker exited from main loop\n"); clean_exit(15); exit( EXIT_SUCCESS ); }
int main(int argc, char **argv) { struct pqos_config cfg; const struct pqos_cpuinfo *p_cpu = NULL; const struct pqos_cap *p_cap = NULL; const struct pqos_capability *cap_mon = NULL, *cap_l3ca = NULL; unsigned sock_count, sockets[PQOS_MAX_SOCKETS]; int cmd, ret, exit_val = EXIT_SUCCESS; int opt_index = 0; m_cmd_name = argv[0]; print_warning(); while ((cmd = getopt_long(argc, argv, "Hhf:i:m:Tt:l:o:u:e:c:a:p:S:srvVR", long_cmd_opts, &opt_index)) != -1) { switch (cmd) { case 'h': print_help(1); return EXIT_SUCCESS; case 'H': profile_l3ca_list(stdout); return EXIT_SUCCESS; case 'S': selfn_set_config(optarg); break; case 'f': if (sel_config_file != NULL) { printf("Only one config file argument is " "accepted!\n"); return EXIT_FAILURE; } selfn_strdup(&sel_config_file, optarg); parse_config_file(sel_config_file); break; case 'i': selfn_monitor_interval(optarg); break; case 'p': selfn_monitor_pids(optarg); break; case 'm': selfn_monitor_cores(optarg); break; case 't': selfn_monitor_time(optarg); break; case 'T': selfn_monitor_top_like(NULL); break; case 'l': selfn_log_file(optarg); break; case 'o': selfn_monitor_file(optarg); break; case 'u': selfn_monitor_file_type(optarg); break; case 'e': selfn_allocation_class(optarg); break; case 'r': sel_free_in_use_rmid = 1; break; case 'R': selfn_reset_cat(NULL); break; case 'a': selfn_allocation_assoc(optarg); break; case 'c': selfn_allocation_select(optarg); break; case 's': selfn_show_allocation(NULL); break; case 'v': selfn_verbose_mode(NULL); break; case 'V': selfn_super_verbose_mode(NULL); break; default: printf("Unsupported option: -%c. " "See option -h for help.\n", optopt); return EXIT_FAILURE; break; case '?': print_help(0); return EXIT_SUCCESS; break; } } memset(&cfg, 0, sizeof(cfg)); cfg.verbose = sel_verbose_mode; cfg.free_in_use_rmid = sel_free_in_use_rmid; cfg.cdp_cfg = selfn_cdp_config; /** * Set up file descriptor for message log */ if (sel_log_file == NULL) { cfg.fd_log = STDOUT_FILENO; } else { cfg.fd_log = open(sel_log_file, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); if (cfg.fd_log == -1) { printf("Error opening %s log file!\n", sel_log_file); exit_val = EXIT_FAILURE; goto error_exit_2; } } ret = pqos_init(&cfg); if (ret != PQOS_RETVAL_OK) { printf("Error initializing PQoS library!\n"); exit_val = EXIT_FAILURE; goto error_exit_1; } ret = pqos_cap_get(&p_cap, &p_cpu); if (ret != PQOS_RETVAL_OK) { printf("Error retrieving PQoS capabilities!\n"); exit_val = EXIT_FAILURE; goto error_exit_2; } ret = pqos_cpu_get_sockets(p_cpu, PQOS_MAX_SOCKETS, &sock_count, sockets); if (ret != PQOS_RETVAL_OK) { printf("Error retrieving CPU socket information!\n"); exit_val = EXIT_FAILURE; goto error_exit_2; } ret = pqos_cap_get_type(p_cap, PQOS_CAP_TYPE_MON, &cap_mon); if (ret == PQOS_RETVAL_PARAM) { printf("Error retrieving monitoring capabilities!\n"); exit_val = EXIT_FAILURE; goto error_exit_2; } ret = pqos_cap_get_type(p_cap, PQOS_CAP_TYPE_L3CA, &cap_l3ca); if (ret == PQOS_RETVAL_PARAM) { printf("Error retrieving allocation capabilities!\n"); exit_val = EXIT_FAILURE; goto error_exit_2; } if (sel_reset_CAT) { /** * Reset CAT configuration to after-reset state and exit */ if (pqos_l3ca_reset(p_cap, p_cpu) != PQOS_RETVAL_OK) { exit_val = EXIT_FAILURE; printf("CAT reset failed!\n"); } else printf("CAT reset successful\n"); goto allocation_exit; } if (sel_show_allocation_config) { /** * Show info about allocation config and exit */ alloc_print_config(cap_mon, cap_l3ca, sock_count, sockets, p_cpu); goto allocation_exit; } if (sel_allocation_profile != NULL) { if (profile_l3ca_apply(sel_allocation_profile, cap_l3ca) != 0) { exit_val = EXIT_FAILURE; goto error_exit_2; } } switch (alloc_apply(cap_l3ca, sock_count, sockets)) { case 0: /* nothing to apply */ break; case 1: /* new allocation config applied and all is good */ goto allocation_exit; break; case -1: /* something went wrong */ default: exit_val = EXIT_FAILURE; goto error_exit_2; break; } /** * Just monitoring option left on the table now */ if (cap_mon == NULL) { printf("Monitoring capability not detected!\n"); exit_val = EXIT_FAILURE; goto error_exit_2; } if (monitor_setup(p_cpu, cap_mon) != 0) { exit_val = EXIT_FAILURE; goto error_exit_2; } monitor_loop(p_cap); monitor_stop(); allocation_exit: error_exit_2: ret = pqos_fini(); ASSERT(ret == PQOS_RETVAL_OK); if (ret != PQOS_RETVAL_OK) printf("Error shutting down PQoS library!\n"); error_exit_1: monitor_cleanup(); /** * Close file descriptor for message log */ if (cfg.fd_log > 0 && cfg.fd_log != STDOUT_FILENO) close(cfg.fd_log); /** * Free allocated memory */ if (sel_allocation_profile != NULL) free(sel_allocation_profile); if (sel_log_file != NULL) free(sel_log_file); if (sel_config_file != NULL) free(sel_config_file); return exit_val; }
int main(int argc, char **argv) { extern char *__progname; char *cfgfile = 0; int ch; if (geteuid() != 0) { /* No point in continuing. */ fprintf(stderr, "%s: This daemon needs to be run as root.\n", __progname); return 1; } while ((ch = getopt(argc, argv, "c:dv")) != -1) { switch (ch) { case 'c': if (cfgfile) usage(); cfgfile = optarg; break; case 'd': cfgstate.debug++; break; case 'v': cfgstate.verboselevel++; break; default: usage(); } } argc -= optind; argv += optind; if (argc > 0) usage(); log_init(__progname); timer_init(); cfgstate.runstate = INIT; LIST_INIT(&cfgstate.peerlist); cfgstate.listen_port = SASYNCD_DEFAULT_PORT; cfgstate.flags |= CTL_DEFAULT; if (!cfgfile) cfgfile = SASYNCD_CFGFILE; if (conf_parse_file(cfgfile) == 0 ) { if (!cfgstate.sharedkey) { fprintf(stderr, "config: " "no shared key specified, cannot continue"); exit(1); } } else { exit(1); } carp_demote(CARP_INC, 0); if (carp_init()) return 1; if (pfkey_init(0)) return 1; if (net_init()) return 1; if (!cfgstate.debug) if (daemon(1, 0)) { perror("daemon()"); exit(1); } if (monitor_init()) { /* Parent, with privileges. */ monitor_loop(); exit(0); } /* Child, no privileges left. Run main loop. */ sasyncd_run(getppid()); /* Shutdown. */ log_msg(0, "shutting down..."); net_shutdown(); pfkey_shutdown(); return 0; }
int main(int argc, char *argv[]) { fd_set *rfds, *wfds; int n, m; size_t mask_size; struct timeval tv, *timeout; closefrom(STDERR_FILENO + 1); /* * Make sure init() won't alloc fd 0, 1 or 2, as daemon() will close * them. */ for (n = 0; n <= 2; n++) if (fcntl(n, F_GETFL, 0) == -1 && errno == EBADF) (void) open("/dev/null", n ? O_WRONLY : O_RDONLY, 0); /* Log cmd line parsing and initialization errors to stderr. */ log_to(stderr); parse_args(argc, argv); log_init(debug); log_print("isakmpd: starting"); /* Open protocols and services databases. */ setprotoent(1); setservent(1); /* Open command fifo */ ui_init(); set_slave_signals(); /* Daemonize before forking unpriv'ed child */ if (!debug) if (daemon(0, 0)) log_fatal("main: daemon (0, 0) failed"); /* Set timezone before priv'separation */ tzset(); write_pid_file(); if (monitor_init(debug)) { /* The parent, with privileges enters infinite monitor loop. */ monitor_loop(debug); exit(0); /* Never reached. */ } /* Child process only from this point on, no privileges left. */ init(); /* If we wanted IKE packet capture to file, initialize it now. */ if (pcap_file != 0) log_packet_init(pcap_file); /* Allocate the file descriptor sets just big enough. */ n = getdtablesize(); mask_size = howmany(n, NFDBITS) * sizeof(fd_mask); rfds = (fd_set *) malloc(mask_size); if (!rfds) log_fatal("main: malloc (%lu) failed", (unsigned long)mask_size); wfds = (fd_set *) malloc(mask_size); if (!wfds) log_fatal("main: malloc (%lu) failed", (unsigned long)mask_size); monitor_init_done(); while (1) { /* If someone has sent SIGHUP to us, reconfigure. */ if (sighupped) { sighupped = 0; log_print("SIGHUP received"); reinit(); } /* and if someone sent SIGUSR1, do a state report. */ if (sigusr1ed) { sigusr1ed = 0; log_print("SIGUSR1 received"); report(); } /* * and if someone set 'sigtermed' (SIGTERM, SIGINT or via the * UI), this indicates we should start a controlled shutdown * of the daemon. * * Note: Since _one_ message is sent per iteration of this * enclosing while-loop, and we want to send a number of * DELETE notifications, we must loop atleast this number of * times. The daemon_shutdown() function starts by queueing * the DELETEs, all other calls just increments the * 'sigtermed' variable until it reaches a "safe" value, and * the daemon exits. */ if (sigtermed) daemon_shutdown(); /* Setup the descriptors to look for incoming messages at. */ bzero(rfds, mask_size); n = transport_fd_set(rfds); FD_SET(ui_socket, rfds); if (ui_socket + 1 > n) n = ui_socket + 1; /* * XXX Some day we might want to deal with an abstract * application class instead, with many instantiations * possible. */ if (!app_none && app_socket >= 0) { FD_SET(app_socket, rfds); if (app_socket + 1 > n) n = app_socket + 1; } /* Setup the descriptors that have pending messages to send. */ bzero(wfds, mask_size); m = transport_pending_wfd_set(wfds); if (m > n) n = m; /* Find out when the next timed event is. */ timeout = &tv; timer_next_event(&timeout); n = select(n, rfds, wfds, 0, timeout); if (n == -1) { if (errno != EINTR) { log_error("main: select"); /* * In order to give the unexpected error * condition time to resolve without letting * this process eat up all available CPU * we sleep for a short while. */ sleep(1); } } else if (n) { transport_handle_messages(rfds); transport_send_messages(wfds); if (FD_ISSET(ui_socket, rfds)) ui_handler(); if (!app_none && app_socket >= 0 && FD_ISSET(app_socket, rfds)) app_handler(); } timer_handle_expirations(); } }
int main (int argc, char *argv[]) { fd_set *rfds, *wfds; int n, m; size_t mask_size; struct timeval tv, *timeout; /* Make sure init() won't alloc fd 0, 1 or 2, as daemon() will close them. */ for (n = 0; n <= 2; n++) if (fcntl (n, F_GETFL, 0) == -1 && errno == EBADF) (void)open ("/dev/null", n ? O_WRONLY : O_RDONLY, 0); /* Log cmd line parsing and initialization errors to stderr. */ log_to (stderr); parse_args (argc, argv); log_init (); /* Do a clean daemon shutdown on TERM reception. (Needed by monitor). */ signal (SIGTERM, daemon_shutdown_now); if (debug) signal (SIGINT, daemon_shutdown_now); #if defined (USE_PRIVSEP) if (monitor_init ()) { /* The parent, with privileges. */ if (!debug) if (daemon (0, 0)) log_fatal ("main [priv]: daemon (0, 0) failed"); /* Enter infinite monitor loop. */ monitor_loop (debug); exit (0); /* Never reached. */ } /* Child process only from this point on, no privileges left. */ #endif init (); if (!debug) { if (daemon (0, 0)) log_fatal ("main: daemon (0, 0) failed"); /* Switch to syslog. */ log_to (0); } write_pid_file (); /* Reinitialize on HUP reception. */ signal (SIGHUP, sighup); /* Report state on USR1 reception. */ signal (SIGUSR1, sigusr1); /* Rehash soft expiration timers on USR2 reception. */ signal (SIGUSR2, sigusr2); #if defined (USE_DEBUG) /* If we wanted IKE packet capture to file, initialize it now. */ if (pcap_file != 0) log_packet_init (pcap_file); #endif /* Allocate the file descriptor sets just big enough. */ n = getdtablesize (); mask_size = howmany (n, NFDBITS) * sizeof (fd_mask); rfds = (fd_set *)malloc (mask_size); if (!rfds) log_fatal ("main: malloc (%lu) failed", (unsigned long)mask_size); wfds = (fd_set *)malloc (mask_size); if (!wfds) log_fatal ("main: malloc (%lu) failed", (unsigned long)mask_size); while (1) { /* If someone has sent SIGHUP to us, reconfigure. */ if (sighupped) { log_print ("SIGHUP received"); reinit (); sighupped = 0; } /* and if someone sent SIGUSR1, do a state report. */ if (sigusr1ed) { log_print ("SIGUSR1 received"); report (); } /* and if someone sent SIGUSR2, do a timer rehash. */ if (sigusr2ed) { log_print ("SIGUSR2 received"); rehash_timers (); } /* * and if someone set 'sigtermed' (SIGTERM or via the UI), this * indicated we should start a shutdown of the daemon. * * Note: Since _one_ message is sent per iteration of this enclosing * while-loop, and we want to send a number of DELETE notifications, * we must loop atleast this number of times. The daemon_shutdown() * function starts by queueing the DELETEs, all other calls just * increments the 'sigtermed' variable until it reaches a "safe" * value, and the daemon exits. */ if (sigtermed) daemon_shutdown (); /* Setup the descriptors to look for incoming messages at. */ memset (rfds, 0, mask_size); n = transport_fd_set (rfds); FD_SET (ui_socket, rfds); if (ui_socket + 1 > n) n = ui_socket + 1; /* * XXX Some day we might want to deal with an abstract application * class instead, with many instantiations possible. */ if (!app_none && app_socket >= 0) { FD_SET (app_socket, rfds); if (app_socket + 1 > n) n = app_socket + 1; } /* Setup the descriptors that have pending messages to send. */ memset (wfds, 0, mask_size); m = transport_pending_wfd_set (wfds); if (m > n) n = m; /* Find out when the next timed event is. */ timeout = &tv; timer_next_event (&timeout); n = select (n, rfds, wfds, 0, timeout); if (n == -1) { if (errno != EINTR) { log_error ("select"); /* * In order to give the unexpected error condition time to * resolve without letting this process eat up all available CPU * we sleep for a short while. */ sleep (1); } } else if (n) { transport_handle_messages (rfds); transport_send_messages (wfds); if (FD_ISSET (ui_socket, rfds)) ui_handler (); if (!app_none && app_socket >= 0 && FD_ISSET (app_socket, rfds)) app_handler (); } timer_handle_expirations (); } }