Пример #1
0
void free_config(void)
{
	hfree(logdir);
	hfree(pidfile);
	
	if (cfgfile != def_cfgfile)
		hfree(cfgfile);
	
	if (logname != def_logname)
		hfree(logname);
	
	if (sound_device != def_sound_device)
		hfree(sound_device);
	
	hfree(sound_in_file);
	hfree(sound_out_file);
	hfree(mysql_host);
	hfree(mysql_db);
	hfree(mysql_user);
	hfree(mysql_password);
	hfree(serial_port);
	
	hfree(mycall);
	hfree(myemail);
	
	free_uplink_config(&uplink_config);
}
Пример #2
0
void uplink_stop(void)
{
	int i, e;
	
	if (!uplink_running)
		return;
	
	hlog(LOG_INFO, "Signalling uplink_thread to shut down...");
	uplink_shutting_down = 1;
	
	if ((e = pthread_join(uplink_th, NULL))) { 
		hlog(LOG_ERR, "Could not pthread_join uplink_th: %s", strerror(e));
	} else {
		hlog(LOG_INFO, "Uplink thread has terminated.");
		uplink_running = 0;
	}
	
	/* free uplink config - and clean up the uplink_client indexed pointers
	 * which refer to the configs
	 */
	if ((e = pthread_mutex_lock(&uplink_client_mutex))) {
		hlog( LOG_ERR, "uplink_stop(): could not lock uplink_client_mutex: %s", strerror(e) );
		return;
	}
	
	for (i = 0; i < MAX_UPLINKS; i++)
		uplink_client[i] = NULL;
	
	free_uplink_config(&uplink_config);
	
	if ((e = pthread_mutex_unlock(&uplink_client_mutex))) {
		hlog( LOG_ERR, "uplink_stop(): could not unlock uplink_client_mutex: %s", strerror(e) );
		return;
	}
}
Пример #3
0
int read_config(void)
{
	int failed = 0;
	char *s;
	
	if (read_cfgfile(cfgfile, cfg_cmds))
		return -1;
	
	/* these parameters will only be used when reading the configuration
	 * for the first time.
	 */
	if(log_dir){	/* Check if logdir passed from command line. In that case config file parameter should be ignored*/
		logdir = hstrdup(log_dir);	
	}
	else if(!logdir) { /* Using current directory as default if not given neither in config file or command line */
		if(log_dest == L_FILE)
			hlog(LOG_WARNING, "Config: logdir not defined. Using . as log directory");
		logdir = hstrdup(".");
	}

	/* mycall is only applied when running for the first time. */
	if (!mycall) {
		mycall = hstrdup("NOCALLDEFINED"); 
		hlog(LOG_WARNING, "Config: mycall is not defined - using: %s.",mycall);
		//failed = 1;
	} else if (!valid_aprsis_call(mycall)) {
		hlog(LOG_CRIT, "Config: mycall '%s' is not valid.", mycall);
		failed = 1;
	}
	
	if (!myemail) {
		myemail = hstrdup("notdefined@notdefined"); 
		hlog(LOG_WARNING, "Config: myemail is not defined - using: %s.",myemail);
		//failed = 1;
	}
	
	if (!sound_in_file && !sound_device) {
		sound_device = def_sound_device;
		hlog(LOG_WARNING, "Config: SoundDevice is not defined - using: %s", sound_device);
	}
	
	if (sound_in_file && sound_device) {
		if (sound_device != def_sound_device)
			hfree(sound_device);
		sound_device = NULL;
	}
	
	/* put in the new uplink config */
	free_uplink_config(&uplink_config);
	uplink_config = new_uplink_config;
	if (uplink_config)
		uplink_config->prevp = &uplink_config;
	new_uplink_config = NULL;

	if (failed)
		return -1;
	
	if (!pidfile) {
		s = hmalloc(strlen(logdir) + 1 + strlen(logname) + 3 + 2);
		sprintf(s, "%s/%s.pid", logdir, logname);
		
		pidfile = s;
	}
	
	return 0;
}
Пример #4
0
void uplink_thread(void *asdf)
{
	sigset_t sigs_to_block;
	int rc;
	int next_uplink = -1; /* the index to the next regular uplink candidate */
	int uplink_error_set = -1;
	
	pthreads_profiling_reset("uplink");
	
	sigemptyset(&sigs_to_block);
	sigaddset(&sigs_to_block, SIGALRM);
	sigaddset(&sigs_to_block, SIGINT);
	sigaddset(&sigs_to_block, SIGTERM);
	sigaddset(&sigs_to_block, SIGQUIT);
	sigaddset(&sigs_to_block, SIGHUP);
	sigaddset(&sigs_to_block, SIGURG);
	sigaddset(&sigs_to_block, SIGPIPE);
	sigaddset(&sigs_to_block, SIGUSR1);
	sigaddset(&sigs_to_block, SIGUSR2);
	pthread_sigmask(SIG_BLOCK, &sigs_to_block, NULL);
	
	//hlog(LOG_INFO, "Uplink thread starting...");
	
	uplink_reconfiguring = 1;
	while (!uplink_shutting_down) {
		if (uplink_reconfiguring || uplink_config_updated) {
			hlog(LOG_INFO, "Uplink thread applying new configuration...");
			__sync_synchronize();
			uplink_reconfiguring = 0;
			close_uplinkers();
			
			free_uplink_config(&uplink_config);
			uplink_config = uplink_config_install;
			uplink_config_install = NULL;
			if (uplink_config)
				uplink_config->prevp = &uplink_config;
			
			uplink_config_updated = 0;
			
			hlog(LOG_INFO, "Uplink thread configured.");
		}
		
		/* speed up shutdown */
		if (uplink_shutting_down || uplink_reconfiguring)
			continue;
		
		if (uplink_config_updated) {
			uplink_reconfiguring = 1;
			continue;
		}
		
		if ((rc = pthread_mutex_lock(&uplink_client_mutex))) {
			hlog(LOG_ERR, "uplink_thread(): could not lock uplink_client_mutex: %s", strerror(rc));
			continue;
		}
		
		/* Check if all we have a single regular uplink connection up, out of all
		 * the configured ones. Also, check that all the UPLINKMULTI links are
		 * connected.
		 */
		
		int has_uplink = 0; /* do we have a single regular uplink? */
		int avail_uplink = 0; /* how many regular uplinks are configured? */
		
		struct uplink_config_t *l = uplink_config;
		for (; l; l = l->next) {
			if (l->client_flags & CLFLAGS_UPLINKMULTI) {
				/* MULTI uplink, needs to be up */
				if (l->state < UPLINK_ST_CONNECTING)
					make_uplink(l);
			} else {
				/* regular uplink, need to have one connected */
				if (l->state >= UPLINK_ST_CONNECTING)
					has_uplink++;
				avail_uplink++;
			}
		}
		
		if (avail_uplink && !has_uplink) {
			hlog(LOG_INFO, "Uplink: %d uplinks configured, %d are connected, need to pick new", avail_uplink, has_uplink);
			/* we have regular uplinks but none are connected,
			 * pick the next one and connect */
			next_uplink++;
			if (next_uplink >= avail_uplink)
				next_uplink = 0;
			//hlog(LOG_DEBUG, "Uplink: picked uplink %d as the new candidate", next_uplink);
			l = uplink_config;
			int i = 0;
			while ((l) && i < next_uplink) {
				if (!(l->client_flags & CLFLAGS_UPLINKMULTI))
					i++;
				l = l->next;
			}
			if (l) {
				hlog(LOG_DEBUG, "Uplink: trying %s (%s:%s)", l->name, l->host, l->port);
				make_uplink(l);
			}
		}
		
		if ((rc = pthread_mutex_unlock(&uplink_client_mutex))) {
			hlog(LOG_CRIT, "close_uplinkers(): could not unlock uplink_client_mutex: %s", strerror(rc));
			continue;
		}
		
		if (avail_uplink && !has_uplink) {
			status_error(3600, "no_uplink");
			uplink_error_set = 1;
		} else {
			if (uplink_error_set == 1) {
				status_error(-1, "no_uplink");
				uplink_error_set = 0;
			}
		}
		
		/* sleep for 4 seconds between successful rounds */
		for (rc = 0; (!uplink_shutting_down) && rc < 4000/200; rc++)
			if (poll(NULL, 0, 200) == -1 && errno != EINTR)
				hlog(LOG_WARNING, "uplink: poll sleep failed: %s", strerror(errno));
	}
	
	hlog(LOG_DEBUG, "Uplink thread shutting down uplinking sockets...");
	close_uplinkers();
}