Ejemplo n.º 1
1
Archivo: remunge.c Proyecto: dun/munge
int
main (int argc, char *argv[])
{
    conf_t conf;

    /*  FIXME: Revamp signal handlers.
     */
    if (posignal (SIGHUP, SIG_IGN) == SIG_ERR) {
        log_err (EMUNGE_SNAFU, LOG_ERR, "Failed to ignore signal=%d", SIGHUP);
    }
    if (posignal (SIGPIPE, SIG_IGN) == SIG_ERR) {
        log_err (EMUNGE_SNAFU, LOG_ERR, "Failed to ignore signal=%d", SIGPIPE);
    }
    /*  Close stdin since it is not used.
     */
    if (close (STDIN_FILENO) < 0) {
        log_errno (EMUNGE_SNAFU, LOG_ERR, "Failed to close standard input");
    }
    /*  Set stdout to be line buffered.
     */
    if (setvbuf (stdout, NULL, _IOLBF, 0) < 0) {
        log_err (EMUNGE_SNAFU, LOG_ERR,
            "Failed to line-buffer standard output");
    }
    log_open_file (stderr, argv[0], LOG_INFO, LOG_OPT_PRIORITY);
    conf = create_conf ();
    parse_cmdline (conf, argc, argv);

    start_threads (conf);
    process_creds (conf);
    stop_threads (conf);

    destroy_conf (conf);
    log_close_file ();
    exit (EMUNGE_SUCCESS);
}
Ejemplo n.º 2
0
	void disk_io_thread_pool::set_max_threads(int const i)
	{
		std::lock_guard<std::mutex> l(m_mutex);
		if (i == m_max_threads) return;
		m_max_threads = i;
		if (m_threads.size() < i) return;
		stop_threads(int(m_threads.size()) - i);
	}
Ejemplo n.º 3
0
Player::~Player(){
	stop_threads();

	numthreads = 0;
	reset_threads(); //shut down the theads properly

	root.dealloc(ctmem);
	ctmem.compact();
}
Ejemplo n.º 4
0
void Player::set_ponder(bool p){
	if(ponder != p){
		ponder = p;
		stop_threads();

		if(ponder)
			start_threads();
	}
}
Ejemplo n.º 5
0
void ringmaster_destroy(ringmaster_t *rm) {
  // rm->consumers belongs to someone else
  // rm->consumer_deps belong to someone else
  rm->state = STOPPED;
  stop_threads(rm->n_consumers, rm->threads);
  free(rm->threads);
  free((void *)rm->consumer_slots);
  free(rm);
}
Ejemplo n.º 6
0
void scheduler::shutdown(void) {
    // lock mutex for thread safety
    std::unique_lock<std::mutex> scheduler_lock{mutex};
    
    if (running) {
        
        STATICLIB_PION_LOG_INFO(log, "Shutting down the thread scheduler");
        
        while (active_users > 0) {
            // first, wait for any active users to exit
            STATICLIB_PION_LOG_INFO(log, "Waiting for " << active_users << " scheduler users to finish");
            no_more_active_users.wait(scheduler_lock);
        }

        // shut everything down
        running = false;
        asio_service.stop();
        stop_threads();
        asio_service.reset();
        thread_pool.clear();
        
        STATICLIB_PION_LOG_INFO(log, "The thread scheduler has shutdown");

        // Make sure anyone waiting on shutdown gets notified
        scheduler_has_stopped.notify_all();
        
    } else {
        
        // stop and finish everything to be certain that no events are pending
        asio_service.stop();
        stop_threads();
        asio_service.reset();
        thread_pool.clear();
        
        // Make sure anyone waiting on shutdown gets notified
        // even if the scheduler did not startup successfully
        scheduler_has_stopped.notify_all();
    }
}
Ejemplo n.º 7
0
void Player::set_board(const Board & board){
	stop_threads();

	nodes -= root.dealloc(ctmem);
	root = Node();
	root.exp.addwins(visitexpand+1);

	rootboard = board;

	reset_threads(); //needed since the threads aren't started before a board it set

	if(ponder)
		start_threads();
}
Ejemplo n.º 8
0
	void disk_io_thread_pool::reap_idle_threads(error_code const& ec)
	{
		// take the minimum number of idle threads during the last
		// sample period and request that many threads to exit
		if (ec) return;
		std::lock_guard<std::mutex> l(m_mutex);
		if (m_abort) return;
		if (m_threads.size() == 0) return;
		m_idle_timer.expires_from_now(reap_idle_threads_interval);
		m_idle_timer.async_wait([this](error_code const& e) { reap_idle_threads(e); });
		int const min_idle = m_min_idle_threads.exchange(m_num_idle_threads);
		if (min_idle <= 0) return;
		// stop either the minimum number of idle threads or the number of threads
		// which must be stopped to get below the max, whichever is larger
		int const to_stop = (std::max)(min_idle, int(m_threads.size()) - m_max_threads);
		stop_threads(to_stop);
	}
Ejemplo n.º 9
0
//------------------------------------------------------------------------------
// Name: detach
// Desc:
//------------------------------------------------------------------------------
void DebuggerCore::detach() {
	if(process_) {

		stop_threads();

		clear_breakpoints();

		for(auto thread: process_->threads()) {
			ptrace(PTRACE_DETACH, thread->tid(), 0, 0);
		}
		
		delete process_;
		process_ = nullptr;

		reset();
	}
}
Ejemplo n.º 10
0
//------------------------------------------------------------------------------
// Name: detach
// Desc:
//------------------------------------------------------------------------------
void DebuggerCore::detach() {
	if(attached()) {

		stop_threads();

		clear_breakpoints();

		for(edb::tid_t thread: thread_ids()) {
			if(ptrace(PTRACE_DETACH, thread, 0, 0) == 0) {
				native::waitpid(thread, 0, __WALL);
			}
		}
		
		delete process_;
		process_ = 0;

		reset();
	}
}
Ejemplo n.º 11
0
Player::Node * Player::genmove(double time, int max_runs, bool flexible){
	time_used = 0;
	int toplay = rootboard.toplay();

	if(rootboard.won() >= 0 || (time <= 0 && max_runs == 0))
		return NULL;

	Time starttime;

	stop_threads();

	if(runs)
		logerr("Pondered " + to_str(runs) + " runs\n");

	runs = 0;
	maxruns = max_runs;
	for(unsigned int i = 0; i < threads.size(); i++)
		threads[i]->reset();

	// if the move is forced and the time can be added to the clock, don't bother running at all
	if(!flexible || root.children.num() != 1){
		//let them run!
		start_threads();

		Alarm timer;
		if(time > 0)
			timer(time - (Time() - starttime), std::bind(&Player::timedout, this));

		//wait for the timer to stop them
		runbarrier.wait();
		CAS(threadstate, Thread_Wait_End, Thread_Wait_Start);
		assert(threadstate == Thread_Wait_Start);
	}

	if(ponder && root.outcome < 0)
		start_threads();

	time_used = Time() - starttime;

//return the best one
	return return_move(& root, toplay);
}
Ejemplo n.º 12
0
Archivo: authsrv.c Proyecto: regit/nufw
/**
 * Deinit NuAuth:
 *    - Stop NuAuth: close_nufw_servers(), close_clients(), end_tls(), end_audit() ;
 *    - Free memory ;
 *    - Unload modules: unload_modules() ;
 *    - Destroy pid file ;
 *    - And finally exit.
*
 */
void nuauth_deinit(gboolean soft)
{
	log_message(CRITICAL, DEBUG_AREA_MAIN, "[+] NuAuth deinit");
#if 0
	signal(SIGTERM, SIG_DFL);
	signal(SIGKILL, SIG_DFL);
	signal(SIGHUP, SIG_DFL);
#endif

	stop_threads(soft);

	log_message(INFO, DEBUG_AREA_MAIN, "Unloading modules");
	unload_modules();

#if 0
	end_tls();
#endif

	log_message(INFO, DEBUG_AREA_MAIN, "Ending audit");
	end_audit();

	log_message(INFO, DEBUG_AREA_MAIN, "Freeing memory");
	free_nuauth_params(nuauthconf);
	if (nuauthconf->acl_cache) {
		cache_destroy(nuauthdatas->acl_cache);
	}
	if (nuauthconf->user_cache) {
		cache_destroy(nuauthdatas->user_cache);
	}
	g_free(nuauthdatas->program_fullpath);
	free_threads();
	clear_push_queue();

	g_hash_table_destroy(conn_list);

	g_static_mutex_free(&insert_mutex);

	/* destroy pid file */
	unlink(NUAUTH_PID_FILE);
}
Ejemplo n.º 13
0
void Player::move(const Move & m){
	stop_threads();

	uword nodesbefore = nodes;

	if(keeptree && root.children.num() > 0){
		Node child;

		for(Node * i = root.children.begin(); i != root.children.end(); i++){
			if(i->move == m){
				child = *i;          //copy the child experience to temp
				child.swap_tree(*i); //move the child tree to temp
				break;
			}
		}

		nodes -= root.dealloc(ctmem);
		root = child;
		root.swap_tree(child);

		if(nodesbefore > 0)
			logerr("Nodes before: " + to_str(nodesbefore) + ", after: " + to_str(nodes) + ", saved " +  to_str(100.0*nodes/nodesbefore, 1) + "% of the tree\n");
	}else{
		nodes -= root.dealloc(ctmem);
		root = Node();
		root.move = m;
	}
	assert(nodes == root.size());

	rootboard.move(m);

	root.exp.addwins(visitexpand+1); //+1 to compensate for the virtual loss
	if(rootboard.won() < 0)
		root.outcome = -3;

	if(ponder)
		start_threads();
}
Ejemplo n.º 14
0
	void disk_io_thread_pool::abort(bool wait)
	{
		std::unique_lock<std::mutex> l(m_mutex);
		if (m_abort) return;
		m_max_threads = 0;
		m_abort = true;
		m_idle_timer.cancel();
		stop_threads(int(m_threads.size()));
		for (auto& t : m_threads)
		{
			if (wait)
			{
				// must release m_mutex to avoid a deadlock if the thread
				// tries to acquire it
				l.unlock();
				t.join();
				l.lock();
			}
			else
				t.detach();
		}
		m_threads.clear();
	}
Ejemplo n.º 15
0
int main(int argc, char ** argv)
{
	char*         cmd = NULL;
	dc_context_t* context = dc_context_new(receive_event, NULL, "CLI");
	int           stresstest_only = 0;

	dc_cmdline_skip_auth(context); /* disable the need to enter the command `auth <password>` for all mailboxes. */

	/* open database from the commandline (if omitted, it can be opened using the `open`-command) */
	if (argc == 2) {
		if (strcmp(argv[1], "--stress")==0) {
			stresstest_only = 1;
		}
		else if (!dc_open(context, argv[1], NULL)) {
			printf("ERROR: Cannot open %s.\n", argv[1]);
		}
	}
	else if (argc != 1) {
		printf("ERROR: Bad arguments\n");
	}

	s_do_log_info = 0;
	stress_functions(context);
	s_do_log_info = 1;


	if (stresstest_only) {
		return 0;
	}

	printf("Delta Chat Core is awaiting your commands.\n");

	/* wait for command */
	while (1)
	{
		/* read command */
		const char* cmdline = read_cmd();
		free(cmd);
		cmd = dc_strdup(cmdline);
		char* arg1 = strchr(cmd, ' ');
		if (arg1) { *arg1 = 0; arg1++; }

		if (strcmp(cmd, "connect")==0)
		{
			start_threads(context);
		}
		else if (strcmp(cmd, "disconnect")==0)
		{
			stop_threads(context);
		}
		else if (strcmp(cmd, "smtp-jobs")==0)
		{
			if (run_threads) {
				printf("smtp-jobs are already running in a thread.\n");
			}
			else {
				dc_perform_smtp_jobs(context);
			}
		}
		else if (strcmp(cmd, "imap-jobs")==0)
		{
			if (run_threads) {
				printf("imap-jobs are already running in a thread.\n");
			}
			else {
				dc_perform_imap_jobs(context);
			}
		}
		else if (strcmp(cmd, "configure")==0)
		{
			start_threads(context);
			dc_configure(context);
		}
		else if (strcmp(cmd, "oauth2")==0)
		{
			char* addr = dc_get_config(context, "addr");
			if (addr==NULL || addr[0]==0) {
				printf("oauth2: set addr first.\n");
			}
			else {
				char* oauth2_url = dc_get_oauth2_url(context, addr,
					"chat.delta:/com.b44t.messenger");
				if (oauth2_url==NULL) {
					printf("OAuth2 not available for %s.\n", addr);
				}
				else {
					printf("Open the following url, "
						"set mail_pw to the generated token "
						"and server_flags to 2:\n%s\n", oauth2_url);
				}
				free(oauth2_url);
			}
			free(addr);
		}
		else if (strcmp(cmd, "clear")==0)
		{
			printf("\n\n\n\n"); /* insert some blank lines to visualize the break in the buffer */
			printf("\e[1;1H\e[2J"); /* should work on ANSI terminals and on Windows 10. If not, well, then not. */
		}
		else if (strcmp(cmd, "getqr")==0 || strcmp(cmd, "getbadqr")==0)
Ejemplo n.º 16
0
 void Console::before_exec(STATE) {
   stop_threads(state);
   close_files(true);
 }
Ejemplo n.º 17
0
 void Console::shutdown(STATE) {
   stop_threads(state);
   close_files(true);
   empty_request_list();
 }
Ejemplo n.º 18
0
int main(int argc, char **argv) {
	if(parse_args(argc, argv))
		return 0;
	int err = 0;
	printf("Starting Server %s (%s)...%ld\n", version_string, compiling_date, nowtime());
	if(myconfig_init(argc, argv) < 0) {
		printf("myconfig_init fail %m\n");
		goto error;
	}
	daemon_start(argc, argv);
	umask(0);
	ICALL(start_watchdog);
	ICALL(init_log);
	ICALL(init_glog);
	ICALL(init_fdinfo);
	ICALL(delay_task_init);
	ICALL(init_thread);
	ICALL(init_global);
	ICALL(vfs_init);
	ICALL(init_task_info);

	if (g_config.voss_flag == 0)
	{
		t_thread_arg arg;
		memset(&arg, 0, sizeof(arg));
		snprintf(arg.name, sizeof(arg.name), "./ott_server.so");
		LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name);
		arg.port = 80;
		arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096);
		if (init_vfs_thread(&arg))
			goto error;
		t_thread_arg arg1;
		memset(&arg1, 0, sizeof(arg1));
		snprintf(arg1.name, sizeof(arg1.name), "./ott_client.so");
		LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg1.name);
		arg1.maxevent = myconfig_get_intval("vfs_data_maxevent", 4096);
		if (init_vfs_thread(&arg1))
			goto error;
		ICALL(init_vfs_agent);
	}
	else
	{
		t_thread_arg arg;
		memset(&arg, 0, sizeof(arg));
		snprintf(arg.name, sizeof(arg.name), "./ott_voss.so");
		LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name);
		arg.port = g_config.sig_port;
		arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096);
		if (init_vfs_thread(&arg))
			goto error;
	}
	thread_jumbo_title();
	struct threadstat *thst = get_threadstat();
	if(start_threads() < 0)
		goto out;
	thread_reached(thst);
	gen_pidfile();	
	printf("Server Started\n");
	vfs_start_time = time(NULL);
	main_loop(thst);
out:
	printf("Stopping Server %s (%s)...\n", version_string, compiling_date);
	thread_reached(thst);
	stop_threads();
	myconfig_cleanup();
	fini_fdinfo();
	printf("Server Stopped.\n");
	return restart;
error:
	if(err == -ENOMEM) 
		printf("\n\033[31m\033[1mNO ENOUGH MEMORY\033[0m\n");

	printf("\033[31m\033[1mStart Fail.\033[0m\n");
	return -1;
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{
    int status = 0;
    struct rc_config rc;
    struct cli_state *state;
    bool exit_immediately = false;

    /* If no actions are specified, just show the usage text and exit */
    if (argc == 1) {
        usage(argv[0]);
        return 0;
    }

    init_rc_config(&rc);

    if (get_rc_config(argc, argv, &rc)) {
        return 1;
    }

    state = cli_state_create();

    if (!state) {
        fprintf(stderr, "Failed to create state object\n");
        return 1;
    }

    bladerf_log_set_verbosity(rc.verbosity);

    if (rc.show_help) {
        usage(argv[0]);
        exit_immediately = true;
    } else if (rc.show_version) {
        printf(BLADERF_CLI_VERSION "\n");
        exit_immediately = true;
    } else if (rc.show_lib_version) {
        struct bladerf_version version;
        bladerf_version(&version);
        printf("%s\n", version.describe);
        exit_immediately = true;
    } else if (rc.probe) {
        status = cmd_handle(state, "probe");
        exit_immediately = true;
    }

    if (!exit_immediately) {
        /* Conditionally performed items, depending on runtime config */
        status = open_device(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not open device\n");
            goto main__issues ;
        }

        status = flash_fw(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not flash firmware\n");
            goto main__issues ;
        }

        status = load_fpga(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not load fpga\n");
            goto main__issues ;
        }

        status = open_script(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not load scripts\n");
            goto main__issues ;
        }

main__issues:
        /* These items are no longer needed */
        free(rc.device);
        rc.device = NULL;

        free(rc.fw_file);
        rc.fw_file = NULL;

        free(rc.fpga_file);
        rc.fpga_file = NULL;

        free(rc.script_file);
        rc.script_file = NULL;

        /* Drop into interactive mode or begin executing commands
         * from a script. If we're not requested to do either, exit cleanly */
        if (rc.interactive_mode || state->script != NULL) {
            status = start_threads(state);

            if (status < 0) {
                fprintf(stderr, "Failed to kick off threads\n");
            } else {
                status = interactive(state, !rc.interactive_mode);
                stop_threads(state);
            }

        }

        /* Ensure we exit with RX & TX disabled.
         * Can't do much about an error at this point anyway... */
        if (state->dev && bladerf_is_fpga_configured(state->dev)) {
            bladerf_enable_module(state->dev, BLADERF_MODULE_TX, false);
            bladerf_enable_module(state->dev, BLADERF_MODULE_RX, false);
        }
    }

    cli_state_destroy(state);
    return status;
}
Ejemplo n.º 20
0
int execute_workload(CONFIG *cfg)
{
	pthread_t *ithreads, *rthreads, *uthreads;
	int ret;
	uint64_t last_inserts, last_reads, last_updates;

	cfg->phase = WT_PERF_READ;
	last_inserts = last_reads = last_updates = 0;
	lprintf(cfg, 0, 1, "Starting read threads");

	if (cfg->read_threads != 0 && (ret = start_threads(
	    cfg, cfg->read_threads, &rthreads, read_thread)) != 0)
		return (ret);

	if (cfg->insert_threads != 0 && (ret = start_threads(
	    cfg, cfg->insert_threads, &ithreads, insert_thread)) != 0)
		return (ret);

	if (cfg->update_threads != 0 && (ret = start_threads(
	    cfg, cfg->update_threads, &uthreads, update_thread)) != 0)
		return (ret);

	/* Sanity check reporting interval. */
	if (cfg->report_interval > cfg->run_time)
		cfg->report_interval = cfg->run_time;

	gettimeofday(&cfg->phase_start_time, NULL);
	for (cfg->elapsed_time = 0;
	    cfg->elapsed_time < cfg->run_time &&
	    g_threads_quit < cfg->read_threads;
	    cfg->elapsed_time += cfg->report_interval) {
		sleep(cfg->report_interval);
		lprintf(cfg, 0, 1,
		    "%" PRIu64 " reads, %" PRIu64 " inserts, %" PRIu64
		    " updates in %d secs",
		    g_nread_ops - last_reads,
		    g_nins_ops - last_inserts,
		    g_nupdate_ops - last_updates,
		    cfg->report_interval);
		last_reads = g_nread_ops;
		last_inserts = g_nins_ops;
		last_updates = g_nupdate_ops;
	}
	/* Report if any worker threads didn't finish. */
	if (g_threads_quit != 0)
		lprintf(cfg, WT_ERROR, 0,
		    "Worker thread(s) exited without finishing.");

	if (cfg->read_threads != 0 &&
	    (ret = stop_threads(cfg, cfg->read_threads, rthreads)) != 0)
		return (ret);

	if (cfg->insert_threads != 0 &&
	    (ret = stop_threads(cfg, cfg->insert_threads, ithreads)) != 0)
		return (ret);

	if (cfg->update_threads != 0 &&
	    (ret = stop_threads(cfg, cfg->update_threads, uthreads)) != 0)
		return (ret);

	return (0);
}
Ejemplo n.º 21
0
int main(void) {
  start_threads();
  usleep(30*1000*1000);
  stop_threads();
}
Ejemplo n.º 22
0
 void Console::shutdown(STATE) {
   stop_threads(state);
   cleanup(true);
 }
Ejemplo n.º 23
0
 void Console::before_exec(STATE) {
   stop_threads(state);
   cleanup(true);
 }
Ejemplo n.º 24
0
 void Console::before_fork(STATE) {
   stop_threads(state);
 }
Ejemplo n.º 25
0
/**
 * Destructor.
 **/
CSerial::~CSerial()
{
  stop_threads();
}
Ejemplo n.º 26
0
Application::~Application() {

  stop_threads();
  quit_eval();
}
Ejemplo n.º 27
0
int main (
  int	argc,
  char	*argv[]
)
{
  pwr_tStatus	sts;
  int		event;
  plc_sProcess	*pp;
  uid_t         ruid;
  struct passwd *pwd;
/*
  struct rlimit rlim;
  int i;
*/  
  /* Set core dump file size limit to infinite */
/*
  rlim.rlim_cur =  RLIM_INFINITY;
  rlim.rlim_max =  RLIM_INFINITY;
  sts = setrlimit(RLIMIT_CORE, &rlim);
  printf("%d\n", sts);
  i = 1/0;
  printf("%d\n", i);
*/
  pp = init_process();

  qcom_WaitAnd(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcInit, qcom_cTmoEternal);

  init_plc(pp);
  create_threads(pp);
  init_threads(pp);

  /* Once threads has set their priority don't run as root */
  
#if 0
  ruid = getuid();
  
  if (ruid == 0) {
    pwd = getpwnam("pwrp");
    if (pwd != NULL) {
      setreuid(pwd->pw_uid, pwd->pw_uid);
    }
  }
  else 
    setreuid(ruid, ruid);
#endif

  qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInitDone);
  qcom_WaitAnd(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcStart, qcom_cTmoEternal);

//  proc_SetPriority(pp->PlcProcess->Prio);
  set_values(pp);
  start_threads(pp);
  run_threads(pp);
  time_Uptime(&sts, &pp->PlcProcess->StartTime, NULL);

  qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcStartDone);

#if 0
  /* Force the backup to take care initialized backup objects. */

  bck_ForceBackup(NULL);
#endif

  errh_SetStatus( PWR__SRUN);

  qcom_WaitOr(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_terminate | ini_mEvent_oldPlcStop, qcom_cTmoEternal, &event);

  switch ( event) {
  case ini_mEvent_terminate:
    errh_SetStatus( PWR__SRVTERM);

    stop_threads(pp);
    clean_all(pp);
    nmps_delete_lock( &sts);
    break;
  case ini_mEvent_oldPlcStop:
    errh_SetStatus( PWR__SRVTERM);

    time_Uptime(&sts, &pp->PlcProcess->StopTime, NULL);
    stop_threads(pp);
    save_values(pp);

    qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_oldPlcStopDone);

#if defined OS_ELN
    sts = proc_SetPriority(31);
#endif

    clean_all(pp);
    break;
  default: ;
  }

  exit(0);
}
Ejemplo n.º 28
0
int main(int argc, char **argv) {
	if(parse_args(argc, argv))
		return 0;
	int err = 0;
	printf("Starting Server %s (%s)...%ld\n", version_string, compiling_date, nowtime());
	if(myconfig_init(argc, argv) < 0) {
		printf("myconfig_init fail %m\n");
		goto error;
	}
	daemon_start(argc, argv);
	umask(0);
	ICALL(init_log);
	ICALL(init_glog);
	ICALL(init_fdinfo);
	ICALL(delay_task_init);
	ICALL(init_thread);
	ICALL(init_global);
	ICALL(vfs_init);
	ICALL(init_task_info);
	ICALL(init_file_filter);
	ICALL(init_tc);
	if (get_self_info(&self_ipinfo))
	{
		LOG(glogfd, LOG_NORMAL, "get_self_role ERR!\n");
		self_ipinfo.role = ROLE_FCS;
	}
	if (self_ipinfo.role <= UNKOWN || self_ipinfo.role >= SELF_IP)
	{
		LOG(glogfd, LOG_ERROR, "get_self_role ERR!\n");
		fprintf(stderr, "get_self_role ERR!\n");
		goto error;
	}
	if (self_ipinfo.role != ROLE_VOSS_MASTER)
		ICALL(init_vfs_agent);
	char *srole = iprole[self_ipinfo.role];
	LOG(glogfd, LOG_NORMAL, "MY ROLE is %s\n", srole);

	t_thread_arg arg;
	memset(&arg, 0, sizeof(arg));
	snprintf(arg.name, sizeof(arg.name), "./%s_client.so", srole);
	LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name);
	if (ROLE_FCS != self_ipinfo.role)
	{
		arg.port = g_config.sig_port;
		arg.flag = 1;
	}
	arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096);
	if (init_vfs_thread(&arg))
		goto error;
	t_thread_arg arg1;
	memset(&arg1, 0, sizeof(arg1));
	snprintf(arg1.name, sizeof(arg1.name), "./%s_http.so", srole);
	LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg1.name);
	arg1.maxevent = myconfig_get_intval("vfs_data_maxevent", 4096);
	if (init_vfs_thread(&arg1))
		goto error;
	thread_jumbo_title();
	struct threadstat *thst = get_threadstat();
	if(start_threads() < 0)
		goto out;
	thread_reached(thst);
	gen_pidfile();	
	printf("Server Started\n");
	vfs_start_time = time(NULL);
	main_loop(thst);
out:
	printf("Stopping Server %s (%s)...\n", version_string, compiling_date);
	thread_reached(thst);
	stop_threads();
	myconfig_cleanup();
	fini_fdinfo();
	printf("Server Stopped.\n");
	return restart;
error:
	if(err == -ENOMEM) 
		printf("\n\033[31m\033[1mNO ENOUGH MEMORY\033[0m\n");
	
	printf("\033[31m\033[1mStart Fail.\033[0m\n");
	return -1;
}
Ejemplo n.º 29
0
int main(int argc, char *argv[]) {

    static struct option long_opts[] = {
        {"help",   0, NULL, 'h'},
        {0,0,0,0}
    };
    int opt, opti;
    while ((opt=getopt_long(argc,argv,"h",long_opts,&opti))!=-1) {
        switch (opt) {
        default:
        case 'h':
            usage();
            exit(0);
            break;
        }
    }

    /* Create FIFO */
    int rv = mkfifo(vegas_DAQ_CONTROL, 0666);
    if (rv!=0 && errno!=EEXIST) {
        fprintf(stderr, "vegas_daq_server: Error creating control fifo\n");
        perror("mkfifo");
        exit(1);
    }

    /* Open command FIFO for read */
#define MAX_CMD_LEN 1024
    char cmd[MAX_CMD_LEN];
    int command_fifo;
    command_fifo = open(vegas_DAQ_CONTROL, O_RDONLY | O_NONBLOCK);
    if (command_fifo<0) {
        fprintf(stderr, "vegas_daq_server: Error opening control fifo\n");
        perror("open");
        exit(1);
    }

    /* Attach to shared memory buffers */
    struct vegas_status stat;
    struct vegas_databuf *dbuf_net=NULL, *dbuf_pfb=NULL, *dbuf_acc=NULL;
    rv = vegas_status_attach(&stat);
    const int netbuf_id = 1;
    const int pfbbuf_id = 2;
    const int accbuf_id = 3;
    if (rv!=VEGAS_OK) {
        fprintf(stderr, "Error connecting to vegas_status\n");
        exit(1);
    }
    dbuf_net = vegas_databuf_attach(netbuf_id);
    if (dbuf_net==NULL) {
        fprintf(stderr, "Error connecting to vegas_databuf (raw net)\n");
        exit(1);
    }
    vegas_databuf_clear(dbuf_net);
    dbuf_pfb = vegas_databuf_attach(pfbbuf_id);
    if (dbuf_pfb==NULL) {
        fprintf(stderr, "Error connecting to vegas_databuf (accum input)\n");
        exit(1);
    }
    vegas_databuf_clear(dbuf_pfb);

    dbuf_acc = vegas_databuf_attach(accbuf_id);
    if (dbuf_acc==NULL) {
        fprintf(stderr, "Error connecting to vegas_databuf (accum output)\n");
        exit(1);
    }
    vegas_databuf_clear(dbuf_acc);

    /* Thread setup */
#define MAX_THREAD 8
    int i;
    int nthread_cur = 0;
    struct vegas_thread_args args[MAX_THREAD];
    pthread_t thread_id[MAX_THREAD];
    for (i=0; i<MAX_THREAD; i++) thread_id[i] = 0;

    /* Print start time for logs */
    time_t curtime = time(NULL);
    char tmp[256];
    printf("\nvegas_daq_server started at %s", ctime_r(&curtime,tmp));
    fflush(stdout);

    /* hmm.. keep this old signal stuff?? */
    run=1;
    srv_run=1;
    signal(SIGINT, srv_cc);
    signal(SIGTERM, srv_quit);

    /* Loop over recv'd commands, process them */
    int cmd_wait=1;
    while (cmd_wait && srv_run) {

        // Check to see if threads have exited, if so, stop them
        if (check_thread_exit(args, nthread_cur)) {
            run = 0;
            stop_threads(args, thread_id, nthread_cur);
            nthread_cur = 0;
        }

        // Heartbeat, status update
        time_t curtime;
        char timestr[32];
        char *ctmp;
        time(&curtime);
        ctime_r(&curtime, timestr);
        ctmp = strchr(timestr, '\n');
        if (ctmp!=NULL) {
            *ctmp = '\0';
        }
        else {
            timestr[0]='\0';
        }
        vegas_status_lock(&stat);
        hputs(stat.buf, "DAQPULSE", timestr);
        hputs(stat.buf, "DAQSTATE", nthread_cur==0 ? "stopped" : "running");
        vegas_status_unlock(&stat);

        // Flush any status/error/etc for logfiles
        fflush(stdout);
        fflush(stderr);

        // Wait for data on fifo
        struct pollfd pfd;
        pfd.fd = command_fifo;
        pfd.events = POLLIN;
        rv = poll(&pfd, 1, 1000);
        if (rv==0) {
            continue;
        }
        else if (rv<0) {
            if (errno!=EINTR) perror("poll");
            continue;
        }

        // If we got POLLHUP, it means the other side closed its
        // connection.  Close and reopen the FIFO to clear this
        // condition.  Is there a better/recommended way to do this?
        if (pfd.revents==POLLHUP) {
            close(command_fifo);
            command_fifo = open(vegas_DAQ_CONTROL, O_RDONLY | O_NONBLOCK);
            if (command_fifo<0) {
                fprintf(stderr,
                        "vegas_daq_server: Error opening control fifo\n");
                perror("open");
                break;
            }
            continue;
        }

        // Read the command
        memset(cmd, 0, MAX_CMD_LEN);
        rv = read(command_fifo, cmd, MAX_CMD_LEN-1);
        if (rv==0) {
            continue;
        }
        else if (rv<0) {
            if (errno==EAGAIN) {
                continue;
            }
            else {
                perror("read");
                continue;
            }
        }

        // Truncate at newline
        // TODO: allow multiple commands in one read?
        char *ptr = strchr(cmd, '\n');
        if (ptr!=NULL) *ptr='\0';

        // Process the command
        if (strncasecmp(cmd,"QUIT",MAX_CMD_LEN)==0) {
            // Exit program
            printf("Exit\n");
            run = 0;
            stop_threads(args, thread_id, nthread_cur);
            cmd_wait=0;
            continue;
        }

        else if (strncasecmp(cmd,"START",MAX_CMD_LEN)==0 ||
                 strncasecmp(cmd,"MONITOR",MAX_CMD_LEN)==0) {
            // Start observations
            // TODO : decide how to behave if observations are running
            printf("Start observations\n");

            if (nthread_cur>0) {
                printf("  observations already running!\n");
            } else {

                // Figure out which mode to start
                char obs_mode[32];
                if (strncasecmp(cmd,"START",MAX_CMD_LEN)==0) {
                    vegas_status_lock(&stat);
                    vegas_read_obs_mode(stat.buf, obs_mode);
                    vegas_status_unlock(&stat);
                } else {
                    strncpy(obs_mode, cmd, 32);
                }
                printf("  obs_mode = %s\n", obs_mode);

                // Clear out data bufs
                vegas_databuf_clear(dbuf_net);
                vegas_databuf_clear(dbuf_pfb);
                vegas_databuf_clear(dbuf_acc);


                // Do it
                run = 1;
                if (strncasecmp(obs_mode, "HBW", 4)==0) {
                    hputs(stat.buf, "BW_MODE", "high");
                    hputs(stat.buf, "SWVER", "1.4");
                    init_hbw_mode(args, &nthread_cur);
                    start_hbw_mode(args, thread_id);
                } else if (strncasecmp(obs_mode, "LBW", 4)==0) {
                    hputs(stat.buf, "BW_MODE", "low");
                    hputs(stat.buf, "SWVER", "1.4");

                    init_lbw_mode(args, &nthread_cur);
                    start_lbw_mode(args, thread_id);
                } else if (strncasecmp(obs_mode, "MONITOR", 8)==0) {
                    init_monitor_mode(args, &nthread_cur);
                    start_monitor_mode(args, thread_id);
                } else {
                    printf("  unrecognized obs_mode!\n");
                }

            }

        }

        else if (strncasecmp(cmd,"STOP",MAX_CMD_LEN)==0) {
            // Stop observations
            printf("Stop observations\n");
            run = 0;
            stop_threads(args, thread_id, nthread_cur);
            nthread_cur = 0;
        }

        else {
            // Unknown command
            printf("Unrecognized command '%s'\n", cmd);
        }
    }

    /* Stop any running threads */
    run = 0;
    stop_threads(args, thread_id, nthread_cur);

    if (command_fifo>0) close(command_fifo);

    vegas_status_lock(&stat);
    hputs(stat.buf, "DAQSTATE", "exiting");
    vegas_status_unlock(&stat);

    curtime = time(NULL);
    printf("vegas_daq_server exiting cleanly at %s\n", ctime_r(&curtime,tmp));

    fflush(stdout);
    fflush(stderr);

    /* TODO: remove FIFO */

    exit(0);
}
Ejemplo n.º 30
0
int execute_populate(CONFIG *cfg)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	pthread_t *threads;
	double secs;
	int ret;
	uint64_t elapsed, last_ops;
	struct timeval e;

	conn = cfg->conn;
	cfg->phase = WT_PERF_POP;
	lprintf(cfg, 0, 1, "Starting populate threads");

	/* First create the table. */
	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
		lprintf(cfg, ret, 0,
		    "Error opening a session on %s", cfg->home);
		return (ret);
	}

	if ((ret = session->create(
	    session, cfg->uri, cfg->table_config)) != 0) {
		lprintf(cfg, ret, 0, "Error creating table %s", cfg->uri);
		session->close(session, NULL);
		return (ret);
	}
	session->close(session, NULL);

	if ((ret = start_threads(
	    cfg, cfg->populate_threads, &threads, populate_thread)) != 0)
		return (ret);

	gettimeofday(&cfg->phase_start_time, NULL);
	for (cfg->elapsed_time = 0, elapsed = last_ops = 0;
	    g_npop_ops < cfg->icount &&
	    g_threads_quit < cfg->populate_threads;) {
		/*
		 * Sleep for 100th of a second, report_interval is in second
		 * granularity, so adjust accordingly.
		 */
		usleep(10000);
		elapsed += 1;
		if (elapsed % 100 == 0 &&
		    (elapsed / 100) % cfg->report_interval == 0) {
			lprintf(cfg, 0, 1, "%" PRIu64 " ops in %d secs",
			    g_npop_ops - last_ops, cfg->report_interval);
			last_ops = g_npop_ops;
		}
	}
	if (g_threads_quit == cfg->populate_threads) {
		lprintf(cfg, WT_ERROR, 0,
		    "Populate threads exited without finishing.");
		return (WT_ERROR);
	}
	gettimeofday(&e, NULL);

	if ((ret = stop_threads(cfg, cfg->populate_threads, threads)) != 0)
		return (ret);

	lprintf(cfg, 0, 1,
	    "Finished load of %d items", cfg->icount);
	secs = e.tv_sec + e.tv_usec / 1000000.0;
	secs -= (cfg->phase_start_time.tv_sec +
	    cfg->phase_start_time.tv_usec / 1000000.0);
	if (secs == 0)
		++secs;
	lprintf(cfg, 0, 1,
	    "Load time: %.2f\n" "load ops/sec: %.2f",
	    secs, cfg->icount / secs);

	return (0);
}