Esempio n. 1
0
int
start_server(GError **error)
{
	if (!*unix_socket_path && inet_socket_port <= 0) {
		GSETERROR(error, "No server configured");
		return 0;
	}
	if (unix_socket_path[0]) {
		if (!start_unix_server(error)) {
			GSETERROR(error,"Failed to start the UNIX server");
			stop_server();
			return 0;
		}
	}
	
	if (inet_socket_port > 0) {
		if (!start_inet_server(error)) {
			GSETERROR(error,"Failed to start the INET server");
			stop_server();
			return 0;
		}
	}

	return 1;
}
Esempio n. 2
0
void upgrade_database(const char *dbname) {

    /** public function - see header */

    //check database is open
    check_db_open(GET_CALL_INFO);

    load_db_game_data();

    //compare database version entry with the hard-coded version in the code-base
    if(game_data.database_version==REQUIRED_DATABASE_VERSION) {

        fprintf(stderr,"Database [%s] is already up to date at version [%i]\n", dbname, REQUIRED_DATABASE_VERSION);
        log_event(EVENT_ERROR, "Database [%s] is already up to date at version [%i]", dbname, REQUIRED_DATABASE_VERSION);
        stop_server();
    }
    else if(game_data.database_version>REQUIRED_DATABASE_VERSION) {

        fprintf(stderr,"Database [%s] is version [%i] which is newer than this codebase version [%i]\n", dbname, game_data.database_version, REQUIRED_DATABASE_VERSION);
        log_event(EVENT_ERROR, "Database [%s] is version [%i] which is newer than this codebase version [%i]", dbname, game_data.database_version, REQUIRED_DATABASE_VERSION);
        stop_server();
    }

    while(game_data.database_version<REQUIRED_DATABASE_VERSION) {

        // find the function that upgrades the database to the next version
        const struct upgrade_array_entry *entry = find_upgrade_entry(game_data.database_version);

        if(!entry){

            log_event(EVENT_ERROR, "can't find entry for database in function %s: module %s: line %i", GET_CALL_INFO);
            stop_server();
        }

        fprintf(stderr,"Database version update %d to %d\n", entry->from_version, entry->to_version);
        log_event(EVENT_ERROR, "Database version update %d to %d:", entry->from_version, entry->to_version);

        // backup is created before calling each upgrade function
        create_backup_file(dbname);

        if(entry->fn(dbname)==0) {

            game_data.database_version = entry->to_version;
            fprintf(stderr,"Database update successful\n");
            log_event(EVENT_ERROR, "Database update successful");
        }
        else {

            fprintf(stderr,"Database update failed\n");
            log_event(EVENT_ERROR, "Database update failed");
            stop_server();
        }
    }
}
Esempio n. 3
0
void load_db_e3ds(){

    /** public function - see header */

    log_event(EVENT_INITIALISATION, "loading e3d...");

    sqlite3_stmt *stmt;

     //check database is open and table exists
    check_db_open(GET_CALL_INFO);
    check_table_exists("E3D_TABLE", GET_CALL_INFO);

    char *sql="SELECT * FROM E3D_TABLE";

    prepare_query(sql, &stmt, GET_CALL_INFO);

    //read the sql query result into the e3d array
    int i=0;
    int rc=0;

    while ( (rc = sqlite3_step(stmt)) == SQLITE_ROW) {

        //get the object id and check that the value does not exceed the maximum permitted
        int id=sqlite3_column_int(stmt,0);

        if(id>MAX_E3D_TYPES){

            log_event(EVENT_ERROR, "id [%i] exceeds range [%i] in function %s: module %s: line %i", id, MAX_E3D_TYPES, GET_CALL_INFO);
            stop_server();
        }

        //handle null string which would crash strcpy
        if(sqlite3_column_text(stmt, 1)) strcpy(e3ds.e3d[id].e3d_filename, (char*)sqlite3_column_text(stmt, 1));

        e3ds.e3d[id].object_id=sqlite3_column_int(stmt, 2);

        log_event(EVENT_INITIALISATION, "loaded [%i] [%s]", id, e3ds.e3d[id].e3d_filename);

        i++;
    }

    destroy_query(sql, &stmt, GET_CALL_INFO);

    if(i==0){

        log_event(EVENT_ERROR, "no e3ds found in database", i);
        stop_server();
    }
}
void load_db_char_races(){

    /** public function - see header */

     //check database is open and table exists
    check_db_open(GET_CALL_INFO);
    check_table_exists("RACE_TABLE", GET_CALL_INFO);

    log_event(EVENT_INITIALISATION, "loading races...");

    sqlite3_stmt *stmt;
    char *sql="SELECT * FROM RACE_TABLE";

    prepare_query(sql, &stmt, GET_CALL_INFO);

    //read the sql query result into the race array
    int i=0;
    int rc=0;

    while ( (rc = sqlite3_step(stmt)) == SQLITE_ROW) {

        int race_id=sqlite3_column_int(stmt, 0);

        if(race_id>MAX_RACES) {

            log_event(EVENT_ERROR, "race_id [%i] exceeds max [%i] in function %s: module %s: line %i", race_id, MAX_RACES, GET_CALL_INFO);
            stop_server();
        }

        //handle null string which would crash strcpy
        if(sqlite3_column_text(stmt, 1)) strcpy(races.race[race_id].race_name, (char*)sqlite3_column_text(stmt, 1));

        //handle null string which would crash strcpy
        if(sqlite3_column_text(stmt, 2)) strcpy(races.race[race_id].race_description, (char*)sqlite3_column_text(stmt, 2));

        log_event(EVENT_INITIALISATION, "loaded [%i] [%s]", race_id, races.race[race_id].race_name);

        i++;
    }

    destroy_query(sql, &stmt, GET_CALL_INFO);

    if(i==0){

        log_event(EVENT_ERROR, "no races found in database", i);
        stop_server();
    }
}
Esempio n. 5
0
// Status check function
void check_timerfunc(void *arg) {
    struct ip_info ipConfig;
    wifi_get_ip_info(STATION_IF, &ipConfig);
    if (ipConfig.ip.addr != 0) {
        connection_status = CONNECTION_CONNECTED;
        //ets_uart_printf("[check_timerfunc] Connected? ");
        ets_uart_printf("C %d.%d.%d.%d\r\n", IP2STR(&ipConfig.ip));
        //ets_uart_printf("C");

        if (mode == MODE_AP) {
            // Just Station and no AP
            setup_stationmode();
            // Turn off HTTP server
            stop_server();
        }

    } else if (connection_status == CONNECTION_CONNECTING) {
        ets_uart_printf("X");
        //print("[check_timerfunc] No IP");
    } else {
        ets_uart_printf("U");
        if (mode != MODE_AP) {
            // Setup AP and Server
            setup_ap();
            setup_server();
        }
    }
}
Esempio n. 6
0
/**
* Walk trackdir and clean up based on conf settings.
*
* For each entry in the trackdir, we check to see if it is
* defined in the super.conf file. If not, then we try to kill the
* server and clean up. Currently, this is only possible if the pid
* file of the running server is present and we kill(). However, this
* is not perfect since the pid is not guaranteed to belong to the
* server (for various reasons). Ideally, if we could simply remove
* the socket file and have the server process "find out" then the
* clean up would be trivial: remove().
*
* @return		0 on success; -1 on failure
*/
int
clean_trackdir(void) {
	DIR		*dirp;
	struct dirent	*dire;
	char		svrname[RUSS_REQ_SPATH_MAX];
	int		n;

	if ((dirp = opendir(trackdir)) == NULL) {
		return -1;
	}
	for (dire = readdir(dirp); dire != NULL; dire = readdir(dirp)) {
		if (dire->d_name[0] == '.') {
			/* ignore ., .., and hidden files */
			continue;
		}
		if (((n = snprintf(svrname, sizeof(svrname), "/%s", dire->d_name)) < 0)
			|| (n >= sizeof(svrname))
			|| (stop_server(svrname) < 0)) {
			// bufsize problem or failed; what to do?
			fprintf(stderr, "warning: failed to stop server (%s)\n", svrname);
		}
	}
	closedir(dirp);
	return 0;
}
void
F::start ()
{
  int retries = 0;

  std::unique_lock <std::mutex> lock (mutex);

  id = 0;

  start_server();
  BOOST_REQUIRE_MESSAGE (pid > 0, "Error launching mediaserver");

  clientThread = std::thread (std::bind (&F::start_client, this) );

  while (!initialized && retries < MAX_RETRIES) {
    lock.unlock();
    std::this_thread::sleep_for (std::chrono::milliseconds (100 * (retries + 1) ) );
    lock.lock();

    if (!initialized) {
      GST_INFO ("Waiting, %d times", retries);
      retries++;
    }
  }

  if (!initialized) {
    stop_client (lock);
    lock.unlock();

    stop_server ();
  }

  BOOST_REQUIRE_MESSAGE (initialized, "Cannot connect to the server");
}
Esempio n. 8
0
File: test.c Progetto: sureshkvl/onm
void main()
{
	int retries=0;
	if(netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,NETSNMP_DS_AGENT_ROLE,1))
	{

            printf("netsnmp_ds_set_boolean failed");
            return;
	}

	//initialize the agent
	while(0!=init_agent("mysnmpagent"))
	{
	     printf("init_agent failed\n");
	     sleep(1);
	}
	netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL,5);

	//mib initialization code
	init_mysnmpagent();
	init_snmp("mysnmpagent");
	keep_running=1;
	printf("My agent starting...\n");
	while(keep_running)
	{
	  if(-1==agent_check_and_process(1))
	     printf("agent_check_and process failed\n");
	}
	stop_server();
	return;
}
Esempio n. 9
0
void agent_impl::release()
{
	if (!running_)
	{
		return;
	}

	{
		std::unique_lock<std::mutex> ul(mutex_conn_);
		for (auto iter = conn_map_.begin();
			iter != conn_map_.end(); ++iter)
		{
			iter->second->close();
		}
		conn_map_.clear();
	}
	
	stop_server();
	for (unsigned i = 0; i < thread_num_; ++i)
	{
		threads_[i].stop();
	}
	delete [] threads_;
	running_ = false;
	delete this;
}
Esempio n. 10
0
void server_close(){
    ioservice_close();
    if (stop_server(server_socket) == -1) {
        log_message("Server stop failed");
        exit(EXIT_FAILURE);
    }
    log_message("Server stopped");
}
Esempio n. 11
0
	//Call update on server and/or client
	void Network::update() {
		if (has_server && server)
			if (!server->update())
				stop_server();
		if (has_client && client)
			if (!client->update())
				stop_client();
	}
Esempio n. 12
0
void handle_user_input(connection_info clients[])
{
  char input[255];
  fgets(input, sizeof(input), stdin);
  trim_newline(input);

  if(input[0] == 'q') {
    stop_server(clients);
  }
}
Esempio n. 13
0
int32_t agent_impl::start_server(unsigned short port)
{
	stop_server();
	acceptor_.reset(new acceptor(*this, get_io_service()));
	int32_t ret = acceptor_->start(port, net_callback_);
	if (ret != 0)
	{
		acceptor_.reset();
	}
	return 0;
}
Esempio n. 14
0
int
start_server(long sock_timeout, GError **error)
{
	if (!start_unix_server(sock_timeout,error)) {
		GSETERROR(error,"Failed to start the UNIX server");
		stop_server();
		return 0;
	}
	
	if (port_inet<0)
		NOTICE("No INET port provided, no INET server started");
	else {
		if (!start_inet_server(sock_timeout,error)) {
			GSETERROR(error,"Failed to start the INET server");
			stop_server();
			return 0;
		}
	}

	return 1;
}
Esempio n. 15
0
void
F::stop()
{
  std::unique_lock <std::mutex> lock (mutex);

  if (initialized) {
    stop_client (lock);
  }

  initialized = false;

  lock.unlock();

  stop_server ();
}
Esempio n. 16
0
static void idaapi run(int arg)
{

	unsigned short loadfile = 0;
	unsigned int sport = 1234, eport = 1239;
	char ip[16] = "0.0.0.0";
	const char * filename;

	char foo[] =
		"STARTITEM 3\n" // shortcut to quickly load files, etc
		"IdaRub!\n"
		"Sucka Free!\n\n"
		"<Listen IP  :A:15:15::>\n"
		"<Start Port :D:5:5::>\n"
		"<End Port   :D:5:5::>\n"
		"<Start Server:R><Load File:R><Load Last File:R>>\n\n\n\n";
	
	// make sure ruby has been loaded...
	init_ruby();

	if(server_running()) {
		if(!AskUsingForm_c("IdaRub!\nStop Server\n\n"))
			return;

		stop_server();
		msg(LPREFIX "stopped the rub\n");
	}
	else {
		if(!AskUsingForm_c(foo, &ip, &sport, &eport, &loadfile))
			return;

		switch(loadfile) {
		case 2: // Load Last File
			run_ruby_file(NULL);
			break;
		case 1: // Load File
			filename = askfile_c(0, "*.rb", "Select Ruby script...");
			if(filename)
				run_ruby_file(filename);
			break;
		case 0: // Start Server
			start_server(ip, sport, eport);
			break;
		}
	}
}
Esempio n. 17
0
/******************************************************************************

  stop_master()

  Stop the master server.

******************************************************************************/
void stop_master()
{
  int err;

  // running?
  if (!master_running) return;

  if ((err = stop_server(bin_dir, user, password, master_port, master_pid,
                         mysql_tmp_dir)) == 0)
  {
    master_running = FALSE;
  }
  else
  {
    log_error("Unable to stop master server.");
  }
}
Esempio n. 18
0
File: main.c Progetto: irontec/isaac
void
quit(int exitcode)
{
    printf("Signal %d received\n", exitcode);
    // Stop server thread
    stop_server();
    // Stop CLI server thread
    cli_server_stop();
    // Stop manager thread
    stop_manager();
    // Remove all loaded modules. They should unregister their apps
    unload_modules();
    // if requested to restart
    //if (sig == SIGHUP) execvp(_argv[0], _argv);
    // Exit the program!
    exit(exitcode);
}
Esempio n. 19
0
int vm_main() {

  int ret;

  ret = start_server();
  if (ret < 0)
    return 0;

  for (;;) {
    int socket_fd = accept_new_client();
    if (socket_fd < 0)
      return -1;
    vm_run(socket_fd);
  }

  stop_server();
  return 0;
}
Esempio n. 20
0
/******************************************************************************

  stop_slave()

  Stop the slave server.

******************************************************************************/
void stop_slave()
{
  int err;

  // running?
  if (!slave_running) return;

  // stop
  if ((err = stop_server(bin_dir, user, password, slave_port, slave_pid,
                         mysql_tmp_dir)) == 0)
  {
    slave_running = FALSE;
  }
  else
  {
    log_error("Unable to stop slave server.");
  }
}
Esempio n. 21
0
int main(int argc, char **argv) {
  int sockfd = -1;
  int port = 20000;

  if (init_server(port, &sockfd) != 0) {
    fprintf(stderr, "Failed to create the server\n");
    return 1;
  }

  if (start_server(sockfd) != 0) {
    fprintf(stderr, "Failed to start the server\n");
    return 1;
  }

  sleep(30);

  stop_server(sockfd);

  exit(EXIT_SUCCESS);
}
TEST_F(ServerShutdown, server_can_shut_down_when_clients_are_blocked)
{
    struct ServerConfig : mtf::TestingServerConfiguration
    {
        // Don't consume frames, so the clients can block waiting for a buffer
        std::shared_ptr<mc::DisplayBufferCompositorFactory> the_display_buffer_compositor_factory() override
        {
            return display_buffer_compositor_factory(
                [] { return std::make_shared<mtd::NullDisplayBufferCompositorFactory>(); });
        }
        // Don't drop frames, so the clients can block waiting for a buffer
        std::shared_ptr<mc::FrameDroppingPolicyFactory> the_frame_dropping_policy_factory() override
        {
            return frame_dropping_policy_factory(
                [] { return std::make_shared<mtd::StubFrameDroppingPolicyFactory>(); });
        }
    };
    server_configuration.reset(new ServerConfig{});

    start_server();

    ClientWithSurface client1{new_connection()};
    ClientWithSurface client2{new_connection()};
    ClientWithSurface client3{new_connection()};

    client1.swap_sync();
    // Ask for the second buffer (should block)
    client1.swap_async();

    client2.swap_sync();
    // Ask for the second buffer (should block)
    client2.swap_async();

    client3.swap_sync();
    // Ask for the second buffer (should block)
    client3.swap_async();

    // Shutting down the server should not block
    stop_server();
}
Esempio n. 23
0
int udp_cmd(int argc, char **argv)
{
    if (argc < 2) {
        printf("usage: %s [send|server]\n", argv[0]);
        return 1;
    }

    if (strcmp(argv[1], "send") == 0) {
        if (argc < 5) {
            printf("usage: %s send <addr> <port> <data>\n", argv[0]);
            return 1;
        }
        send(argv[2], argv[3], argv[4]);
    }
    else if (strcmp(argv[1], "server") == 0) {
        if (argc < 3) {
            printf("usage: %s server [start|stop]\n", argv[0]);
            return 1;
        }
        if (strcmp(argv[2], "start") == 0) {
            if (argc < 4) {
                printf("usage %s server start <port>\n", argv[0]);
                return 1;
            }
            start_server(argv[3]);
        }
        else if (strcmp(argv[2], "stop") == 0) {
            stop_server();
        }
        else {
            puts("error: invalid command");
        }
    }
    else {
        puts("error: invalid command");
    }
    return 0;
}
Esempio n. 24
0
int get_move_command(int tile_pos, int tile_dest, int map_axis){

    /** RESULT  : calculates the move command based on the current and destination tile

        RETURNS : move command

        PURPOSE :

        NOTES   :
    */

    int i=0;
    int move=tile_dest-tile_pos;

    if(move==map_axis) i=0;

    else if(move==map_axis+1) i=1;

    else if(move==map_axis-1) i=7;

    else if(move==(map_axis*-1)) i=4;

    else if(move==(map_axis*-1)+1) i=3;

    else if(move==(map_axis*-1)-1) i=5;

    else if(move==1) i=2;

    else if(move==-1) i=6;

    else {
        log_event(EVENT_MOVE_ERROR, "illegal move in function %s: module %s: line %i", __func__, __FILE__, __LINE__);
        log_text(EVENT_MOVE_ERROR, "current tile [%i] destination tile [%i] move distance [%i]", tile_pos, tile_dest, move);
        stop_server();
    }

    return vector[i].move_cmd;
}
Esempio n. 25
0
static void signal_handler_server(int signal, siginfo_t *sig_info, void *ucontext_t_casted)
{
	switch (signal)
	{	
	case SIGCHLD:
		{
		int status = -1;

		while (waitpid(-1, &status, WNOHANG) > 0)
		{
			if (WIFEXITED(status))
			{
				DEBUG("child process terminated with exit code %d\n", WEXITSTATUS(status));
			}
			else if (WIFSIGNALED(status))
			{
				DEBUG("child process killed by signal %d\n", WTERMSIG(status));
			}
		}

		}
		break;
	
	case SIGHUP:
	case SIGTERM:
	case SIGINT:
		stop_server(&rfsd_instance);
		exit(0);
		
	case SIGALRM:
		check_keep_alive(&rfsd_instance);
		break;
		
	case SIGPIPE:
		break;
	}
}
Esempio n. 26
0
File: main.c Progetto: Xion/reefs
int main(int argc, char* argv[])
{
    char* config_file;

    switch (argc)
    {
        case 1:     config_file = DEFAULT_CONFIG_FILE;  break;
        case 2:     config_file = argv[1];              break;
        default:    usage();                            return EXIT_FAILURE;
    }

    struct sigaction sa;
    sa.sa_handler = SIG_IGN;    if (sigaction(SIGPIPE, &sa, NULL) == -1)    FATAL("Ignoring SIGPIPE");
    sa.sa_handler = sig_INT;    if (sigaction(SIGINT, &sa, NULL) == -1)     FATAL("Handling SIGINT");

    struct server serv;
    if (init_server(config_file, &serv) == -1)
    {
        fprintf (stderr, "%s", "Error during server's initialization.\n");
        perror (":");        return EXIT_FAILURE;
    }

    srand ((unsigned)time(0));
    if (start_server(&serv) == -1)
    {
        fprintf (stderr, "%s", "Could not start server.\n");
        perror (":");        return EXIT_FAILURE;
    }

    if (stop_server(&serv) == -1)
    {
        fprintf (stderr, "%s", "Error during server's shutdown.\n");
        perror(":");         return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
Esempio n. 27
0
void *launch_thread(void * p){
	Params params = (Params) p;

	switch(params->mode){
		case 1 : start_server();
			break;
		case 2 : stop_server();
			break;
		case 3 : take_snap();
			break;
		case 4 : start_video_record(params->duration);
			break;
		case 5 : start_motion_detector();
			break;
		case 6 : stop_motion_detector();
			break;
		case 7 : play_sound("meow");
			break;
		case 8 : play_sound("bug");
			break;
		default:;
	}
    pthread_exit(NULL);
}
TEST_F(ServerShutdown, server_releases_resources_on_shutdown_with_connected_clients)
{
    server_configuration.reset(new mtf::TestingServerConfiguration{});

    start_server();

    ClientWithSurface client1{new_connection()};
    ClientWithSurface client2{new_connection()};
    ClientWithSurface client3{new_connection()};

    stop_server();

    std::weak_ptr<mir::graphics::Display> display = server_configuration->the_display();
    std::weak_ptr<mir::compositor::Compositor> compositor = server_configuration->the_compositor();
    std::weak_ptr<mir::frontend::Connector> connector = server_configuration->the_connector();
    std::weak_ptr<mi::InputManager> input_manager = server_configuration->the_input_manager();

    server_configuration.reset();

    EXPECT_EQ(0, display.use_count());
    EXPECT_EQ(0, compositor.use_count());
    EXPECT_EQ(0, connector.use_count());
    EXPECT_EQ(0, input_manager.use_count());
}
Esempio n. 29
0
int main()
{
	char **postvars = NULL;	/* POST request data repository */
	char **getvars = NULL;	/* GET request data repository */
	int form_method;	/* POST = 1, GET = 0 */
	s_info *info = &sinfo;

	form_method = getRequestMethod();

	if (form_method == POST) {
		getvars = getGETvars();
		postvars = getPOSTvars();
	} else if (form_method == GET) {
		getvars = getGETvars();
	}

	MakeSessionFiles(info);
	ParseRequest(form_method, getvars, postvars, info);
	CheckRequest(form_method, getvars, postvars, info);

	switch (info->run) {

	case ACQUIRE:
		AllocateMemory(form_method, getvars, postvars, info);
		MakeFileInit(info, form_method, getvars, postvars);
		MakeFileSamples(form_method, getvars, postvars, info);
		free(info->samples);
		system(info->pGNUPLOT);
		DoHTML(info, form_method, getvars, postvars);
		break;

	case REPLOT:
		MakeFileInit(info, form_method, getvars, postvars);
		system(info->pGNUPLOT);
		DoHTML(info, form_method, getvars, postvars);
		break;

	case START_SERVER:
		stop_server(form_method, getvars, postvars, info);
		DoHTML(info, form_method, getvars, postvars);
		AllocateMemory(form_method, getvars, postvars, info);
		MakeFileSamples(form_method, getvars, postvars, info);
		free(info->samples);
		start_server(form_method, getvars, postvars, info);
		break;

	case STOP_SERVER:
		DoHTML(info, form_method, getvars, postvars);
		stop_server(form_method, getvars, postvars, info);
		break;

	case MULTIMETER:
		break;

	case SHOWSAMPLES:
		break;

	case GNUPLOT_FILES:
		DoHTML(info, form_method, getvars, postvars);
		break;

	default:

		break;
	}

	cleanUp(form_method, getvars, postvars);
	CleanupSessionFiles(info);
	exit(0);
}
Esempio n. 30
0
RemoteControl::~RemoteControl()
{
    stop_server();
}