Ejemplo n.º 1
0
void sighup_cb(struct ev_loop *loop, struct ev_signal *w, int revents)
{
	g_warning("%s loop %p w %p revents %i",__PRETTY_FUNCTION__, loop, w, revents);

	g_info("Reloading config");
	if( (g_dionaea->config.config = lcfg_new(g_dionaea->config.name)) == NULL )
	{
		g_critical("config not found");
	}

	if( lcfg_parse(g_dionaea->config.config) != lcfg_status_ok )
	{
		g_critical("lcfg error: %s\n", lcfg_error_get(g_dionaea->config.config));
	}

	g_dionaea->config.root = lcfgx_tree_new(g_dionaea->config.config);


	// modules ...
	modules_hup();

	// loggers hup
	for( GList *it = g_dionaea->logging->loggers; it != NULL; it = it->next )
	{
		struct logger *l = it->data;
		g_message("Logger %p hup %p", l, l->log);
		if( l->hup != NULL )
			l->hup(l, l->data);
	}
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
	pthread_t temperature_thread,templog_thread,setpoint_thread;
	int not_connect = 0;
	int c;
	char *channel = NULL;
	pthread_mutex_t mutex;
	pthread_cond_t condvar;
	int ret;
	int done = 0;
	gre_io_t *send_handle;
	thdata data1;
	size_t len;
	struct lcfg *cfg = lcfg_new("./brew.cfg");
	
	//open the log
	openlog("Fermtroller", LOG_PID, LOG_USER);

	if ( lcfg_parse(cfg) != lcfg_status_ok ) {
		syslog(LOG_INFO,"Error reading config file : %s\n", lcfg_error_get(cfg));
	} else {
		lcfg_accept(cfg, read_cfg,0);
	}

	lcfg_value_get(cfg, "wort_address",(void *)&temp_wort, &len);
	lcfg_value_get(cfg, "ambient_address",(void *)&temp_ambient, &len);
	if ( lcfg_value_get(cfg, "web_address", (void *)&web_address, &len) != lcfg_status_ok ) {
		syslog(LOG_ERR,"Error reading web_address : %s\n", lcfg_error_get(cfg));
	}
	lcfg_value_get(cfg, "user",(void *)&user,&len);
	lcfg_value_get(cfg,"pass",(void *)&pass,&len);

	// assign the GPIO file descriptors
	
 	cool_fd = open(cool_control,O_WRONLY);
	heat_fd = open(heat_control,O_WRONLY);

	data1.temp_data.temp1 = 0.0;
	data1.temp_data.temp2 = 0.0;
	data1.good_read = 0;	
	data1.heatcool = 1;
	data1.debug = 0;
	data1.read_freq = 30; // default read frequency is 30 seconds
	control_temp("0","0");
	while ((c = getopt( argc, argv, "vc:p:t:r:")) != -1 )
	{
		switch(c)
		{
			case 'v':
				data1.debug = 1;
				break;
			case 'c':
				channel = optarg;
				syslog(LOG_INFO,"Setting channel to : %s\n", channel);
				break;
			case 't':
				data1.temp_data.set_point= atof(optarg);
				syslog(LOG_INFO,"Setting Ferment temp to %f\n", data1.temp_data.set_point);
				break;
			case 'r':
				data1.read_freq = atoi(optarg);
				syslog(LOG_INFO,"Setting read frequency to %d\n", data1.read_freq);
				break;

		}
	}
#ifdef STORYBOARD
	if ( channel == NULL ) {
		syslog(LOG_ERR,"You must supply a greio channel temp_driver -c <storyboard channel>\n");
		exit(-1);
	}
	send_handle = gre_io_open(channel, GRE_IO_TYPE_WRONLY);
	if(send_handle == NULL && channel != NULL ) {
		syslog(LOG_ERR,"Can't open send handle\n");
		while ( not_connect == 0 ) {
			send_handle = gre_io_open(channel, GRE_IO_TYPE_WRONLY);
			if ( send_handle != NULL ) {
				not_connect = 1;
			}
			syslog(LOG_INFO,"Waiting to connect\n");
			sleep(1);
		}
	}

	// push the send handle into the thread data pointer so we can access it in our check_tmep thread.
	data1.send_handle = send_handle;
#endif
	FILE * t_fd = fopen("/tmp/set_point", "r");
	char temp_buf[32];
	long length;
	if ( t_fd ) {
		while ( fgets(temp_buf, 32, t_fd) != NULL )  {
		}
	}
	fclose(t_fd);
	if ( temp_buf ) {
		data1.temp_data.set_point = atof(temp_buf);
		syslog(LOG_DEBUG, "Setpoint converted to float is %f\n", data1.temp_data.set_point);
	}
	syslog(LOG_INFO,"Fermtroller starting");
	pthread_create(&temperature_thread, NULL, (void *)&check_temperature, &data1);
	sleep(1);
	pthread_create(&templog_thread, NULL, (void *)&log_temp, &data1);
	pthread_create(&setpoint_thread, NULL, (void *)&read_setpoint, &data1);
	ret = pthread_mutex_init(&mutex, NULL);
	if(ret != 0) {
		syslog(LOG_ERR,"Mutex error\n");
		return -1;
	}

	ret = pthread_cond_init(&condvar, NULL);
	if(ret != 0) {
		syslog(LOG_ERR,"Condvar error\n");
		return -1;
	}
	
	//get_input(&data1);
	while(!done) {
		syslog(LOG_INFO,"waiting\n");
		pthread_mutex_lock(&mutex);
		pthread_cond_wait(&condvar, &mutex);
	}


	lcfg_delete(cfg);
	free (temp_wort);
	free (temp_ambient);
	free (web_address);
	free (user);
	free (pass);
	syslog(LOG_INFO,"Fermtroller shutting down\n");

	close(cool_fd);
	close(heat_fd);
	closelog();
	return 0;
}
Ejemplo n.º 3
0
int main ( int argc, char const *const *argv )
{
    if ( argc != 3 )
    {
        printf ( "usage: %s CFG_FILE LOG_FILE\n", argv[0] );

        return -1;
    }

    const char *log_filename = argv[2];
    int flags = O_CREAT | O_APPEND | O_RDWR;
    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
    int log_fd = open ( log_filename, flags, mode );

    if ( log_fd < 0 )
    {
        fprintf ( stderr, "ERROR: Falied to open the log file '%s'\n", log_filename );

        exit ( 1 );
    }

    /* Read the configuration file. */
    struct lcfg *cfg = lcfg_new ( argv[1] );

    if ( lcfg_parse ( cfg ) != lcfg_status_ok )
    {
        printf ( "lcfg error: %s\n", lcfg_error_get ( cfg ) );

        return -1;
    }

    /* Read all the configuration parameters. */
    fprintf ( stdout, "Starting Murano agent with the following configuration:\n\n" );

    const char *host = get_config_value ( cfg, "RABBITMQ_HOST" , 1 );
    int port = atoi ( get_config_value ( cfg, "RABBITMQ_PORT" , 1 ) );
    const char *vhost = get_config_value ( cfg, "RABBITMQ_VHOST"  , 1 );
    const char *username = get_config_value ( cfg, "RABBITMQ_USERNAME"  , 1 );
    const char *password = get_config_value ( cfg, "RABBITMQ_PASSWORD"  , 1 );
    const char *queuename = get_config_value ( cfg, "RABBITMQ_INPUT_QUEUE"  , 1 );
    const char *result_routing_key = get_config_value ( cfg, "RABBITMQ_RESULT_ROUTING_KEY", 1 );

    amqp_connection_state_t conn = amqp_new_connection();
    amqp_socket_t *socket = NULL;
    amqp_bytes_t queuename_bytes = amqp_cstring_bytes ( queuename );

    socket = amqp_tcp_socket_new ( conn );
    if ( !socket )
    {
        die ( "creating TCP socket" );
    }

    if ( amqp_socket_open ( socket, host, port ) )
    {
        die ( "opening TCP socket" );
    }

    die_on_amqp_error ( amqp_login ( conn, vhost, 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, username, password ),
                        "Logging in" );
    amqp_channel_open ( conn, 1 );
    die_on_amqp_error ( amqp_get_rpc_reply ( conn ), "Opening channel" );

    amqp_basic_consume ( conn, 1, queuename_bytes, amqp_empty_bytes, 0, 1, 0, amqp_empty_table );
    die_on_amqp_error ( amqp_get_rpc_reply ( conn ), "Consuming" );

    puts ( "\nSuccessfully connected to Rabbit MQ server! Ready for messages..." );

    run ( conn, log_fd , result_routing_key );

    close ( log_fd );
    lcfg_delete ( cfg );

    die_on_amqp_error ( amqp_channel_close ( conn, 1, AMQP_REPLY_SUCCESS ), "Closing channel" );
    die_on_amqp_error ( amqp_connection_close ( conn, AMQP_REPLY_SUCCESS ), "Closing connection" );
    die_on_error ( amqp_destroy_connection ( conn ), "Ending connection" );

    return 0;
}