int main(int argc, char *argv[]) { proctitle_init(argc, argv); set_program_name(argv[0]); parse_options(argc, argv); run_command(argc - optind, argv + optind, all_commands); return 0; }
static void test_jsonrpc_main(int argc, char *argv[]) { proctitle_init(argc, argv); set_program_name(argv[0]); service_start(&argc, &argv); parse_options(argc, argv); run_command(argc - optind, argv + optind, get_all_commands()); }
int main(int argc, char *argv[]) { struct unixctl_server *unixctl; struct signal *sighup; char *remote; bool exiting; int retval; proctitle_init(argc, argv); set_program_name(argv[0]); stress_init_command(); remote = parse_options(argc, argv); signal(SIGPIPE, SIG_IGN); sighup = signal_register(SIGHUP); process_init(); ovsrec_init(); daemonize_start(); retval = unixctl_server_create(NULL, &unixctl); if (retval) { exit(EXIT_FAILURE); } unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting); bridge_init(remote); free(remote); exiting = false; while (!exiting) { if (signal_poll(sighup)) { vlog_reopen_log_file(); } bridge_run_fast(); bridge_run(); bridge_run_fast(); unixctl_server_run(unixctl); netdev_run(); signal_wait(sighup); bridge_wait(); unixctl_server_wait(unixctl); netdev_wait(); if (exiting) { poll_immediate_wake(); } poll_block(); } bridge_exit(); unixctl_server_destroy(unixctl); signal_unregister(sighup); return 0; }
int main(int argc, char *argv[]) { char *unixctl_path = NULL; struct unixctl_server *unixctl; struct signal *sighup; char *remote; bool exiting; int retval; proctitle_init(argc, argv); set_program_name(argv[0]); service_start(&argc, &argv); remote = parse_options(argc, argv, &unixctl_path); signal(SIGPIPE, SIG_IGN); sighup = signal_register(SIGHUP); ovsrec_init(); daemonize_start(); if (want_mlockall) { #ifdef HAVE_MLOCKALL if (mlockall(MCL_CURRENT | MCL_FUTURE)) { VLOG_ERR("mlockall failed: %s", ovs_strerror(errno)); } #else VLOG_ERR("mlockall not supported on this system"); #endif } retval = unixctl_server_create(unixctl_path, &unixctl); if (retval) { exit(EXIT_FAILURE); } unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting); bridge_init(remote); free(remote); exiting = false; while (!exiting) { if (signal_poll(sighup)) { vlog_reopen_log_file(); } memory_run(); if (memory_should_report()) { struct simap usage; simap_init(&usage); bridge_get_memory_usage(&usage); memory_report(&usage); simap_destroy(&usage); } bridge_run(); unixctl_server_run(unixctl); netdev_run(); signal_wait(sighup); memory_wait(); bridge_wait(); unixctl_server_wait(unixctl); netdev_wait(); if (exiting) { poll_immediate_wake(); } poll_block(); if (should_service_stop()) { exiting = true; } } bridge_exit(); unixctl_server_destroy(unixctl); service_stop(); return 0; }
int main(int argc, char *argv[]) { struct unixctl_server *server; enum { MAX_RECV = 1500 }; const char *target; struct ofpbuf buf; bool exiting = false; int error; int sock; int n; proctitle_init(argc, argv); set_program_name(argv[0]); parse_options(argc, argv); if (argc - optind != 1) { ovs_fatal(0, "exactly one non-option argument required " "(use --help for help)"); } target = argv[optind]; sock = inet_open_passive(SOCK_DGRAM, target, 0, NULL, 0); if (sock < 0) { ovs_fatal(0, "%s: failed to open (%s)", argv[1], strerror(-sock)); } daemon_save_fd(STDOUT_FILENO); daemonize_start(); error = unixctl_server_create(NULL, &server); if (error) { ovs_fatal(error, "failed to create unixctl server"); } unixctl_command_register("exit", "", 0, 0, test_netflow_exit, &exiting); daemonize_complete(); ofpbuf_init(&buf, MAX_RECV); n = 0; for (;;) { int retval; unixctl_server_run(server); ofpbuf_clear(&buf); do { retval = read(sock, buf.data, buf.allocated); } while (retval < 0 && errno == EINTR); if (retval > 0) { ofpbuf_put_uninit(&buf, retval); if (n++ > 0) { putchar('\n'); } print_netflow(&buf); fflush(stdout); } if (exiting) { break; } poll_fd_wait(sock, POLLIN); unixctl_server_wait(server); poll_block(); } return 0; }
int main(int argc, char *argv[]) { char *unixctl_path = NULL; char *run_command = NULL; struct unixctl_server *unixctl; struct ovsdb_jsonrpc_server *jsonrpc; struct shash remotes; struct ovsdb_error *error; struct ovsdb_file *file; struct ovsdb *db; struct process *run_process; char *file_name; bool exiting; int retval; proctitle_init(argc, argv); set_program_name(argv[0]); signal(SIGPIPE, SIG_IGN); process_init(); parse_options(argc, argv, &file_name, &remotes, &unixctl_path, &run_command); die_if_already_running(); daemonize_start(); error = ovsdb_file_open(file_name, false, &db, &file); if (error) { ovs_fatal(0, "%s", ovsdb_error_to_string(error)); } jsonrpc = ovsdb_jsonrpc_server_create(db); reconfigure_from_db(jsonrpc, db, &remotes); retval = unixctl_server_create(unixctl_path, &unixctl); if (retval) { exit(EXIT_FAILURE); } if (run_command) { char *run_argv[4]; run_argv[0] = "/bin/sh"; run_argv[1] = "-c"; run_argv[2] = run_command; run_argv[3] = NULL; retval = process_start(run_argv, NULL, 0, NULL, 0, &run_process); if (retval) { ovs_fatal(retval, "%s: process failed to start", run_command); } } else { run_process = NULL; } daemonize_complete(); unixctl_command_register("exit", ovsdb_server_exit, &exiting); unixctl_command_register("ovsdb-server/compact", ovsdb_server_compact, file); unixctl_command_register("ovsdb-server/reconnect", ovsdb_server_reconnect, jsonrpc); exiting = false; while (!exiting) { reconfigure_from_db(jsonrpc, db, &remotes); ovsdb_jsonrpc_server_run(jsonrpc); unixctl_server_run(unixctl); ovsdb_trigger_run(db, time_msec()); if (run_process && process_exited(run_process)) { exiting = true; } ovsdb_jsonrpc_server_wait(jsonrpc); unixctl_server_wait(unixctl); ovsdb_trigger_wait(db, time_msec()); if (run_process) { process_wait(run_process); } poll_block(); } ovsdb_jsonrpc_server_destroy(jsonrpc); ovsdb_destroy(db); shash_destroy(&remotes); unixctl_server_destroy(unixctl); if (run_process && process_exited(run_process)) { int status = process_status(run_process); if (status) { ovs_fatal(0, "%s: child exited, %s", run_command, process_status_msg(status)); } } return 0; }
/** * @brief openvassd. * @param argc Argument count. * @param argv Argument vector. */ int main (int argc, char *argv[]) { int exit_early = 0, scanner_port = 9391; pid_t handler_pid; char *myself; struct arglist *options = emalloc (sizeof (struct arglist)); struct addrinfo *mysaddr; struct addrinfo hints; struct addrinfo ai; struct sockaddr_in saddr; struct sockaddr_in6 s6addr; proctitle_init (argc, argv); gcrypt_init (); if ((myself = strrchr (*argv, '/')) == 0) myself = *argv; else myself++; static gboolean display_version = FALSE; static gboolean dont_fork = FALSE; static gchar *address = NULL; static gchar *port = NULL; static gchar *config_file = NULL; static gchar *gnutls_priorities = "NORMAL"; static gchar *dh_params = NULL; static gboolean print_specs = FALSE; static gboolean print_sysconfdir = FALSE; static gboolean only_cache = FALSE; GError *error = NULL; GOptionContext *option_context; static GOptionEntry entries[] = { {"version", 'V', 0, G_OPTION_ARG_NONE, &display_version, "Display version information", NULL}, {"foreground", 'f', 0, G_OPTION_ARG_NONE, &dont_fork, "Do not run in daemon mode but stay in foreground", NULL}, {"listen", 'a', 0, G_OPTION_ARG_STRING, &address, "Listen on <address>", "<address>"}, {"port", 'p', 0, G_OPTION_ARG_STRING, &port, "Use port number <number>", "<number>"}, {"config-file", 'c', 0, G_OPTION_ARG_FILENAME, &config_file, "Configuration file", "<.rcfile>"}, {"cfg-specs", 's', 0, G_OPTION_ARG_NONE, &print_specs, "Print configuration settings", NULL}, {"sysconfdir", 'y', 0, G_OPTION_ARG_NONE, &print_sysconfdir, "Print system configuration directory (set at compile time)", NULL}, {"only-cache", 'C', 0, G_OPTION_ARG_NONE, &only_cache, "Exit once the NVT cache has been initialized or updated", NULL}, {"gnutls-priorities", '\0', 0, G_OPTION_ARG_STRING, &gnutls_priorities, "GnuTLS priorities string", "<string>"}, {"dh-params", '\0', 0, G_OPTION_ARG_STRING, &dh_params, "Diffie-Hellman parameters file", "<string>"}, {NULL} }; option_context = g_option_context_new ("- Scanner of the Open Vulnerability Assessment System"); g_option_context_add_main_entries (option_context, entries, NULL); if (!g_option_context_parse (option_context, &argc, &argv, &error)) { g_print ("%s\n\n", error->message); exit (0); } g_option_context_free (option_context); if (print_sysconfdir) { g_print ("%s\n", SYSCONFDIR); exit (0); } /* Switch to UTC so that OTP times are always in UTC. */ if (setenv ("TZ", "utc 0", 1) == -1) { g_print ("%s\n\n", strerror (errno)); exit (0); } tzset (); if (print_specs) exit_early = 2; /* no cipher initialization */ if (address != NULL) { memset (&hints, 0, sizeof (hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = AI_NUMERICHOST; if (getaddrinfo (address, NULL, &hints, &mysaddr)) { printf ("Invalid IP address.\n"); printf ("Please use %s --help for more information.\n", myself); exit (0); } /* deep copy */ ai.ai_family = mysaddr->ai_family; if (ai.ai_family == AF_INET) { memcpy (&saddr, mysaddr->ai_addr, mysaddr->ai_addrlen); ai.ai_addr = (struct sockaddr *) &saddr; } else { memcpy (&s6addr, mysaddr->ai_addr, mysaddr->ai_addrlen); ai.ai_addr = (struct sockaddr *) &s6addr; } ai.ai_family = mysaddr->ai_family; ai.ai_protocol = mysaddr->ai_protocol; ai.ai_socktype = mysaddr->ai_socktype; ai.ai_addrlen = mysaddr->ai_addrlen; freeaddrinfo (mysaddr); } else { /* Default to IPv4 */ /*Warning: Not filling all the fields */ saddr.sin_addr.s_addr = INADDR_ANY; saddr.sin_family = ai.ai_family = AF_INET; ai.ai_addrlen = sizeof (saddr); ai.ai_addr = (struct sockaddr *) &saddr; } if (port != NULL) { scanner_port = atoi (port); if ((scanner_port <= 0) || (scanner_port >= 65536)) { printf ("Invalid port specification.\n"); printf ("Please use %s --help for more information.\n", myself); exit (1); } } if (display_version) { printf ("OpenVAS Scanner %s\n", OPENVASSD_VERSION); printf ("Nessus origin: (C) 2004 Renaud Deraison <*****@*****.**>\n"); printf ("Most new code since OpenVAS: (C) 2013 Greenbone Networks GmbH\n"); printf ("License GPLv2: GNU GPL version 2\n"); printf ("This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n\n"); exit (0); } if (config_file != NULL) arg_add_value (options, "acc_hint", ARG_INT, sizeof (int), (void *) 1); if (!config_file) { config_file = emalloc (strlen (OPENVASSD_CONF) + 1); strncpy (config_file, OPENVASSD_CONF, strlen (OPENVASSD_CONF)); } arg_add_value (options, "scanner_port", ARG_INT, sizeof (gpointer), GSIZE_TO_POINTER (scanner_port)); arg_add_value (options, "config_file", ARG_STRING, strlen (config_file), config_file); arg_add_value (options, "addr", ARG_PTR, -1, &ai); if (only_cache) { init_openvassd (options, 0, 1, dont_fork); init_plugins (options); exit (0); } init_openvassd (options, 1, exit_early, dont_fork); g_options = options; global_iana_socket = GPOINTER_TO_SIZE (arg_get_value (options, "isck")); global_plugins = arg_get_value (options, "plugins"); /* special treatment */ if (print_specs) dump_cfg_specs (global_preferences); if (exit_early) exit (0); init_ssl_ctx (gnutls_priorities, dh_params); // Daemon mode: if (dont_fork == FALSE) set_daemon_mode (); pidfile_create ("openvassd"); handler_pid = loading_handler_start (); init_plugins (options); loading_handler_stop (handler_pid); main_loop (); exit (0); }