コード例 #1
0
ファイル: hawk.c プロジェクト: dylanfmarquis/HAwk
/*	Query MySQL/MariaDB WS_REP Status	*/
char* mysql_status(dictionary *conf, FILE *log)
{
	MYSQL *curs = mysql_init(NULL);
	MYSQL_ROW row;	
	char *entry = NULL;

	if (!curs)
	{
		entry = concat_str("ERROR - Could not create MySQL cursor: ", mysql_error(curs), NULL);
		put_log(log, entry);
		free(entry);
		return("0");
	}

	if (mysql_real_connect(curs, get_config(conf, "mysql:host"), get_config(conf, "mysql:user"), get_config(conf, "mysql:pass"), "mysql", 0, NULL, 0) == NULL)
	{
		entry = concat_str("ERROR - Could not connect to MySQL server: ", mysql_error(curs), NULL);
                put_log(log, entry);
		free(entry);
		mysql_close(curs);
		return("0");
	}
	
	if (mysql_query(curs, "SHOW STATUS LIKE 'wsrep_local_state'"))
	{
		entry = concat_str("ERROR - Could not execute query on ws_rep status: ", mysql_error(curs), NULL);
                put_log(log, entry);
		free(entry);
		mysql_close(curs);
      		return("0");
  	}

	MYSQL_RES *result = mysql_store_result(curs);
	
	if (!result)
	{
		entry = concat_str("ERROR - Could not store MySQL result: ", mysql_error(curs), NULL);
                put_log(log, entry);
		free(entry);
		mysql_close(curs);
		return("0");
	}
	
	int num_fields = mysql_num_fields(result);

	char *ws_rep_status = NULL;

	while ((row = mysql_fetch_row(result)))
	{
		for (int i=0; i < num_fields; i++)
		{
			ws_rep_status =  (row[i]);
		}
	}

	mysql_free_result(result);
	mysql_close(curs);
	return ws_rep_status;
}
コード例 #2
0
ファイル: hawk.c プロジェクト: dylanfmarquis/HAwk
/* 	Main Routine				*/
int main_construct(FILE *log, dictionary *conf, int listenfd)
{
        int connfd = 0;
        struct sockaddr_in serv_addr;
        char sendBuff[140];

        //Start main loop
        while(1)
        {

                //If data is recieved - run mysql_status and write result to socket
                connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);

                if (connfd != -1)
                {
                        char *message = "HTTP/1.1 503 Service Unavailable\r\nContent-Type: text/plain\r\nConnection: close\r\nContent-Length: 44\r\n\r\nMariaDB Cluster Node is not synced.\r\n";
                        char *status = mysql_status(conf, log);

                        if (strncmp("4", status, 1024) == 0)
                        {
                                message = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: close\r\nContent-Length: 40\r\n\r\nMariaDB Cluster Node is synced.\r\n";
                        }
                        snprintf(sendBuff, sizeof(sendBuff), "%s\r\n", message);
                        write(connfd, sendBuff, strlen(sendBuff));
                }

		//Signal Actions
		if (sig_flag == 4)
		{
			put_log(log, "INFO - Shutting down HAwk...");
        		put_log(log, "INFO - Releasing Socket");
        		close(listenfd);
			//Freeing configuration dictionary
			iniparser_freedict(conf);
        		put_log(log, "INFO - Closing Log Files");
			fflush(log);
			fclose(log);
			close(connfd);
			break;
		}
		if (sig_flag == 6)
		{
			put_log(log, "INFO - Received HUP. Reloading...");
			fflush(log);
			fclose(log);
			close(connfd);
			log = open_logs();
			put_log(log, "INFO - Successfully reloaded logs");
			//free(conf);
			iniparser_freedict(conf);
			conf = load_conf();
			sig_flag = 0;	
		}
		close(connfd);
                sleep(1);
        }
	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: Justkog/Autobot
void __ISR(_EXTERNAL_1_VECTOR, IPL4SOFT) buttonHANDLER(void)
{
    put_log("kbunel\r\n");
    put_log("4567noobs\r\n");
    

    LATFbits.LATF1 = 1 ^ LATFbits.LATF1;
    IFS0bits.INT1IF = 0;
}
コード例 #4
0
ファイル: leds.c プロジェクト: marcaz/Fleet
__task void LED_TOGGLE (void) {
	//----------------------------------------------------------------
	uint8_t led_timer = 0;
   //----------------------------------------------------------------
	put_log("[LED]: LED Task Started...\r\n");
	//----------------------------------------------------------------
	for (;;) {
		//----------------------------------------------------------------
		os_dly_wait(20);
		//----------------------------------------------------------------
		led_timer++;
		//----------------------------------------------------------------
		if(led_timer==3 || led_timer==4){
			//----------------------------------------------------------------
			tmr1 = os_tmr_create (5, MAIN_LED_OFF_TMO);
			if (tmr1 != NULL) {
				GPIOD->BSRRL = GPIO_Pin_12;
			}
			//----------------------------------------------------------------
			if(led_timer==4){
				led_timer = 0;
			}
			//----------------------------------------------------------------
		}
		//----------------------------------------------------------------
	}
	//----------------------------------------------------------------
}
コード例 #5
0
ファイル: main.c プロジェクト: marcaz/Fleet
__task void Init_System(void){
	//----------------------------------------------------------------
	// Peripgherals INIT Section
	//----------------------------------------------------------------
	os_dly_wait(1);
	//----------------------------------------------------------------
	put_log("[MAIN]: Starting System PERIPHERALS Initialisation...\r\n");
	//----------------------------------------------------------------
	LED_Init();
	//----------------------------------------------------------------
	// System Tasks INIT Section
	//----------------------------------------------------------------
	put_log("[MAIN]: Starting System TASKS...\r\n");
	//----------------------------------------------------------------
	create_LED_Control_Task();
	create_Acc_Update_task();	
	//----------------------------------------------------------------
	put_log("[MAIN]: TASKS and PERIPHERALS Init Complete.\r\n");
	//----------------------------------------------------------------
	os_tsk_delete_self();
	//----------------------------------------------------------------
}
コード例 #6
0
bool ImagePyramidContent::readMetadata()
{
    try
    {
        TiffPyramidReader reader{getUri()};
        setDimensions(reader.getImageSize());
        _transparent = reader.hasAlphaChannel();
    }
    catch (const std::exception& e)
    {
        put_log(LOG_DEBUG, LOG_TIFF, e.what());
        return false;
    }
    return true;
}
コード例 #7
0
ファイル: probe.c プロジェクト: amithash/seeker-scheduler
/*******************************************************************************
 * inst_release_thread - probe for release_thread
 * @t - the task which is getting released (murder!)
 * @return - None
 * @Side Effect - If debug has started, then pid is logged.
 *
 * Logs the pids and command names of threads when they die
 *******************************************************************************/
void inst_release_thread(struct task_struct *t)
{
	struct log_block *p = NULL;
	if (TS_MEMBER(t, seeker_scheduled) != SEEKER_MAGIC_NUMBER)
		goto out;
	if (is_blacklist_task(t))
		goto out;
	p = get_log();
	if (p) {
		p->entry.type = LOG_PID;
		p->entry.u.tpid.pid = (u32) (t->pid);
		memcpy(&(p->entry.u.tpid.name[0]), t->comm, 16);
	}

	put_log(p);

	/* Make sure there is no pending work on this task */
	cancel_task_work(t);
out:
	jprobe_return();

}
コード例 #8
0
ファイル: hawk.c プロジェクト: dylanfmarquis/HAwk
int main(void)
{
        pid_t pid, sid;
        
        //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);       

	//Load Configuration File        
        dictionary *conf = load_conf();

        //Opening Log
	FILE *log = open_logs();

	//Query for UID/GID
	uid_t id = getid_byName(get_config(conf, "hawk:daemon_user"));

	//Set UID
	if (setuid(id) != 0)
	{
		put_log(log, "FATAL - Could not set UID for daemon");
		exit(1);
	}
	
        //Create a new SID for the child process 
        sid = setsid();
        if (sid < 0) {
                put_log(log, "FATAL - Session ID was not set properly");
                exit(EXIT_FAILURE);
        }

	//Write PID file
	if(strcmp(get_config(conf, "hawk:pid_path"),"") > 0)
	{
		FILE *pidfile;
		pidfile = fopen(get_config(conf, "hawk:pid_path"), "w");
		fprintf(pidfile, "%d", getpid());
		fflush(pidfile);
	}
        
	//Initialize Socket
	int listenfd = socket_init(conf);

        //Close out the standard file descriptors
        fflush(stdin);
	fflush(stdout);
	fflush(stderr);
        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);

	signal(SIGHUP, signal_handler);
	signal(SIGTERM, signal_handler);

        //Begin main routine
	put_log(log, "INFO - Starting HAwk...");
        main_construct(log, conf, listenfd);	
	return 0;
}