Exemplo n.º 1
0
static __init void cd_cmd_init(void)
{
	register_command(&cmd_cd);
}
Exemplo n.º 2
0
static __init void xsync_cmd_init(void)
{
	register_command(&cmd_xsync);
}
Exemplo n.º 3
0
static __init void fileram_cmd_init(void)
{
	register_command(&cmd_fileram);
}
Exemplo n.º 4
0
void
register_commands (void)
{
    register_command("connect", command_connect);
}
Exemplo n.º 5
0
static __init void echo_cmd_init(void)
{
	register_command(&cmd_echo);
}
Exemplo n.º 6
0
static __init void write_cmd_init(void)
{
	register_command(&cmd_write);
}
Exemplo n.º 7
0
int main(int argc, char *argv[]) {
	pthread_t t_cleanup; // thread for cleaning up dead sessions.
	pthread_t t_healthagent; // thread for health agent.
	pthread_t t_cli; // thread for cli.
	pthread_t t_counters; // thread for performance counters.
	pthread_t t_memorymanager; // thread for the memory manager.
	struct ifaddrs *ifaddr;//, *ifa;
	__u32 tempIP;
//	int s;
	int i;
	char message[LOGSZ];
	char strIP[20];
//	char host[NI_MAXHOST];
	char path[100] = "/etc/opennop/opennop.conf";
	int tmp;
	__u32 packet_size = PACKET_SIZE, packet_number = PACKET_NUMBER, thr_num = DEF_THR_NUM;
        __u32 fpPerPkt = DEF_FP_PER_PKT, fpsFactor = DEF_FPS_FACTOR;

#if defined(DEBUG)

	int daemonize = false;
#else

	int daemonize = true;
#endif

	/* Setup signal handling */
	signal(SIGHUP, signal_handler);
	signal(SIGTERM, signal_handler);
	signal(SIGINT, signal_handler);
	signal(SIGQUIT, signal_handler);
	signal(SIGPIPE,SIG_IGN);

	int c;
	while ((c = getopt(argc, argv, "nh|help")) != -1) {
		switch (c) {
		case 'h':
			PrintUsage(argc, argv);
			exit(0);
			break;
		case 'n':
			daemonize = 0;
			isdaemon = false;
			break;
		default:
			PrintUsage(argc, argv);
			break;
		}
	}


	sprintf(message, "Initialization: %s daemon starting up.\n", DAEMON_NAME);
	logger(LOG_INFO, message);

	/*
	 * Configuration: read the configuration file
	 */
	sprintf(message, "Configuring: reading file %s.\n", path);
	logger(LOG_INFO, message);

	tmp = configure(path, &localID, &packet_number, &packet_size, &thr_num, &fpPerPkt, &fpsFactor);

	if(tmp == 1){
		sprintf(message, "Configuring error. EXIT\n");
		logger(LOG_INFO, message);
		exit(EXIT_FAILURE);
	}

	sprintf(message, "Initialization: Version %s.\n", VERSION);
	logger(LOG_INFO, message);

	/*
	 * Get the numerically highest local IP address.
	 * This will be used as the acceleratorID.
	 */
	if (getifaddrs(&ifaddr) == -1) {
		sprintf(message, "Initialization: Error opening interfaces.\n");
		logger(LOG_INFO, message);
		exit(EXIT_FAILURE);
	}

//	for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { // loop through all interfaces.
//
//		if (ifa->ifa_addr != NULL) {
//
//			if (ifa->ifa_addr->sa_family == AF_INET) { // get all IPv4 addresses.
//				s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
//						host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
//
//				if (s != 0) {
//					exit(EXIT_FAILURE);
//				}
//
//				inet_pton(AF_INET, (char *) &host, &tempIP); // convert string to decimal.
//
//				/*
//				 * Lets fine the largest local IP, and use that as accelleratorID
//				 * Lets also exclude 127.0.0.1 as a valid ID.
//				 */
//				if ((tempIP > localID) && (tempIP != LOOPBACKIP)) {
//					localID = tempIP;
//				}
//			} // end get all IPv4 addresses.
//		} // end ifa->ifa_addr NULL test.
//	} // end loop through all interfaces.

	if (localID == 0) { // fail if no usable IP found.
		inet_ntop(AF_INET, &tempIP, strIP, INET_ADDRSTRLEN);
		sprintf(message, "Initialization: No usable IP Address. %s\n", strIP);
		logger(LOG_INFO, message);
		exit(EXIT_FAILURE);
	}

#if defined(DEBUG)
	setlogmask(LOG_UPTO(LOG_DEBUG));
	openlog(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);
#else

	setlogmask(LOG_UPTO(LOG_INFO));
	openlog(DAEMON_NAME, LOG_CONS, LOG_USER);
#endif

	/* Our process ID and Session ID */
	pid_t pid, sid;
	if (daemonize) {
		sprintf(message, "Initialization: Daemonizing the %s process.\n",
				DAEMON_NAME);
		logger(LOG_INFO, message);

		/* Fork off the parent process */
		pid = fork();
		if (pid < 0) {
			exit(EXIT_FAILURE);
		}

		/* If we got a good PID, then
		 we can exit the parent process. */
		if (pid > 0) {
			exit(EXIT_SUCCESS);
		}

		/* Change the file mode mask */
		umask(0);

		/* Create a new SID for the child process */
		sid = setsid();
		if (sid < 0) {
			/* Log the failure */
			exit(EXIT_FAILURE);
		}

		/* Change the current working directory */
		if ((chdir("/")) < 0) {
			/* Log the failure */
			exit(EXIT_FAILURE);
		}

		/* Close out the standard file descriptors */
		close(STDIN_FILENO);
		close(STDOUT_FILENO);
		close(STDERR_FILENO);
	}

	/*
	 * Starting up the daemon.
	 */

	initialize_sessiontable();

	if (get_workers() == 0) {
		set_workers(thr_num);
		//set_workers(sysconf(_SC_NPROCESSORS_ONLN) * 2);
	}

#ifdef ROLLING
	init_common(packet_number,packet_size, fpPerPkt, fpsFactor, shareddict);
	init_debugd() ;
#endif

 	for (i = 0; i < get_workers(); i++) {
		create_worker(i);
	}

#ifdef BASIC
	create_hashmap(&ht); // Create hash table
#endif

	// Only one type of optimization can be active
//	assert(deduplication != compression);

	/*
	 * Create the fetcher thread that retrieves
	 * IP packets from the Netfilter Queue.
	 */
	create_fetcher();
	pthread_create(&t_cleanup, NULL, cleanup_function, (void *) NULL);
	pthread_create(&t_healthagent, NULL, healthagent_function, (void *) NULL);
	pthread_create(&t_cli, NULL, cli_manager_init, (void *) NULL);
	pthread_create(&t_counters, NULL, counters_function, (void *) NULL);
	pthread_create(&t_memorymanager, NULL, memorymanager_function, (void *) NULL);

	sprintf(message, "[OpenNOP]: Started all threads.\n");
	logger(LOG_INFO, message);

	/*
	 * All the threads have been created now commands should be registered.
	 */
	register_command("show traces mask", cli_show_traces_mask, false, false);
	register_command("traces mask orr", cli_traces_mask_orr, true, false);
	register_command("traces mask and", cli_traces_mask_and, true, false);
	register_command("traces mask nand", cli_traces_mask_nand, true, false);
	register_command("reset stats in_dedup", cli_reset_stats_in_dedup, false, false);
	register_command("reset stats in_dedup_thread", cli_reset_stats_in_dedup, false, false);
	register_command("show stats in_dedup", cli_show_stats_in_dedup, false, false);
	register_command("show stats in_dedup_thread", cli_show_stats_in_dedup_thread, false, false);
	register_command("reset stats out_dedup", cli_reset_stats_out_dedup, false, false);
	register_command("reset stats out_dedup_thread", cli_reset_stats_out_dedup, false, false);
	register_command("show stats out_dedup", cli_show_stats_out_dedup, false, false);
	register_command("show stats out_dedup_thread", cli_show_stats_out_dedup_thread, false, false);

	register_command("traces enable", cli_traces_enable, true, false);

	register_command("traces disable", cli_traces_disable, true, false);

	register_command("show version", cli_show_version, false, false);
	register_command("show compression", cli_show_compression, false, false);
	register_command("show workers", cli_show_workers, false, false);
	register_command("show fetcher", cli_show_fetcher, false, false);
	register_command("show sessions", cli_show_sessionss, false, false);
	register_command("show deduplication", cli_show_deduplication, false, false);
	register_command("compression enable", cli_compression_enable, false, false);
	register_command("compression disable", cli_compression_disable, false, false);
	register_command("deduplication enable", cli_deduplication_enable, false, false);
	register_command("deduplication disable", cli_deduplication_disable, false, false);

	/*
	 * Rejoin all threads before we exit!
	 */
	rejoin_fetcher();
	sprintf(message, "[OpenNOP] Fetcher joined\n");
	logger(LOG_INFO, message);
	pthread_join(t_cleanup, NULL);
	sprintf(message, "joined cleanup\n");
	logger(LOG_INFO, message);
	pthread_join(t_healthagent, NULL);
	sprintf(message, "joined health\n");
	logger(LOG_INFO, message);
	pthread_join(t_cli, NULL);
	sprintf(message, "joined cli\n");
	logger(LOG_INFO, message);
	pthread_join(t_counters, NULL);
	sprintf(message, "joined counters\n");
	logger(LOG_INFO, message);
	pthread_join(t_memorymanager, NULL);

	for (i = 0; i < get_workers(); i++) {
		rejoin_worker(i);
	}
#ifdef BASIC
	remove_hashmap(ht);
#endif
	clear_sessiontable();

	sprintf(message, "Exiting: %s daemon exiting", DAEMON_NAME);
	logger(LOG_INFO, message);

	exit(EXIT_SUCCESS);
}
Exemplo n.º 8
0
	/** Service **/
	bool CallbackService::on_load(){
		if(!Super::on_load()) return false;
		ASSIGN_POINTER(m_command_desc_table, SafeNew<Hash>());
		register_command();
		return true;
	}
Exemplo n.º 9
0
Arquivo: cmd-go.c Projeto: xboot/xboot
static __init void go_cmd_init(void)
{
	register_command(&cmd_go);
}
Exemplo n.º 10
0
int str9xpec_register_commands(struct command_context_s *cmd_ctx)
{
	command_t *str9xpec_cmd = register_command(cmd_ctx, NULL, "str9xpec", NULL, COMMAND_ANY, "str9xpec flash specific commands");

	register_command(cmd_ctx, str9xpec_cmd, "enable_turbo", str9xpec_handle_flash_enable_turbo_command, COMMAND_EXEC,
					 "enable str9xpec turbo mode");
	register_command(cmd_ctx, str9xpec_cmd, "disable_turbo", str9xpec_handle_flash_disable_turbo_command, COMMAND_EXEC,
					 "disable str9xpec turbo mode");
	register_command(cmd_ctx, str9xpec_cmd, "options_cmap", str9xpec_handle_flash_options_cmap_command, COMMAND_EXEC,
					 "configure str9xpec boot sector");
	register_command(cmd_ctx, str9xpec_cmd, "options_lvdthd", str9xpec_handle_flash_options_lvdthd_command, COMMAND_EXEC,
					 "configure str9xpec lvd threshold");
	register_command(cmd_ctx, str9xpec_cmd, "options_lvdsel", str9xpec_handle_flash_options_lvdsel_command, COMMAND_EXEC,
					 "configure str9xpec lvd selection");
	register_command(cmd_ctx, str9xpec_cmd, "options_lvdwarn", str9xpec_handle_flash_options_lvdwarn_command, COMMAND_EXEC,
					 "configure str9xpec lvd warning");
	register_command(cmd_ctx, str9xpec_cmd, "options_read", str9xpec_handle_flash_options_read_command, COMMAND_EXEC,
					 "read str9xpec options");
	register_command(cmd_ctx, str9xpec_cmd, "options_write", str9xpec_handle_flash_options_write_command, COMMAND_EXEC,
					 "write str9xpec options");
	register_command(cmd_ctx, str9xpec_cmd, "lock", str9xpec_handle_flash_lock_command, COMMAND_EXEC,
					 "lock str9xpec device");
	register_command(cmd_ctx, str9xpec_cmd, "unlock", str9xpec_handle_flash_unlock_command, COMMAND_EXEC,
					 "unlock str9xpec device");
	register_command(cmd_ctx, str9xpec_cmd, "part_id", str9xpec_handle_part_id_command, COMMAND_EXEC,
					 "print part id of str9xpec flash bank <num>");

	return ERROR_OK;
}
Exemplo n.º 11
0
        void tracer::install(service_spec& spec)
        {
            auto trace = dsn_config_get_value_bool("task..default", "is_trace", false,
                "whether to trace tasks by default");

            for (int i = 0; i <= dsn_task_code_max(); i++)
            {
                if (i == TASK_CODE_INVALID)
                    continue;

                std::string section_name = std::string("task.") + std::string(dsn_task_code_to_string(i));
                task_spec* spec = task_spec::get(i);
                dassert (spec != nullptr, "task_spec cannot be null");

                if (!dsn_config_get_value_bool(section_name.c_str(), "is_trace", trace, 
                    "whether to trace this kind of task"))
                    continue;

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_task_enqueue", true, 
                    "whether to trace when a timer or async task is enqueued"))
                    spec->on_task_enqueue.put_back(tracer_on_task_enqueue, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_task_begin", true, 
                    "whether to trace when a task begins"))
                    spec->on_task_begin.put_back(tracer_on_task_begin, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_task_end", true, 
                    "whether to trace when a task ends"))
                    spec->on_task_end.put_back(tracer_on_task_end, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_task_cancelled", true,
                    "whether to trace when a task is cancelled"))
                    spec->on_task_cancelled.put_back(tracer_on_task_cancelled, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_task_wait_pre", true,
                    "whether to trace when a task is to be wait"))
                    spec->on_task_wait_pre.put_back(tracer_on_task_wait_pre, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_task_wait_post", true,
                    "whether to trace when a task is wait post"))
                    spec->on_task_wait_post.put_back(tracer_on_task_wait_post, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_task_cancel_post", true,
                    "whether to trace when a task is cancel post"))
                    spec->on_task_cancel_post.put_back(tracer_on_task_cancel_post, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_aio_call", true, 
                    "whether to trace when an aio task is called"))
                    spec->on_aio_call.put_back(tracer_on_aio_call, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_aio_enqueue", true,
                    "whether to trace when an aio task is enqueued"))
                    spec->on_aio_enqueue.put_back(tracer_on_aio_enqueue, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_rpc_call", true,
                    "whether to trace when a rpc is made"))
                    spec->on_rpc_call.put_back(tracer_on_rpc_call, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_rpc_request_enqueue", true,
                    "whether to trace when a rpc request task is enqueued"))
                    spec->on_rpc_request_enqueue.put_back(tracer_on_rpc_request_enqueue, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_rpc_reply", true,
                    "whether to trace when reply a rpc request"))
                    spec->on_rpc_reply.put_back(tracer_on_rpc_reply, "tracer");

                if (dsn_config_get_value_bool(section_name.c_str(), "tracer::on_rpc_response_enqueue", true,
                    "whetehr to trace when a rpc response task is enqueued"))
                    spec->on_rpc_response_enqueue.put_back(tracer_on_rpc_response_enqueue, "tracer");
            }

            register_command({ "tracer.find" }, 
                "tracer.find - find related logs", 
                "tracer.find forward|f|backward|b rpc|r|task|t trace_id|task_id(e.g., a023003920302390) log_file_name(log.xx.txt)",
                tracer_log_flow
                );
        }
Exemplo n.º 12
0
static __init void delay_cmd_init(void)
{
	register_command(&cmd_delay);
}
Exemplo n.º 13
0
    command_manager::command_manager()
    {
        register_command(
            {"help", "h", "H", "Help"}, 
            "help|Help|h|H [command] - display help information", 
            "",
            [this](const safe_vector<safe_string>& args)
            {
                safe_sstream ss;

                if (args.size() == 0)
                {
                    utils::auto_read_lock l(_lock);
                    for (auto c : this->_commands)
                    {
                        ss << c->help_short << std::endl;
                    }
                }
                else
                {
                    utils::auto_read_lock l(_lock);
                    auto it = _handlers.find(args[0]);
                    if (it == _handlers.end())
                        ss << "cannot find command '" << args[0] << "'";
                    else
                    {
                        ss.width(6);
                        ss << std::left << it->first << ": " << it->second->help_short << std::endl << it->second->help_long << std::endl;
                    }
                }

                return ss.str();
            }
        );

        register_command(
            { "repeat", "r", "R", "Repeat" },
            "repeat|Repeat|r|R interval_seconds max_count command - execute command periodically",
            "repeat|Repeat|r|R interval_seconds max_count command - execute command every interval seconds, to the max count as max_count (0 for infinite)",
            [this](const safe_vector<safe_string>& args)
        {
            safe_sstream ss;

            if (args.size() < 3)
            {
                return "insufficient arguments";
            }

            int interval_seconds = atoi(args[0].c_str());
            if (interval_seconds <= 0)
            {
                return "invalid interval argument";
            }

            int max_count = atoi(args[1].c_str());
            if (max_count < 0)
            {
                return "invalid max count";
            }

            if (max_count == 0)
            {
                max_count = std::numeric_limits<int>::max();
            }

            safe_string cmd = args[2];
            safe_vector<safe_string> largs;
            for (int i = 3; i < (int)args.size(); i++)
            {
                largs.push_back(args[i]);
            }

            for (int i = 0; i < max_count; i++)
            {
                safe_string output;
                auto r = this->run_command(cmd, largs, output);

                if (!r)
                {
                    break;
                }

                std::this_thread::sleep_for(std::chrono::seconds(interval_seconds));
            }

            return "repeat command completed";
        }
        );
    }
Exemplo n.º 14
0
int command_tests_passed(){
	int i = 0;

   	for(i = 0; i < 100; i++){
		register_command("afdsasd",1);
		register_command("%mkdir",1);
		register_command("asfdsafsdd",1);
		register_command("afdsasd",1);
		register_command("afdsafsdsd",1);
		register_command("afdsafsdsd",1);
		register_command("afsdafsdasd",1);
		register_command("asfdsafsdd",1);
		register_command("fWS",1);
		register_command("afdsafdsfsdfsd",1);
		
	}

	register_command("%WS",1);
	register_command("%WT",1);

	unregister_all_commands();
	return 1;
}
Exemplo n.º 15
0
static void
register_commands (void)
{
	/* The order here is important. Commands registered earlier have higher
	 * priority.  However commands that can read and write a file format
	 * have higher priority over commands that can only read the same
	 * format, regardless of the registration order. */

	register_command (FR_TYPE_COMMAND_TAR);
	register_command (FR_TYPE_COMMAND_CFILE);
	register_command (FR_TYPE_COMMAND_7Z);
	register_command (FR_TYPE_COMMAND_DPKG);

	register_command (FR_TYPE_COMMAND_ACE);
	register_command (FR_TYPE_COMMAND_ALZ);
	register_command (FR_TYPE_COMMAND_AR);
	register_command (FR_TYPE_COMMAND_ARJ);
	register_command (FR_TYPE_COMMAND_CPIO);
	register_command (FR_TYPE_COMMAND_ISO);
	register_command (FR_TYPE_COMMAND_JAR);
	register_command (FR_TYPE_COMMAND_LHA);
	register_command (FR_TYPE_COMMAND_RAR);
	register_command (FR_TYPE_COMMAND_RPM);
	register_command (FR_TYPE_COMMAND_UNSTUFF);
	register_command (FR_TYPE_COMMAND_ZIP);
	register_command (FR_TYPE_COMMAND_LRZIP);
	register_command (FR_TYPE_COMMAND_ZOO);
#if HAVE_JSON_GLIB
	register_command (FR_TYPE_COMMAND_UNARCHIVER);
#endif
}
Exemplo n.º 16
0
static __init void mw_cmd_init(void)
{
	register_command(&cmd_mw);
}