예제 #1
0
파일: wmr_updexec.c 프로젝트: koljanos/wmr
void upd_scan_dir(WEATHER * weather, char * udir, int syslogEn, int debugEn)
{
    DIR *dp;
    char tmp_string[2048];
    struct dirent *fp;

    //pthread_mutex_lock(&job_mutex);
    dp = opendir(udir);

    if (dp != NULL)
    {
        while ( (fp = readdir(dp)) != NULL )
        {
            // if(fp->d_type == 4)
            // {

            if (( fnmatch( "*.sh", fp->d_name, 0) ) == 0)
            {
                if( debugEn > 2 )
                {
                    sprintf (tmp_string, WMR_UPDEXEC_C_TXT_1, fp->d_name, fp->d_type, fp->d_reclen);
                    syslog_msg (syslogEn, tmp_string);
                }

                sprintf (tmp_string,"%s/%s", udir,fp->d_name);

                if(system (tmp_string) != 0)
                {
                    if( debugEn > 0 )
                    {
                        sprintf (tmp_string, WMR_UPDEXEC_C_TXT_2, fp->d_name);
                        syslog_msg (syslogEn, tmp_string);
                    }
                } else {

                    if( debugEn > 2 )
                    {
                        sprintf (tmp_string, WMR_UPDEXEC_C_TXT_3, udir, fp->d_name, fp->d_type);
                        syslog_msg (syslogEn, tmp_string);
                    }
                }

            }
            //}
        }

        closedir(dp);
    } else {

        if( debugEn > 0 )
        {
            sprintf (tmp_string, WMR_UPDEXEC_C_TXT_4, udir);
            syslog_msg (syslogEn, tmp_string);
        }
    }

    //pthread_mutex_unlock(&job_mutex);
//  end
}
예제 #2
0
static void doKlogd (void)
{
	int priority = LOG_INFO;
	char log_buffer[4096];
	int i, n, lastc;
	char *start;

	/* Set up sig handlers */
	signal(SIGINT, klogd_signal);
	signal(SIGKILL, klogd_signal);
	signal(SIGTERM, klogd_signal);
	signal(SIGHUP, SIG_IGN);

	/* "Open the log. Currently a NOP." */
	klogctl(1, NULL, 0);

	syslog_msg(LOG_DAEMON, 0, "klogd started: " BB_BANNER);

	while (1) {
		/* Use kernel syscalls */
		memset(log_buffer, '\0', sizeof(log_buffer));
		n = klogctl(2, log_buffer, sizeof(log_buffer));
		if (n < 0) {
			char message[80];

			if (errno == EINTR)
				continue;
			snprintf(message, 79, "klogd: Error return from sys_sycall: %d - %s.\n", 
												errno, strerror(errno));
			syslog_msg(LOG_DAEMON, LOG_SYSLOG | LOG_ERR, message);
			exit(1);
		}

		/* klogctl buffer parsing modelled after code in dmesg.c */
		start=&log_buffer[0];
		lastc='\0';
		for (i=0; i<n; i++) {
			if (lastc == '\0' && log_buffer[i] == '<') {
				priority = 0;
				i++;
				while (isdigit(log_buffer[i])) {
					priority = priority*10+(log_buffer[i]-'0');
					i++;
				}
				if (log_buffer[i] == '>') i++;
				start = &log_buffer[i];
			}
			if (log_buffer[i] == '\n') {
				log_buffer[i] = '\0';  /* zero terminate this message */
				syslog_msg(LOG_DAEMON, LOG_KERN | priority, start);
				start = &log_buffer[i+1];
				priority = LOG_INFO;
			}
			lastc = log_buffer[i];
		}
	}
}
예제 #3
0
static void klogd_signal(int sig)
{
	klogctl(7, NULL, 0);
	klogctl(0, 0, 0);
	//logMessage(0, "Kernel log daemon exiting.");
	syslog_msg(LOG_SYSLOG, LOG_NOTICE, "Kernel log daemon exiting.");
	exit(TRUE);
}
예제 #4
0
파일: wmr_sql.c 프로젝트: allexpert/wmr
int wmr_sqldb_init(sqlite3 **db, char * db_name, int syslogEn, int debugEn)
{

    if( sqlite3_open( db_name, *&db) )
    {
	if( debugEn > 0 )
	{
	    sprintf (err_string, WMR_SQL_C_TXT_3, sqlite3_errmsg(*db));
	    syslog_msg (syslogEn, err_string);
	    return WMR_EXIT_NORMAL;
	}
    }
	if( debugEn > 1 )
	{
    	    sprintf (err_string, WMR_SQL_C_TXT_4, db_name);
	    syslog_msg (syslogEn, err_string);
	}

return WMR_EXIT_SUCCESS;
}
예제 #5
0
파일: wmr_sql.c 프로젝트: allexpert/wmr
void wmr_sqldb_log(sqlite3 **db, char * curtime, char *msgs, int tbln, int syslogEn, int debugEn )
{
    char msg[200];

    sprintf ( msg, WMR_TMPL_SQL_INSERT, TABLES[tbln], curtime, msgs );

    if( debugEn > 2 )
    {
	sprintf (err_string, "SQL[%s]:%s\n", curtime, msg);
	syslog_msg (syslogEn, err_string);
    }

    if ( sqlite3_exec(*db, msg, 0, 0, 0) != SQLITE_OK )
    {
	if( debugEn > 0 )
	{
	    sprintf (err_string, WMR_SQL_C_TXT_2, sqlite3_errmsg(*db));
	    syslog_msg (syslogEn, err_string);
	}
    }
}
예제 #6
0
파일: wmr_sql.c 프로젝트: allexpert/wmr
void wmr_sqldb_create(sqlite3 **db, int tbln, int syslogEn, int debugEn)
{

    if ( sqlite3_exec(*db, WMR_SQL_CREATE[tbln], 0,0,0) != SQLITE_OK )
    {
	if( debugEn > 0 )
	{
	    sprintf (err_string, WMR_SQL_C_TXT_1, TABLES[tbln], sqlite3_errmsg(*db));
	    syslog_msg (syslogEn, err_string);
	}
    }
}
예제 #7
0
파일: wmr_updexec.c 프로젝트: koljanos/wmr
int upd_exec_handle ( key_t shmID, char * udir, char * lock_file, int syslogEn, int debugEn )
{
    int pid;
    WEATHER *weather = NULL;
    char tmp_string[4096];

    /*
        if (weather == NULL)
        {
    	if( debugEn > 0 )
    	{
        	    syslog_msg (syslogEn,WMR_UPDEXEC_C_TXT_10);
    	}

        exit(WMR_EXIT_FAILURE);
        }
    */

// signal(SIGINT,  __cleanup);
// signal(SIGTERM, __cleanup);

    pid = fork();

    if (pid == 0)
    {

        //pthread_mutex_lock(&job_mutex);
        weather = weather_new( 1, shmID, "", debugEn );

        if( debugEn > 1 )
        {
            sprintf (tmp_string, WMR_UPDEXEC_C_TXT_7, pid, getpid(), weather->run.UPD[0], weather->run.updTime);
            syslog_msg (syslogEn, tmp_string);
        }

        UPDrun = weather->run.UPD[0];

        while( UPDrun )
        {
            //sleep( weather->run.updTime );
            sleep( 60 );

            printf("\n\n--- UPDrun %d %d ---\n\n", UPDrun, weather->run.UPD[0] );
            if( UPDpid == 0 ) {
                break;
            }

            if( debugEn > 2 )
            {
                sprintf (tmp_string, WMR_TMPL_UPD_EXEC_DEBUG, \
                         weather->run.shmid, \
                         "MAIN UPD:", \
                         weather->temp[0].humidity, \
                         weather->temp[0].temp, \
                         weather->temp[0].dewpoint, \
                         weather->temp[0].smiley, \
                         weather->temp[0].trendTxt, \
                         weather->temp[0].smileyTxt, \
                         weather->temp[1].humidity, \
                         weather->temp[1].temp, \
                         weather->temp[1].dewpoint, \
                         weather->temp[1].smiley, \
                         weather->temp[1].trendTxt, \
                         weather->temp[1].smileyTxt, \
                         weather->water[0].temp, \
                         weather->uv.uvindex, \
                         weather->pressure.pressure, \
                         weather->pressure.forecast, \
                         weather->rain.rate, \
                         weather->rain.hour, \
                         weather->rain.day, \
                         weather->rain.total, \
                         weather->wind.wind_dir, \
                         weather->wind.low_speed, \
                         weather->wind.high_speed, \
                         weather->wind.wind_speed, \
                         weather->wind.avg_speed, \
                         weather->wind.wind_chill \
                        );

                syslog_msg (syslogEn, WMR_UPDEXEC_C_TXT_11);
                syslog_msg (syslogEn, tmp_string);
                syslog_msg (syslogEn, "\n");
            }

            UPDrun = weather->run.UPD[0];
        }

        if( debugEn > 1 )
        {
            sprintf (tmp_string, WMR_UPDEXEC_C_TXT_8, pid, getpid(), getppid(), weather->run.UPD[0] );
            syslog_msg (syslogEn, tmp_string);
        }

        //weather->run.UPD[0] = 0;
        //weather_close( weather, shmID, weather->run.MAINpid, 1, syslogEn, debugEn );
        //pthread_mutex_unlock(&job_mutex);

        //exit (WMR_EXIT_SUCCESS);
        return (WMR_EXIT_SUCCESS);

    } else if (pid > 0) {

        weather->run.UPDpid = pid;
        UPDpid = pid;

        if( debugEn > 1 )
        {
            sprintf (tmp_string, WMR_UPDEXEC_C_TXT_9, pid, getpid(), getppid(), weather->run.UPD[0] );
            syslog_msg (syslogEn, tmp_string);
        }

        //pthread_mutex_unlock(&job_mutex);
        //exit (WMR_EXIT_NORMAL);
        return (WMR_EXIT_NORMAL);

    } else {

        if( debugEn > 0 )
        {
            syslog_msg (syslogEn,WMR_UPDEXEC_C_TXT_12);
        }

        //weather->run.UPD[0] = 0;
        //weather_close( weather, shmID, weather->run.MAINpid, 1, syslogEn, debugEn );
    }


    return (WMR_EXIT_FAILURE);
}