Esempio n. 1
0
File: s_zlog.c Progetto: iskey/zlog
int s_zlog_init(const char *conf)
{
	int rc;

	rc = zlog_init(conf);
	if (rc) {
		printf("BNC_LOG: init config failed!\n");
		printf("BNC_LOG: Now init to default!\n");

		rc= zlog_init(NULL);
		if(rc){
			printf("BNC_LOG: init to default faild!\n");
			return -1;
		}
	}

	zc = zlog_get_category("bnc_cat");
	if (!zc) {
		printf("BNC_LOG: get cat fail\n");
		printf("BNC_LOG: bnc_log system will not work!");
		zlog_fini();
		return -2;
	};
	
	return 0;
}
Esempio n. 2
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_by_roy.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category(MY_CATEGORY);
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_info(zc, "hello, zlog");
	sleep(1);
	zlog_info(zc, "hello, zlog2");
	sleep(2);
	zlog_info(zc, "hello, zlog3");
	zlog_info(zc, "hello, zlog4");

	zlog_fini();
	
	return 0;
}
Esempio n. 3
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_level.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_trace(zc, "hello, zlog - trace");
	zlog_debug(zc, "hello, zlog - debug");
	zlog_info(zc, "hello, zlog - info");

	zlog_fini();
	
	return 0;
}
Esempio n. 4
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_syslog.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_info(zc, "hello, zlog -- info");
	zlog_error(zc, "hello, zlog -- error");

	zlog_fini();
	
	return 0;
}
Esempio n. 5
0
int zlog_test()
{
	int rc;
	zlog_category_t *c;

	rc = zlog_init("d:\\tmp\\zlog.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	c = zlog_get_category("my_cat");
	if (!c) {
		printf("get cat fail\n");
		zlog_fini();

		return -2;
	}


	zlog_info(c, "hello, zlog");
	zlog_debug(c, "hello, zlog");
	zlog_error(c, "hello, zlog");

	zlog_fini();
	printf("exit.\n");

	return 0;
} 
Esempio n. 6
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;
	

	rc = zlog_init("test_conf.conf");
	if (rc) {
		printf("init failed, try zlog-chk-conf test_conf.conf for more detail\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_info(zc, "hello, zlog");

	zlog_fini();
	printf("log end\n");
	
	return 0;
}
Esempio n. 7
0
int main(int argc, char** argv)
{
	int rc; 
	zlog_category_t *zc;
	rc = zlog_init("test_tmp.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_debug(zc, "%s%d");
	zlog_info(zc, "hello, zlog 2");

	sleep(1);

	zlog_info(zc, "hello, zlog 3");
	zlog_debug(zc, "hello, zlog 4");

//	zlog_profile();

	zlog_fini();
	
	return 0;
}
Esempio n. 8
0
int main(int argc, char** argv)
{
	int rc = 0;
	int j = 100;

    	rc = zlog_init("change_rule.conf");
    	if (rc){
    		printf("init failed\n");
        	return 2;
    	}

	zlog_category_t *zc;
	zc = zlog_get_category("yang");

	pthread_t  tid;
	pthread_create(&tid, NULL, work, (void*)("yang"));
	
	while(j-- > 0) {
		zlog_debug(zc, "debuglog");
		zlog_info(zc, "infolog");
		zlog_error(zc, "errorlog");
		sleep(1);
	}

	pthread_join(tid, NULL);
	zlog_fini();
	
	return 0;
}
Esempio n. 9
0
int main(int argc, char** argv)
{
	int rc = 0;
	zlog_category_t *zc = NULL;

	// 初始化库, 给出配置文件路径
	rc = zlog_init("test_hello.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	// 获取分类名, 表示要打印哪些日志
	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_info(zc, "hello, zlog");

	zlog_fini();
	
	return 0;
}
Esempio n. 10
0
File: test_mdc.c Progetto: 3van/zlog
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_mdc.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}


	zlog_info(zc, "1.hello, zlog");

	zlog_put_mdc("myname", "Zhang");

	zlog_info(zc, "2.hello, zlog");

	zlog_put_mdc("myname", "Li");

	zlog_info(zc, "3.hello, zlog");

	zlog_fini();
	
	return 0;
}
Esempio n. 11
0
int main(int argc, char** argv)
{
	unsigned char aa[32];
	int i, j;

	i = 1;
	j = 2;
	zlog_init("AA");


// 	i = atoi(argv[1]);
// 	j = atoi(argv[2]);
	printf("Hello.\n");
	zlog_test();
// 
// 	memset(aa, 0x00, sizeof(aa));
// 
// 	aa[i/8] |=  ~(0xFF << (8 - i % 8));
// 	memset(aa + i/8 + 1, 0xFF, sizeof(aa) - i/8 - 1);

// 	hdzlog_info(aa, sizeof(aa));
// 
// 	dzlog_info("%0x", aa[j/8]);
// 	dzlog_info("%0x", aa[j/8] >> 6);
// 
// 	dzlog_info("%0x", ~((aa[j/8] >> (7 - j % 8)) & 0x01) );
// 
// 	zlog_fini();
	
	return 0;
}
Esempio n. 12
0
int main(int argc, char** argv)
{
	int rc;

	if (argc != 4) {
		fprintf(stderr, "test nprocess nthreads nloop\n");
		exit(1);
	}

	rc = zlog_init("test_press_zlog.conf");
	if (rc) {
		printf("init failed\n");
		return 2;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat failed\n");
		zlog_fini();
		return 3;
	}

	loop_count = atol(argv[3]);
	test(atol(argv[1]), atol(argv[2]));

	zlog_fini();
	
	return 0;
}
Esempio n. 13
0
int main(int argc, char **argv)
{
  struct net_handle* file_ctx = NULL;
  struct timeval start,end;

  char rcv_buf[MAX_BUFSIZE];
  if (argc < 3) {
    printf("usage:need argument ip_address port_num\n");
    exit(-1);
  }
  int rvl=0; 
  int port_num= strtoul(argv[2],NULL,0);
  zlog_init("./zlog.conf");
  rvl = net_module_init(NULL);
  assert(!rvl);

  file_ctx = net_open(argv[1],port_num,4,16,SPK_DIR_WRITE,net_intf_tcp);
  if (!file_ctx) {
    printf("failed to open net\n");
    rvl = SPKERR_BADRES;
    goto out;
  }
  rvl= net_intf_is_connected(file_ctx);
  if(!rvl) {
    printf("net is not connected!\n");
	goto out;
  }
  
  uint64_t xfer=0;
  gettimeofday(&start, NULL);
  uint64_t total_count=0;
  while (1) {

    xfer = net_write(file_ctx, rcv_buf, MAX_BUFSIZE);
    if(xfer != MAX_BUFSIZE) {
	    printf("send data error=>xfer:%ld\n",xfer);
	} else {
//	    printf("write OK!\n");
	}

	total_count++;
    gettimeofday(&end, NULL);
    float diff=(end.tv_sec-start.tv_sec)+(end.tv_usec - start.tv_usec)/1000000.0;
	if(diff > 5) {
    	float speed=(total_count*MAX_BUFSIZE)/1024/diff;
		printf("time:%-15f s speed:%-15f KB/s\n",diff,speed);
        gettimeofday(&start, NULL);
		total_count=0;
	}
  }

out:
    if (file_ctx) {
        net_close(file_ctx);
        file_ctx = NULL;
    }
  return rvl;
}
Esempio n. 14
0
int main(int argc, char *argv[])
{
	int rc = 0;
	int op;
	int quiet = 0;
	static const char *help = 
		"useage: zlog-chk-conf [conf files]...\n"
		"\t-q,\tsuppress non-error message\n"
		"\t-h,\tshow help message\n"
		"zlog version: " ZLOG_VERSION "\n";

#ifndef _MSC_VER
	while((op = getopt(argc, argv, "qhv")) > 0) {
		if (op == 'h') {
			fputs(help, stdout);
			return 0;
		} else if (op == 'q') {
			quiet = 1;
		}
	}

	argc -= optind;
	argv += optind;
#endif

	if (argc == 0) {
		fputs(help, stdout);
		return -1;
	}

#ifdef _MSC_VER
#define setenv(a,b,c) _putenv_s(a,b)
#endif
	setenv("ZLOG_PROFILE_ERROR", "/dev/stderr", 1);
	setenv("ZLOG_CHECK_FORMAT_RULE", "1", 1);

	while (argc > 0) {
		rc = zlog_init(*argv);
		if (rc) {
			printf("\n---[%s] syntax error, see error message above\n",
				*argv);
			exit(2);
		} else {
			zlog_fini();
			if (!quiet) {
				printf("--[%s] syntax right\n", *argv);
			}
		}
		argc--;
		argv++;
	}

	exit(0);
}
Esempio n. 15
0
void zlogInit(std::string path)
{
    rc =zlog_init(path.c_str());
    if (rc)
    {
        printf("init failed\n");
        zlog_fini();
        return;
    }

    zc = zlog_get_category("my_cat");
}
Esempio n. 16
0
int log_init()
{
	if(log)
		return 0;
	int flag=zlog_init("/data/zlog.conf");
	if(flag!=0)
		return -1;
	log= zlog_get_category("my_cat");
	if(!log)
	{
		zlog_fini();
		return -2;
	}
}
Esempio n. 17
0
int logger_init(Logger *logger, 
                 int mode, 
                 const char *log_conf_path, 
                 const char *log_file_dir)
{
    int rc;
    zlog_category_t *zc;

    logger->log_i = my_zlog_info;
    logger->log_d = my_zlog_debug;
    logger->log_e = my_zlog_error;

    int ret = make_config(log_conf_path, log_file_dir);
    if (ret < 0) {
        goto ERROR;
    }

    rc = zlog_init(log_conf_path);
	if (rc) {
        fprintf(stderr, "logger_init: zlog_init error\n");
        goto ERROR;
	}

    if (mode == LOG_STDOUT) {
        zc = zlog_get_category("stdout");
    } else if (mode == LOG_FILE) {
        zc = zlog_get_category("file");
    }

    if (!zc) {
        fprintf(stderr, "logger_init: zlog_get_category error\n");
        goto ERROR;
    }

    logger->zc = zc;
    logger->log_mode = mode;
    logger->log_on = 1;

    s_init_zlog_success = 1;

    return 0;

ERROR:
    logger_destroy(logger);

    return -1;
}
Esempio n. 18
0
int main () {
	int state = zlog_init("../zlog.conf");
    category = zlog_get_category("default");
    zlog_info (category, "Server starts!");

    init_server (&server);
    server.run (&server);

    while (1) {
        char c = getchar ();
        if (c == 'q')
            break;
    }

    destroy_server (&server);

    zlog_fini ();
}
Esempio n. 19
0
int main(int argc, char** argv)
{
	int rc;
	int k;
	int i;

	if (argc != 2) {
		printf("test_leak ntime\n");
		return -1;
	}

	rc = zlog_init("test_leak.conf");

	k = atoi(argv[1]);
	while (k-- > 0) {
		i = rand();
		switch (i % 4) {
		case 0:
			rc = dzlog_init("test_leak.conf", "xxx");
			dzlog_info("init");
			break;
		case 1:
			rc = zlog_reload(NULL);
			dzlog_info("reload null");
			break;
		case 2:
			rc = zlog_reload("test_leak.2.conf");
			dzlog_info("reload 2");
			break;
		case 3:
			zlog_fini();
			printf("fini\n");
	//		printf("zlog_finish\tj=[%d], rc=[%d]\n", j, rc);
			break;
		}
	}

	zlog_fini();
	return 0;
}
Esempio n. 20
0
/* Architecture note: For the time being (as of early 2014, at least),
 * we're using libuv to handle asynchronous I/O stuff.  It would be
 * lovely if we could "embed" libuv's event loop in the yield logic.
 * Unfortunately, libuv embedding is not totally solidified yet.  So
 * we're going to have a separate thread for running the I/O event
 * loop.  Eventually we should be able to get rid of that.
 *
 * ... On the other hand, having a separate thread for the event loop
 * means that we can do the heartbeat timer there and not have to worry
 * about signal handling junk.  Seems like that might be a nicer way to
 * go for many systems.  In the long term, probably should support
 * both. */
int main( int argc, char **argv, char **env )
{
    /* Okay to stack-allocate these here because the I/O thread should
     * always be the last thing running in a Charcoal process.
     * TODO: Document why we need these for the I/O thread */
    int rc;
    if( ( rc = zlog_init( zlog_config_full_filename ) ) )
    {
        return -1;
    }

    if( !( crcl(c) = zlog_get_category( "main_cat" ) ) )
    {
        zlog_error( crcl(c), "Failure: Missing logging category\n" );
        zlog_fini();
        return -2;
    }

    __argc = argc;
    __argv = argv;
    __env  = env;
    if( ( rc = crcl(init_io_loop)( start_application_main ) ) )
    {
        zlog_error( crcl(c), "Failure: Initialization of the I/O loop: %d\n", rc );
        return rc;
    }

    if( ( rc = uv_run( crcl(evt_loop), UV_RUN_DEFAULT ) ) )
    {
        zlog_error( crcl(c), "Failure: Running the I/O loop: %d", rc );
        return rc;
    }

    zlog_info( crcl(c), "switch cnt: %ld", crcl(switch_cnt) );
    zlog_info( crcl(c), "Charcoal application finished.  Exit code: %d",
               crcl(process_exit_code) );
    zlog_fini();
    return crcl(process_exit_code);
}
Esempio n. 21
0
int main(int argc, char** argv)
{
	int rc;
	
	zlog_category_t *zc;

	rc = zlog_init("test_init.conf");
	if (rc) {
		printf("init fail");
		return -2;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("zlog_get_category fail\n");
		zlog_fini();
		return -1;
	}

	ZLOG_INFO(zc, "before update");

	sleep(3);

	rc = zlog_reload("test_init.2.conf");
	if (rc) {
		printf("update fail\n");
	}

	ZLOG_INFO(zc, "after update");

	zlog_profile();

	zlog_fini();

	
	return 0;
}
Esempio n. 22
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_hello.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	ZLOG_INFO(zc, "hello, zlog");

	zlog_fini();
	
	return 0;
}
Esempio n. 23
0
int log_init(const char * conf_path)
{
    int rc;

    if (!conf_path) {
        printf("conf_path is null\n");
        return -1;
    }

    rc = zlog_init(conf_path);
    if (rc) {
        printf("init failed[%s]\n", conf_path);
        return -1;
    }

    g_logger = zlog_get_category("my_cat");
    if (!g_logger) {
        printf("get cat fail\n");
        zlog_fini();
        return -2;
    }

    return 0;
} 
Esempio n. 24
0
File: p.c Progetto: Cai900205/test
int main(int argc, char **argv)
{
    int rvl = 0;
    int i;

    zlog_init("./zlog.conf");
    rvl = ips_module_init(NULL);
    assert(!rvl);
    rvl = idt_module_init(NULL);
    assert(!rvl);
    
    // channel 0
    link_desc_tbl[0].mst_id = IPS_MAKE_EPID(IPS_EPMODE_MASTER, 0, 0x0);
    link_desc_tbl[0].slv_id = IPS_MAKE_EPID(IPS_EPMODE_SLAVE, 0, 0x0);
    link_desc_tbl[0].mst_port = 6;
    link_desc_tbl[0].slv_port = 1;
    link_desc_tbl[0].is_master = 0;
    if (PIPE_NUM == 2) {
        link_desc_tbl[1].mst_id = IPS_MAKE_EPID(IPS_EPMODE_MASTER, 0, 0x1);
        link_desc_tbl[1].slv_id = IPS_MAKE_EPID(IPS_EPMODE_SLAVE, 0, 0x1);
        link_desc_tbl[1].mst_port = 3;
        link_desc_tbl[1].slv_port = 4;
        link_desc_tbl[0].is_master = 0;
    }
    pthread_barrier_init(&barrier, NULL, PIPE_NUM);
    sync_cnt = 0;
    pthread_mutex_init(&sync_cnt_lock, NULL);

    int idt_fd = idt_dev_open(2, 0x67);
    assert(idt_fd > 0);    
    for(i=0; i<PIPE_NUM; i++){
        ips_linkdesc_t* desc = &link_desc_tbl[i];
        
        if (desc->is_master) {
            assert(0);
        } else {
            // reset link partner
            idt_port_recovery(idt_fd, desc->mst_port);
            // set routetbl entries
            idt_routetbl_set(idt_fd, desc->mst_port,
                                     desc->slv_id,
                                     desc->slv_port);
            idt_routetbl_set(idt_fd, desc->slv_port,
                                     desc->mst_id,
                                     desc->mst_port);
        }
    }
    idt_dev_close(idt_fd);
    //init ips mode
    parse_ips_mode_ini();
    ips_init_mode(test_ips_mode);
    for(int pipe=0; pipe<PIPE_NUM; pipe++) {
        ips_epdesc_t   epdesc;
        memset(&epdesc, 0, sizeof(ips_epdesc_t));
        epdesc.capacity = 0;
        epdesc.pc_num = 1;
        for (i = 0; i < epdesc.pc_num; i++) {
            ips_pcdesc_t* pcdesc = &epdesc.pcdesc_tbl[i];
            pcdesc->dest_id = link_desc_tbl[pipe].mst_id;
            pcdesc->capacity = epdesc.capacity;
        }
        rvl = ips_ep_init(link_desc_tbl[pipe].slv_id, &epdesc);
        assert(rvl == 0);
        for (i = 0; i < epdesc.pc_num; i++) {
            thread_args_t* args = malloc(sizeof(thread_args_t));
            args->epid = link_desc_tbl[pipe].slv_id;
            args->pc_id = i;
            args->wkr_id = pipe;
            rvl = pthread_create(&wkr[pipe], NULL, __worker_slave, args);
            assert(!rvl);
        }
    }

    while(1) {
        for(int pipe=0; pipe<PIPE_NUM; pipe++) {
            pthread_join(wkr[pipe], NULL);
        }
    };


    return 0;
}
Esempio n. 25
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;
	int i = 0;
	struct stat stat_0, stat_1;

	/* Create the logging directory if not yet ceated */
	mkdir("./test_multithread-logs", 0777);

	if (stat(CONFIG, &stat_0))
	{
		printf("Configuration file not found\n");
		return -1;
	}

	rc = zlog_init(CONFIG);
	if (rc) {
		printf("main init failed\n");
		return -2;
	}

	zc = zlog_get_category("main");
	if (!zc) {
		printf("main get cat fail\n");
		zlog_fini();
		return -3;
	}

	/* Interrupt (ANSI).		<Ctrl-C> */
	if (signal(SIGINT, intercept) == SIG_IGN )
	{
		zlog_fatal(zc, "Can't caught the signal SIGINT, Interrupt (ANSI)");
		signal(SIGINT, SIG_IGN );
		return -4;
	}

	// start threads
    tinfo = calloc(NB_THREADS, sizeof(struct thread_info));
	for (i=0; i<NB_THREADS; i++)
	{
        tinfo[i].thread_num = i + 1;
        tinfo[i].loop = 0;
		if(pthread_create(&tinfo[i].thread_id, NULL, myThread, &tinfo[i]) != 0)
		{
			zlog_fatal(zc, "Unable to start thread %d", i);
			zlog_fini();
			return(-5);
		}
    }

	/* Wait and log thread informations */
	sleep(1);
	for (i=0; i<NB_THREADS; i++)
	{
		zlog_info(zc, "Thread [%d], zlog_category:@%p", tinfo[i].thread_num, tinfo[i].zc);
    }

	/* Log main loop status */
	i=0;
	while(1)
	{
		int reload;

		sleep(1);
		i++;
		zlog_info(zc, "Running time: %02d:%02d:%02d", i/3600, (i/60)%60, i%60);

		/* Check configuration file update */
		stat(CONFIG, &stat_1);

		/* Is configuration file modified */
		reload = (stat_0.st_mtime != stat_1.st_mtime);

		/* Or do we want to reload periodicaly the configuration file */
		if ( ! reload)
			if ( RELOAD_DELAY > 0)
				reload = (i % RELOAD_DELAY == 0);

		if (reload)
		{
			zlog_info(zc, "Will reload configuration...");
			rc = zlog_reload(CONFIG);
			if (rc) {
				printf("main init failed\n");
				return -6;
			}
			zlog_info(zc, "Configuration reloaded :)");
			stat(CONFIG, &stat_0);
		}
	}
	
    exit(EXIT_SUCCESS);
}
Esempio n. 26
0
int main(int argc, char** argv)
{
	int rc;
	pid_t pid;
	
	//注册信号
	(void)signal(TFTP_SIGNAL, Tftp_Sig);
	
	//初始化缓存队列
	queue_init(&coapMsgQ, free);
	
	//初始化信号量,初始值为0
	rc = sem_init(&msgQSem, 0, 0);
	if(rc == -1)
	{
		printf("init msgQSem error!\r\n");
		exit(-1);
	}
	
	//初始化互斥量
	rc = pthread_mutex_init(&msgQ_mutex, NULL);
	if(rc != 0)
	{
		printf("msgQ_mutex init error!\r\n");
		exit(-1);
	}
	
	
	//打开数据库
	Open_db("CoapMsg.db", &db);
	
	rc = zlog_init("log.conf");
	if (rc) 
	{
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) 
	{
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}
	
	zlog_info(zc, "Start!");

	zlog_info(zc, "Uart_Init!");
	//初始化串口
	Uart_Init(115200);

	//创建串口读取数据线程
	rc = pthread_create(&uartRd_Thread, NULL, Uart_ReadThread, NULL);
	if(0!=rc)
	{
		zlog_error(zc, "uartRd_Thread create error!");
		exit(-1);
	}
	else
	{
		zlog_debug(zc, "uartRd_Thread create success!");
	}
	
	//创建分发数据线程
	rc = pthread_create(&transMsg_Thread, NULL, TransMsgThread, NULL);
	if(0!=rc)
	{
		zlog_error(zc, "TransMsgThread create error!");
		exit(-1);
	}
	else
	{
		zlog_debug(zc, "TransMsgThread create success!");
	}
	
	//初始化链表
	list_init( &iplist, free);
	zlog_debug(zc, "list_init success!");
	
	//创建tftp Server进程
	pid = fork();
	if(pid == 0)
	{
		printf("enter tftp server,pid = %d\r\n", getpid());
		zlog_debug(zc, "enter tftp server,pid = %d", getpid());
		tftpd_init(NULL);
	}
	else if(pid<0)
	{
		printf("create tftp server process error!\r\n");
		zlog_error(zc, "create tftp server process error!");
	}
	else if(pid > 0)
	{
		//记录tftp子进程的pid
		tftp_pid = pid;
	}
	
	//创建coapclient任务
	CreatCoapclient(&iplist);
	
	//创建coap Server进程
	pid = fork();
	if(pid == 0)
	{
		printf("enter coap server,pid = %d\r\n", getpid());
		zlog_debug(zc, "enter coap server,pid = %d", getpid());
		CoapServ(NULL);
	}
	else if(pid<0)
	{
		printf("create coap server process error!\r\n");
		zlog_error(zc, "create coap server process error!");
	}
	else if(pid > 0)
	{
		//记录coap server子进程的pid
		coap_serv_pid = pid;
	}
	
	while(1)
	{
		sleep(1);
	}

	return 0;
}
Esempio n. 27
0
int main(int argc, char **argv)
{
    int ret;
    int i;
    char msg_ibuf[CMI_MAX_MSGSIZE];

    umask(022);

    // build assert
    assert(DFV_MAX_SLOTS == CMI_MAX_SLOTS);
    assert(IPS_MAX_FCNUM == CMI_MAX_FCNUM);
    assert(!(SYS_CACHE_SIZE % CMI_MAX_FRAGSIZE));

    printf("\n");
    printf("SSSSSSSSSS\n");
    printf("SSSSSSSSSS\n");
    printf("SSS    SSS  PPPPP      AA     RRRRR    KK  KK\n");
    printf("SS  SS  SS  PP  PP    AAAA    RR  RR   KK  KK\n");
    printf("SS  SSSSSS  PP  PP   AA  AA   RR  RR   KK KK\n");
    printf("SSS  SSSSS  PP  PP   AA  AA   RR  RR   KK KK\n");
    printf("SSSS  SSSS  PPPPP    AA  AA   RRRRR    KKKK\n");
    printf("SSSSS  SSS  PP       AAAAAA   RR RR    KK KK\n");
    printf("SSSSSS  SS  PP       AA  AA   RR  RR   KK KK\n");
    printf("SS  SS  SS  PP       AA  AA   RR  RR   KK  KK\n");
    printf("SSS    SSS  PP       AA  AA   RR  RR   KK  KK\n");
    printf("SSSSSSSSSS  \n");
    printf("SSSSSSSSSS  ==SYS: LK  ==VER: %s\n", SYS_VERSION);
    printf("\n");

    // initialize log system
    zlog_init("./zlog.conf");
    sys_zc = zlog_get_category("SYS");
    assert(sys_zc);

    zlog_notice(sys_zc, "------------------------------------------");
    zlog_notice(sys_zc, "==> system starting ...");
    zlog_notice(sys_zc, "==> dump system versions ...");
    zlog_notice(sys_zc, "  SYS: %s", SYS_VERSION);
    zlog_notice(sys_zc, "  IPS: %s", IPS_MOD_VER);
    zlog_notice(sys_zc, "  DFV: %s", DFV_MOD_VER);
    zlog_notice(sys_zc, "  IDT: %s", IDT_MOD_VER);
    zlog_notice(sys_zc, "  CMI: %s", CMI_MOD_VER);

    // initialize env
    // TBD: should be read from .conf
    zlog_notice(sys_zc, "> loading conf ...");
    memset(&sys_env, 0, sizeof(sys_env));
    
    sys_env.features = SYSFEA_USE_LOCALSTATS;

    sys_env.intf_type = cmi_intf_tcp;
    sys_env.endian = cmi_endian_auto;
    sys_env.ipaddr = NULL;
    sys_env.port = 1235;

    sys_env.dfv_desc_tbl[0].mnt_path = "sdb";
    sys_env.dfv_desc_tbl[0].dev_path = "sdb";
    sys_env.dfv_desc_tbl[0].flag = 0;
    sys_env.dfv_desc_tbl[1].mnt_path = "sdf";
    sys_env.dfv_desc_tbl[1].dev_path = "sdf";
    sys_env.dfv_desc_tbl[1].flag = 0;

    sys_env.ips_linkdesc_tbl[0].mst_id = IPS_MAKE_EPID(IPS_EPMODE_MASTER, 0, 0);
    sys_env.ips_linkdesc_tbl[0].slv_id = IPS_MAKE_EPID(IPS_EPMODE_SLAVE, 0, 0);
    sys_env.ips_linkdesc_tbl[0].mst_port = 1;
    sys_env.ips_linkdesc_tbl[0].slv_port = 6;
    sys_env.ips_linkdesc_tbl[0].is_master = 1;

    sys_env.ips_linkdesc_tbl[1].mst_id = IPS_MAKE_EPID(IPS_EPMODE_MASTER, 0, 1);
    sys_env.ips_linkdesc_tbl[1].slv_id = IPS_MAKE_EPID(IPS_EPMODE_SLAVE, 0, 1);
    sys_env.ips_linkdesc_tbl[1].mst_port = 4;
    sys_env.ips_linkdesc_tbl[1].slv_port = 3;
    sys_env.ips_linkdesc_tbl[1].is_master = 1;

    assert(sys_env.ips_linkdesc_tbl[0].is_master); // I am master
    assert(sys_env.ips_linkdesc_tbl[1].is_master); // I am master

    sys_env.ips_desc_tbl[0].capacity = 0;
    sys_env.ips_desc_tbl[0].pc_num = 1;
    for (i = 0; i < 1; i++) {
        ips_pcdesc_t* pcdesc = &sys_env.ips_desc_tbl[0].pcdesc_tbl[i];
        pcdesc->src_id = sys_env.ips_linkdesc_tbl[0].mst_id;
        pcdesc->dest_id = sys_env.ips_linkdesc_tbl[0].slv_id;
        pcdesc->sector_sz = IPS_CLS_SECTOR_SIZE;
        pcdesc->sector_num = IPS_CLS_SECTOR_NUM;
    }

    sys_env.ips_desc_tbl[1].capacity = 0;
    sys_env.ips_desc_tbl[1].pc_num = 1;
    for (i = 0; i < 1; i++) {
        ips_pcdesc_t* pcdesc = &sys_env.ips_desc_tbl[1].pcdesc_tbl[i];
        pcdesc->src_id = sys_env.ips_linkdesc_tbl[1].mst_id;
        pcdesc->dest_id = sys_env.ips_linkdesc_tbl[1].slv_id;
        pcdesc->sector_sz = IPS_CLS_SECTOR_SIZE;
        pcdesc->sector_num = IPS_CLS_SECTOR_NUM;
    }

    // initialize each module
    zlog_notice(sys_zc, "==> initializing modules ...");
#ifdef ARCH_ppc64
    ret = ips_module_init(NULL);
    assert(!ret);
    ret = idt_module_init(NULL);
    assert(!ret);
#endif
    ret = dfv_module_init(NULL);
    assert(!ret);
    ret = cmi_module_init(NULL);
    assert(!ret);

    //init ips mode
    syslk_parse_ips_mode("./syslk_ips.conf");
    ips_init_mode(syslk_ips_mode);
    zlog_notice(sys_zc,"dma_use_nlwr:%d dma_use_chain:%d tx_wmd:%d tx_rmd:%d rx_wmd:%d rx_rmd:%d",
                syslk_ips_mode.dma_use_nlwr, syslk_ips_mode.dma_use_chain, syslk_ips_mode.tx.use_wptr,
                syslk_ips_mode.tx.use_rptr, syslk_ips_mode.rx.use_wptr, syslk_ips_mode.rx.use_rptr);    
    // initialize ctxs
    memset(&sys_ctx, 0, sizeof(sys_ctx));

    zlog_notice(sys_zc, "==> initializing storage ...");
    const char* repo_mnt_tbl[DFV_MAX_REPOS] = {NULL};
    const char* repo_dev_tbl[DFV_MAX_REPOS] = {NULL};
    for (i=0; i<SYS_MAX_PIPES; i++) {
        repo_mnt_tbl[i] = sys_env.dfv_desc_tbl[i].mnt_path;
        repo_dev_tbl[i] = sys_env.dfv_desc_tbl[i].dev_path;
    }
    sys_ctx.vault = dfv_vault_open(SYS_MAX_PIPES, DFV_SLICE_NUM, repo_mnt_tbl, repo_dev_tbl, 0);
    if (!sys_ctx.vault) {
        zlog_fatal(sys_zc, "failed to initializing storage, quit");
        exit(-1);
    }
    sys_ctx.diskcap = dfv_vault_get_diskcap(sys_ctx.vault);
    // check freeslot
    int slot_id = dfv_vault_get_freeslot(sys_ctx.vault);
    if (slot_id < 0) {
        zlog_fatal(sys_zc, "no spece left on vault, quit");
        exit(-1);
    }

#ifdef ARCH_ppc64
    zlog_notice(sys_zc, "==> initializing switch route table ...");
    int idt_fd = idt_dev_open(2, 0x67);
    assert(idt_fd > 0);
    for (i=0; i<SYS_MAX_PIPES; i++) {
        ips_linkdesc_t* linkdesc = &sys_env.ips_linkdesc_tbl[i];
        // reset link parnter
//        idt_port_recovery(idt_fd, linkdesc->slv_port);
        // reset routetbl entries
        idt_routetbl_set(idt_fd, linkdesc->mst_port,
                         linkdesc->slv_id,
                         linkdesc->slv_port);
        idt_routetbl_set(idt_fd, linkdesc->slv_port,
                         linkdesc->mst_id,
                         linkdesc->mst_port);
    }
    idt_dev_close(idt_fd);

    zlog_notice(sys_zc, "==> initializing srio ...");
    for (i=0; i<SYS_MAX_PIPES; i++) {
        // init repo
        zlog_notice(sys_zc, "  initializing ips_srio: pipe=%d, id=0x%x",
                    i,
                    sys_env.ips_linkdesc_tbl[i].mst_id);
        ret = ips_ep_init(sys_env.ips_linkdesc_tbl[i].mst_id, &sys_env.ips_desc_tbl[i]);
        assert(!ret);
    }
#endif
    sys_ctx.file_cache = malloc(sizeof(sys_cache_t));
    assert(sys_ctx.file_cache);
    memset(sys_ctx.file_cache, 0, sizeof(sys_cache_t));
    sys_ctx.file_cache->slot_id = -1;
    sys_ctx.file_cache->data = malloc(SYS_CACHE_SIZE);
    assert(sys_ctx.file_cache->data);

    zlog_notice(sys_zc, "==> initializing job workers ...");
    for (i=0; i<SYS_MAX_PIPES; i++) {
        sys_wkr_ctx_t* wkr_ctx = malloc(sizeof(sys_wkr_ctx_t));
        assert(wkr_ctx);
        memset(wkr_ctx, 0, sizeof(sys_wkr_ctx_t));

        wkr_ctx->wkr_state = sys_state_idle;
        wkr_ctx->wkr_id = i;
        pthread_mutex_init(&wkr_ctx->buf_snap_lock, NULL);
        sys_jobq_init(&wkr_ctx->job_in);
        sys_jobq_init(&wkr_ctx->job_out);
        wkr_ctx->wkr_thread = malloc(sizeof(pthread_t));
        assert(wkr_ctx->wkr_thread);
        sys_ctx.wkr_ctx_tbl[i] = wkr_ctx;

        pthread_create(wkr_ctx->wkr_thread, NULL, __sys_wkr_job, (void*)wkr_ctx);
    }

    sys_ctx.auto_rec = 0;
    if (sys_ctx.auto_rec) {
        pthread_t thread_autorec;
        pthread_create(&thread_autorec, NULL, __sys_wkr_autorec, NULL);
    }

RECONN:
    zlog_notice(sys_zc, "==> ---------- SERVER START ----------");
    // stop all workers
    for (i=0; i<SYS_MAX_PIPES; i++) {
        sys_wkr_ctx_t* wkr_ctx = sys_ctx.wkr_ctx_tbl[i];
        if (wkr_ctx->wkr_state != sys_state_idle) {
            zlog_notice(sys_zc, "==> stopping job worker#%d ...", i);
            wkr_ctx->reset_req = 1;
            while(wkr_ctx->wkr_state != sys_state_idle) {
                usleep(100);
            }
        }
    }
    
    sys_cmd_exec_stopul(NULL);
    
    if (sys_ctx.cmi_intf) {
        zlog_notice(sys_zc, "==> closing client cmi ...");
        cmi_intf_close(sys_ctx.cmi_intf);
        sys_ctx.cmi_intf = NULL;
    }

    if (sys_ctx.sysdown_req) {
        goto out;
    }

    // open cmi
    zlog_notice(sys_zc, "==> opening client cmi ...");
    sys_ctx.cmi_intf = cmi_intf_open(cmi_type_server,
                                     sys_env.intf_type,
                                     sys_env.endian);
    if (!sys_ctx.cmi_intf) {
        assert(0);
        exit(-1);
    }    
    
    zlog_notice(sys_zc, "==> connecting client cmi ...");
    ret = cmi_intf_connect(sys_ctx.cmi_intf,
                           sys_env.ipaddr,
                           sys_env.port);
    if (ret != SPK_SUCCESS) {
        assert(0);
        exit(-1);
    }

    while(1) {
        // main loop
        // update sys_state
        if (!sys_ctx.auto_rec) {
            // some jobs are done by job workers
            // we do not known when they finished
            // so we inquiry workers state in some states
            switch(sys_ctx.sys_state) {
            case sys_state_rec:
            case sys_state_play:
            case sys_state_dl:
            case sys_state_format:
                {
                    int all_idle = 1;
                    for (int i=0; i<SYS_MAX_PIPES; i++) {
                        sys_wkr_ctx_t* wkr_ctx = sys_ctx.wkr_ctx_tbl[i];
                        if (wkr_ctx && wkr_ctx->wkr_state != sys_state_idle) {
                            all_idle = 0;
                        }
                    }
                    if (all_idle) {
                        sys_change_state(sys_state_idle);
                    }
                }
                break;
            }
        }

        // get message from cmi
        ssize_t msg_size = cmi_intf_read_msg(sys_ctx.cmi_intf,
                                             msg_ibuf,
                                             CMI_MAX_MSGSIZE);
        if (msg_size < 0) {
            zlog_warn(sys_zc, "failed to read from socket: ret=%ld", msg_size);
            goto RECONN;
        }
        if (msg_size == 0) {
            usleep(100);
            continue;
        }

        // msg arrived
//        cmi_msg_dump(ZLOG_LEVEL_NOTICE, msg_ibuf, msg_size);
//        zlog_notice(sys_zc, "> read msg: code=0x%x, size=%ld", MSG_CODE(msg_ibuf), msg_size);

        // notify auto_rec_thread() to quit
        sys_ctx.auto_rec = 0;
        
        ret = SPK_SUCCESS;
        // parse msg
        switch(MSG_CODE(msg_ibuf)) {
        case msg_code_cmd:
            ret = sys_cmd_exec((cmi_cmd_t*)msg_ibuf,
                               msg_size);
            break;
        case msg_code_data:
            ret = sys_msg_parse_data((cmi_data_t*)msg_ibuf, msg_size);
            break;
        case msg_code_cmdresp:
        case msg_code_status:
        default:
            // impossible
            assert(0);
            break;
        }
        if (ret == SPKERR_RESETSYS) {
            zlog_warn(sys_zc, "socket error, restart");
            goto RECONN;
        }
        
        if (sys_ctx.sysdown_req) {
            zlog_notice(sys_zc, "################# SYSTEM SHUTDOWN");
            spk_os_exec("poweroff");
            goto RECONN;
        }
        // TODO: other ret code
    }

out:
    for (i=0; i<SYS_MAX_PIPES; i++) {
        sys_wkr_ctx_t* wkr_ctx = sys_ctx.wkr_ctx_tbl[i];
        if (wkr_ctx) {
            wkr_ctx->quit_req = 1;
            pthread_join(*wkr_ctx->wkr_thread, NULL);
            SAFE_RELEASE(wkr_ctx->wkr_thread);
            SAFE_RELEASE(wkr_ctx);
        }
    }

    return 0;
}
Esempio n. 28
0
File: log.c Progetto: niks3089/nixia
int
log_init()
{
	return (zlog_init(LOG_CONFIG_FILE));
}
Esempio n. 29
0
void logger_init(const char * filename, const char * category) {
	if (strlen(filename) && strlen(category)) {
		massert(!zlog_init(filename), "Can not initialize logger");
		sensey_logger = zlog_get_category(category);
	}
}
Esempio n. 30
0
int main(void)
{
	int l_init = 0;

	l_init = zlog_init("/etc/zlog.conf");
	if (l_init) {
		printf("logging init failed");
		return -1;
	}
	c = zlog_get_category("hngui");
	if (!c) {
		printf("Logging init (category) fail\n");
		return -1;
	}




	zlog_info(c, "Program starting... ");
	DIR           *d;
	struct dirent *dir;
	d = opendir("/var/tmp");
	if (d) {
		while ((dir = readdir(d)) != NULL) {
			zlog_info(c, "%s", dir->d_name);
		}

		closedir(d);
	}

	zlog_info(c, "Created Tree From Sample Text..");
	SetExpansionState(tree, TRUE);
	LogPrintTree(c, tree, PRINT_ONLY_EXPANDED_NODES);
	zlog_info(c, "Tree Size: %d\n", TotalSize(tree));
	initscr();
	mousemask(ALL_MOUSE_EVENTS, NULL);
	cbreak();
	noecho();
	nonl();
	curs_set(0);
	keypad(stdscr, TRUE);
	start_color();
	curs_set(0);
	init_pair(1, COLOR_YELLOW, COLOR_BLACK);
	init_pair(2, COLOR_RED, COLOR_BLACK);
	init_pair(3, COLOR_YELLOW, COLOR_BLUE);
	init_pair(4, COLOR_RED, COLOR_BLUE);

	int startx, starty, width, height;
	height = LINES - 2;
	width  = COLS - 2;
	starty = (LINES - height) / 4;  /* Calculating for a center placement */
	startx = (COLS - width) / 2;    /* of */
	refresh();
	win = create_newwin(height, width, starty, startx);
	if (win == NULL) {
		zlog_info(c, "Window Was null...\n");
		endwin();
		printf("Window was null??\n");
		return -1;
	}

	zlog_info(c, "Rendering Tree into window %p \n", win);
	RenderTreeIntoWindow(tree);
	refresh();
	wrefresh(win);

	int ch;
	while ((ch = getch()) != KEY_F(4)) {
		zlog_info(c, "Trapped Keypress  %d", ch );
		MEVENT event;
		switch (ch) {
		case KEY_RESIZE:
			zlog_info(c, "Resize()");
			RenderTreeIntoWindow(tree);
			refresh();
			wrefresh(win);
			break;
		case KEY_F(3):
			zlog_info(c, "F3=> Refresh");
			RefreshData();
			break;
		case KEY_LEFT:
			zlog_info(c, "Left key");
			toggleExpand(win, false);
			break;
		case KEY_RIGHT:
			zlog_info(c, "Right key");
			toggleExpand(win, true);
			break;
		case KEY_UP:
			zlog_info(c, "Up Key");
			moveUp(win);
			break;
		case KEY_DOWN:
			zlog_info(c, "Down Key");
			moveDown(win);
			break;

		}
		if (getmouse(&event) == OK) {
			zlog_info(c, "Mouse => %d, %d", event.x, event.y);
		}
		//LogPrintTree(c, tree, PRINT_ALL_TREE);

	}

	endwin();
	return 0;
}