예제 #1
0
파일: main.c 프로젝트: MiZaRUs/SyMonTSTO
// Обработчики сигналов
static void sign_segv( int sig ) {
    fprintf( stderr,"\nSIGSEGV: Step(%s).\n", str_err );
    delete_ipc();
//    syslog( LOG_NOTICE, "SIGSEGV: Step(%s)", str_err);
//    closelog();
    exit( EXIT_FAILURE );
}// End _segv
예제 #2
0
파일: plug.c 프로젝트: easymc/easymc
int emc_close(int plug){
	int index = 0;
	void * msg = NULL;
	struct easymc_plug * pg = NULL;
	
	pg = (struct easymc_plug *)global_get_plug(plug);
	if(!pg){
		errno = ENOPLUG;
		return -1;
	}
	del_device_plug(pg->device, plug);
	for(index = 0; index < 0xFFFF; index ++){
		post_ringqueue(pg->mq);
	}
	if(pg->ipc_){
		delete_ipc(pg->ipc_);
	}
	if(pg->tcp_){
		delete_tcp(pg->tcp_);
	}
	while(1){
		if(pop_ringqueue_multiple(pg->mq, (void **)&msg) < 0){
			break;
		}else{
			emc_msg_free(msg);
		}
	}
	delete_ringqueue(pg->mq);
	free(pg);
	global_erase_plug(plug);
	return 0;
}
예제 #3
0
파일: main.c 프로젝트: MiZaRUs/SyMonTSTO
//  -------------------------------------------------------------------------
static void sign_exit( int sig ) {
    fprintf( stderr,"\nEXIT: Signal(%d).\n", sig );
    delete_transport();
    delete_ipc();
//    syslog( LOG_NOTICE, "EXIT: Signal(%d)", sig);
//    closelog();
    exit( EXIT_SUCCESS );
}// End _exit
예제 #4
0
파일: main.c 프로젝트: MiZaRUs/SyMonTSTO
int main( int argc, char *argv[] ) {
//    err = 1;
    str_err = "!!";
    time_wait = 2;
    max_point = 0;
    buf_len = 0;
    cur_device = 0;
//  --
    if( argc < 1 ) exit( 0 );// простотакчтобнекричал!
    char *d_name = ( strrchr( argv[0], '/' ) + 1 );
//    openlog(d_name,LOG_PID|LOG_CONS|LOG_NDELAY|LOG_NOWAIT,LOG_LOCAL0);
//  --
//printf( "Получаем конфигурацию сервера по имени: %s\n", d_name );
//  --
    if( !create_ipc( d_name )){
#ifdef DEBUG
printf( "Error: open_ipc(%s)\n", d_name );
#endif
//        syslog(LOG_LOCAL0|LOG_INFO, "Error: open_ipc(%s)", d_name);
        exit( 0 );
    }
//  ---------------

/* Инициализация основных объектов данными из конфиг-файла */
#include "0_inc_dev.h"
//    create_transport( "10.0.10.47", 4001, 500 )
// Устройства в цикле из БД:
//    dev[].x = x; err = 0;
//  ---------------
    int ij = 0;
    for(; ij < max_device; ij++ ){
#ifdef DEBUG
printf( "Device[%d] = %d, %d, %s, %d\n", ij, dev[ij].id, dev[ij].adr, dev[ij].name, dev[ij].reg );
#endif
        max_point += dev[ij].reg;
    }
#ifdef DEBUG
printf( "max_point = %d\n", max_point );
#endif
//  ---------------

/* Настройка системных сигналов */
    signal( SIGSEGV, sign_segv );	// !!!
    signal( SIGPIPE, SIG_IGN );
//  --
    signal( SIGINT, sign_exit );
    signal( SIGUSR1, sign_exit );
    signal( SIGQUIT, sign_exit );
    signal( SIGTERM, sign_exit );
//  ---------------

// Run
//    syslog(LOG_LOCAL0|LOG_INFO, "Run.");
    while( 1 ){
str_err = "start while";
        int i;
        char fifo_msg[MSGSIZE];
//  --
#ifdef MSG_JSON
        int i_msg = sprintf((char*)fifo_msg, "#%d={", max_point);
        for( i = 0; i < max_device; i++ ){
            if(refresh(&dev[i]) > 0 ){
                int j, k;
                for( j = 0; j < dev[i].reg; j++ ){
                    int id = dev[i].id * 1000 + j + 1;
                    int da = dev[i].get_data( j, buffer, buf_len );
                    k = sprintf((char*)fifo_msg + i_msg, "\"%d\":[\"%d\"],", id, da);
                    i_msg += k;
                }
            }// refresh
            usleep(50);
        }// for max_device
str_err = "write_ipc";
        sprintf(( char* )fifo_msg + i_msg -1, "}#%d\n", i_msg );
        if( write_ipc( fifo_msg, strlen( fifo_msg )) < 1) break;;
#else
        int i_msg = sprintf((char*)fifo_msg, "#%s:%d\n", d_name, max_point);
        for( i = 0; i < max_device; i++ ){
            if(refresh(&dev[i]) > 0 ){
                int j, k;
                for( j = 0; j < dev[i].reg; j++ ){
                    int id = dev[i].id * 1000 + j + 1;
                    int da = dev[i].get_data( j, buffer, buf_len );
                    k = sprintf((char*)fifo_msg + i_msg, "%d:%d\n", id, da);
                    i_msg += k;
                }
//                k = sprintf((char*)fifo_msg + i_msg, "\n");	// ???
//                i_msg += k;					// ???
            } else {//if refresh or dev[].err
                i_msg = sprintf((char*)fifo_msg, "#%s:%d\n", d_name, dev[i].err );
            }// end if( refresh )
            usleep(50);
        }// for max_device
//  --
str_err = "write_ipc";
        sprintf(( char* )fifo_msg + i_msg, "%d#\n", i_msg );
        if( write_ipc( fifo_msg, strlen( fifo_msg )) < 1) break;;
#endif
//  --
//fprintf( stderr, "*" );
        sleep(time_wait);
    }// while
//  -------------------------------------------------------------------------
    fprintf( stderr,"\nBREAK: Error(%s).\n", str_err );
    delete_transport();
    delete_ipc();
//    syslog( LOG_NOTICE, "BREAK: Error(%s)", str_err);
//    closelog();
    exit( EXIT_FAILURE );
}// End main ----------------------------------------------------------------