/* * plmysql_init - initalize a MYSQL database. * Return NULL on failure, or a PLMYSQL * on success. */ static PLMYSQL *plmysql_init(char *hostnames[], int len_hosts) { PLMYSQL *PLDB; int i; if ((PLDB = (PLMYSQL *) mymalloc(sizeof(PLMYSQL))) == NULL) { msg_fatal("mymalloc of pldb failed"); } PLDB->len_hosts = len_hosts; if ((PLDB->db_hosts = (HOST **) mymalloc(sizeof(HOST *) * len_hosts)) == NULL) return NULL; for (i = 0; i < len_hosts; i++) { PLDB->db_hosts[i] = host_init(hostnames[i]); } return PLDB; }
/* * plmysql_init - initalize a MYSQL database. * Return NULL on failure, or a PLMYSQL * on success. */ static PLMYSQL *plmysql_init(ARGV *hosts) { PLMYSQL *PLDB; int i; if ((PLDB = (PLMYSQL *) mymalloc(sizeof(PLMYSQL))) == 0) msg_fatal("mymalloc of pldb failed"); PLDB->len_hosts = hosts->argc; if ((PLDB->db_hosts = (HOST **) mymalloc(sizeof(HOST *) * hosts->argc)) == 0) return (0); for (i = 0; i < hosts->argc; i++) PLDB->db_hosts[i] = host_init(hosts->argv[i]); return PLDB; }
/* lpCmdLine: command line args as a single string with program name and leading whitespace excluded */ int32 WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { globalInstance = hInstance; // This is pass by value. lpCmdLine is unchanged in this context COM_ParseCmdLine(lpCmdLine); // Call init code host_init(); // Initialize the timer float oldtime = sys_initFloatTime(); while (isRunning) { // Get a new value from the initialized timer float newtime = sys_floatTime(); // Separate out update and rendering logic host_frame(newtime - oldtime); // Better to use subtractive tracking of time // No lost frames on each iteration due to floating point precision oldtime = newtime; /* // DEBUG char buf[64]; sprintf_s(buf, 64, "Total time: %3.7f \n", newtime); OutputDebugString(buf); */ } // Shutdown code host_shutdown(); #if _DEBUG _CrtDumpMemoryLeaks(); #endif return 0; }
int main(int argc, char **argv) { static char *ifname = NULL; /* Name of interface to attach to */ fd_set rfds, readers; int n, nfds = 0, i; int daemonize = 0; struct timeval *timeout; struct timespec timeout_spec; struct sigaction sigact; sigset_t mask, origmask; /* Remember the name of the executable... */ progname = strrchr(argv[0], '/'); if (progname) progname++; else progname = argv[0]; /* Use debug output as default */ debug = 1; memset (&sigact, 0, sizeof(struct sigaction)); sigact.sa_handler = signal_handler; /* This server should shut down on these signals. */ sigaction(SIGTERM, &sigact, 0); sigaction(SIGHUP, &sigact, 0); sigaction(SIGINT, &sigact, 0); sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGHUP); sigaddset(&mask, SIGINT); /* Only capture segmentation faults when we are not debugging... */ #ifndef DEBUG sigaddset(&mask, SIGSEGV); #endif /* Block the signals we are watching here so that we can * handle them in pselect instead. */ sigprocmask(SIG_BLOCK, &mask, &origmask); /* Parse command line: */ while (1) { int opt; opt = getopt_long(argc, argv, "i:fjln:dghoq:r:s:c:uwxDLRV", longopts, 0); if (opt == EOF) break; switch (opt) { case 0: break; case 'd': debug = 0; daemonize = 1; break; case 'f': llfeedback = 1; active_route_timeout = ACTIVE_ROUTE_TIMEOUT_LLF; break; case 'g': rreq_gratuitous = !rreq_gratuitous; break; case 'i': ifname = optarg; break; case 'j': hello_jittering = !hello_jittering; break; case 'l': log_to_file = !log_to_file; break; case 'n': if (optarg && isdigit(*optarg)) { receive_n_hellos = atoi(optarg); if (receive_n_hellos < 2) { fprintf(stderr, "-n should be at least 2!\n"); exit(-1); } } break; case 'o': optimized_hellos = !optimized_hellos; break; case 'q': if (optarg && isdigit(*optarg)) qual_threshold = atoi(optarg); break; case 'r': if (optarg && isdigit(*optarg)) rt_log_interval = atof(optarg) * 1000; break; case 's': if (optarg && isdigit(*optarg)) inet_aton(optarg, &server_addr); break; case 'c': if (optarg && isdigit(*optarg)) { node_discovery_mode = !node_discovery_mode; discovery_internal = atof(optarg) * 1000 * 60; } break; case 'u': unidir_hack = !unidir_hack; break; case 'w': internet_gw_mode = !internet_gw_mode; break; case 'x': expanding_ring_search = !expanding_ring_search; break; case 'L': local_repair = !local_repair; break; case 'D': wait_on_reboot = !wait_on_reboot; break; case 'R': ratelimit = !ratelimit; break; case 'V': printf ("\nAODV-UU v%s, %s © Uppsala University & Ericsson AB.\nAuthor: Erik Nordström, <*****@*****.**>\n\n", AODV_UU_VERSION, DRAFT_VERSION); exit(0); break; case '?': case ':': exit(0); default: usage(0); } } /* Check that we are running as root */ if (geteuid() != 0) { fprintf(stderr, "must be root\n"); exit(1); } /* Detach from terminal */ if (daemonize) { if (fork() != 0) exit(0); /* Close stdin, stdout and stderr... */ /* close(0); */ close(1); close(2); setsid(); } /* Make sure we cleanup at exit... */ atexit((void *) &cleanup); /* Initialize data structures and services... */ rt_table_init(); log_init(); /* packet_queue_init(); */ host_init(ifname); /* packet_input_init(); */ nl_init(); nl_send_conf_msg(); aodv_socket_init(); #ifdef LLFEEDBACK if (llfeedback) { llf_init(); } #endif /* Set sockets to watch... */ FD_ZERO(&readers); for (i = 0; i < nr_callbacks; i++) { FD_SET(callbacks[i].fd, &readers); if (callbacks[i].fd >= nfds) nfds = callbacks[i].fd + 1; } /* Set the wait on reboot timer... */ if (wait_on_reboot) { timer_init(&worb_timer, wait_on_reboot_timeout, &wait_on_reboot); timer_set_timeout(&worb_timer, DELETE_PERIOD); alog(LOG_NOTICE, 0, __FUNCTION__, "In wait on reboot for %d milliseconds. Disable with \"-D\".", DELETE_PERIOD); } if(node_discovery_mode && internet_gw_mode) { timer_init(&discovery_timer, node_discovery_timeout, NULL); timer_set_timeout(&discovery_timer, discovery_internal); DEBUG(LOG_DEBUG, 0, "This is gateway and set with node discovery\n"); } /* Schedule the first Hello */ if (!optimized_hellos && !llfeedback) hello_start(); if (rt_log_interval) log_rt_table_init(); while (1) { memcpy((char *) &rfds, (char *) &readers, sizeof(rfds)); timeout = timer_age_queue(); timeout_spec.tv_sec = timeout->tv_sec; timeout_spec.tv_nsec = timeout->tv_usec * 1000; if ((n = pselect(nfds, &rfds, NULL, NULL, &timeout_spec, &origmask)) < 0) { if (errno != EINTR) alog(LOG_WARNING, errno, __FUNCTION__, "Failed select (main loop)"); continue; } if (n > 0) { for (i = 0; i < nr_callbacks; i++) { if (FD_ISSET(callbacks[i].fd, &rfds)) { /* We don't want any timer SIGALRM's while executing the callback functions, therefore we block the timer... */ (*callbacks[i].func) (callbacks[i].fd); } } } } /* Main loop */ return 0; }
int host_parse(dig_params_t *params, int argc, char *argv[]) { int opt = 0; if (params == NULL || argv == NULL) { DBG_NULL; return KNOT_EINVAL; } if (host_init(params) != KNOT_EOK) { return KNOT_ERROR; } query_t *conf = params->config; uint16_t rclass, rtype; uint32_t serial; // Command line options processing. while ((opt = getopt(argc, argv, "46adrsTvwc:t:R:W:")) != -1) { switch (opt) { case '4': conf->ip = IP_4; break; case '6': conf->ip = IP_6; break; case 'a': conf->type_num = KNOT_RRTYPE_ANY; conf->style.format = FORMAT_FULL; conf->style.show_header = true; conf->style.show_edns = true; conf->style.show_footer = true; break; case 'd': msg_enable_debug(1); break; case 'r': conf->flags.rd_flag = false; break; case 's': conf->servfail_stop = true; break; case 'T': conf->protocol = PROTO_TCP; break; case 'v': conf->style.format = FORMAT_FULL; conf->style.show_header = true; conf->style.show_edns = true; conf->style.show_footer = true; break; case 'w': conf->wait = -1; break; case 'c': if (params_parse_class(optarg, &rclass) != KNOT_EOK) { ERR("bad class %s\n", optarg); return KNOT_EINVAL; } conf->class_num = rclass; break; case 't': if (params_parse_type(optarg, &rtype, &serial) != KNOT_EOK) { ERR("bad type %s\n", optarg); return KNOT_EINVAL; } conf->type_num = rtype; conf->xfr_serial = serial; break; case 'R': if (params_parse_num(optarg, &conf->retries) != KNOT_EOK) { return KNOT_EINVAL; } break; case 'W': if (params_parse_wait(optarg, &conf->wait) != KNOT_EOK) { return KNOT_EINVAL; } break; default: host_help(argc, argv); return KNOT_ENOTSUP; } } // Process non-option parameters. switch (argc - optind) { case 2: if (params_parse_server(argv[optind + 1], &conf->servers, conf->port) != KNOT_EOK) { return KNOT_EINVAL; } case 1: // Fall through. if (parse_name(argv[optind], ¶ms->queries, conf) != KNOT_EOK) { return KNOT_EINVAL; } break; default: host_help(argc, argv); return KNOT_ENOTSUP; } // Complete missing data in queries based on defaults. complete_queries(¶ms->queries, params->config); return KNOT_EOK; }
int main (int argc, char **argv) { static char *ifname = NULL; /* Name of interface to attach to */ fd_set rfds, readers; int n, nfds = 0, i; int daemonize = 0; /* Remember the name of the executable... */ progname = strrchr(argv[0], '/'); if (progname) progname++; else progname = argv[0]; /* Use debug output as default */ debug = 1; /* Parse command line: */ argc--; argv++; while(argc) { if(argv[0][0] == '-') { switch(argv[0][1]) { case 'i': if(argv[1] != NULL) { ifname = argv[1]; argc--; argv++; break; } print_usage(); exit(-1); case 'd': debug = 0; daemonize = 1; break; case 'l': log_to_file = 1; break; case 'u': unidir_hack = 1; break; case 'g': rreq_gratuitous = 1; break; case 't': log_rt_table = 1; if(argv[1] != NULL && argv[1][0] != '-') { printf("arg: %d\n", atoi(argv[1])); rt_log_interval = atoi(argv[1])*1000; argc--; argv++; } break; default: print_usage(); exit(-1); } } else { fprintf(stderr, "Unknown option: %s\n", argv[0]); print_usage(); exit(-1); } argc--; argv++; } /* Check that we are running as root */ if (geteuid() != 0) { fprintf(stderr, "aodvd: must be root\n"); exit(1); } /* Detach from terminal */ if(daemonize) { if (fork() != 0) exit(0); /* Close stdin, stdout and stderr... */ close(0); close(1); close(2); setsid(); } /* Initialize data structures and services... */ host_init(ifname); log_init(); timer_queue_init(); rt_table_init(); packet_input_init(); aodv_socket_init(); log(LOG_NOTICE, 0, "INIT: Attaching to interface %s, override with -i <interface>.",this_host->ifname); /* Make sure we cleanup at exit... */ atexit((void *)&cleanup); /* Make sure we run at high priority to make up for the user space packet processing... */ /* nice(-5); */ /* Catch SIGHUP, SIGINT and SIGTERM type signals */ signal(SIGHUP, signal_handler); signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); /* Only capture segmentation faults when we are not debugging... */ #ifndef DEBUG signal(SIGSEGV, signal_handler); #endif /* Set sockets to watch... */ FD_ZERO(&readers); for (i = 0; i < nr_callbacks; i++) { FD_SET(callbacks[i].fd, &readers); if (callbacks[i].fd >= nfds) nfds = callbacks[i].fd + 1; } /* Set bcast_time, which ensures that we don't send unnecessary hello msgs. */ this_host->bcast_time = get_currtime(); /* Schedule the first Hello */ timer_new(HELLO_INTERVAL, hello_send, NULL); if(log_rt_table) timer_new(rt_log_interval, print_rt_table, NULL); while(1) { memcpy((char *)&rfds, (char *)&readers, sizeof(rfds)); if ((n = select(nfds, &rfds, NULL, NULL, NULL)) < 0) { if (errno != EINTR) log(LOG_WARNING, errno, "main.c: Failed select (main loop)"); continue; } if (n > 0) { for (i = 0; i < nr_callbacks; i++) { if (FD_ISSET(callbacks[i].fd, &rfds)) { /* We don't want any timer SIGALRM's while executing the callback functions, therefore we block the timer... */ timer_block(); (*callbacks[i].func)(callbacks[i].fd); timer_unblock(); } } } } /* Main loop */ return 0; }