Beispiel #1
0
int main(int argc, char *argv[])
{
    short port = 0;
    char *path;
	int udp_flag = 0;
    
    int opt;
	while((opt = getopt(argc, argv, "u:f:p:P:h:m:tSf:")) != -1)
	{
		switch(opt)
		{
            case 'f':
                path = strdup(optarg);
                break;
                
            case 'p':
                port = (short)atoi(optarg);
                break;

			case 'u':
				udp_flag = (short)atoi(optarg);
				break;
                
            default:	/* '?' */
                printf("dcenter version:%s \nusage: %s -f save_file_path -p listen_port -u udp_flag \n", DC_VERSION, argv[0]);
                return 1;
		}
	}

	if (path == NULL || port <= 0)
	{
        printf("dcenter version:%s \nusage: %s -f save_file_path -p listen_port -u udp_flag \n", DC_VERSION, argv[0]);
		return 1;
	}

    /* libevent thread */
    evthread_use_pthreads();
    
    dcycle = cycle_init();
    dcycle->path = (path != NULL) ? strdup(path) : NULL;
    dcycle->lport = port;
	dcycle->udp_flag = udp_flag;
    
    /* signal process */
    signal(SIGPIPE, SIG_IGN);

    open_record_file();
    
    /* init dcenter sock */
  	if(dcycle->udp_flag==1)
	{
		dcenter_sock_udp_init();
	}
	else
	{
		dcenter_sock_tcp_init();
	}

    /* dcenter sock */
    dcenter_sock();
    
	return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	char			*conf_path;
	struct passwd	*pwd;
	FILE			*pidfd;
	zgx_listening_t	*listen;
	uid_t			uid;
	gid_t			gid;
	char			c;
	int				ret;
	int				i;

	while ((c = getopt(argc,argv,"c:")) != -1 ) {
		switch (c) {
		case 'c':
			conf_path = optarg;
			break;
		default:
			fprintf(stderr,"Usage:%s -c ConfigFile\r\n",argv[0]);
			return -1;
		}
	}

    fprintf(stderr,"conf path %s\n",conf_path);
	if ( (ret = parse_conf(conf_path)) < 0) {
		return -1;
	}

	cycle_init();
	zgx_shmtx_init();

	/* If we're root and we're going to become another user, get the uid/gid
    ** now.
    */
	
	if (getuid() == 0) {
		pwd = getpwnam("www");
		if (!pwd) {
			fprintf(stderr,"unkown user:%s\n",conf.user);
			return -1;
		}
		
		uid = pwd->pw_uid;
		gid = pwd->pw_gid;
	}
	/*logfile
	*/
	if (conf.log[0] != '/') {
		fprintf(stderr,"pls set log abs path!\n");
		return -1;
	}
	
	cycle.logfp = fopen(conf.log,"a");
	if (!cycle.logfp){
		fprintf(stderr,"open the log [%s] error!\n",conf.log);
		return -1;
	}

	if (getuid() == 0) {
		if ( fchown(fileno(cycle.logfp),uid,gid) < 0) {
			fprintf(stderr,"fchown logfile - error!\n");
			return -1 ;
		}
	}
	
	/*daemonize
	*/
	if ( (ret = make_deamon()) < 0 ) {
		fprintf(stderr,"make daemon error!\n");
		return -1;
	}

	if (conf.pidfile[0] != '/') {
		fprintf(stderr,"it's not a abs path!\n");
	}
	
	pidfd = fopen(conf.pidfile,"w");
	if (!pidfd){
		fprintf(stderr, "can't open [%s] pid file!\n",conf.pidfile);
		return -1;
	}

	fprintf(pidfd,"%d\n",(int)getpid());
	fclose(pidfd);

    zgx_log(ERROR,"begin to listen!");
	if ( init_listening_socket(listen) < 0 ) {
        return -1;
	}
	
	for (i=0;i<conf.process_num;i++) {
		zgx_start_worker_process((void *)(int) i, zgx_worker_process_cycle);
	}
	
	
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    char* host = NULL;
    short port = 0;
	char* interface = NULL;
    char* conf;
    
    int opt;
	while((opt = getopt(argc, argv, "c:i:p:P:h:m:tSf:")) != -1)
	{
		switch(opt)
		{
		    case 'c':
                conf = strdup(optarg);
                break;
            case 'i':
                interface = strdup(optarg);
                break;
                
            case 'h':
                host = strdup(optarg);
                break;
                
            case 'p':
                port = (short)atoi(optarg);
                break;
                
            default:	/* '?' */
                printf("dagent version:%s \nusage: %s -c conf_file -h sync_host -p sync_port -i ethx \n", DA_VERSION, argv[0]);
                return 1;
		}
	}

	if (host == NULL || port <= 0 || (interface == NULL))
	{
        printf("dagent version:%s \nusage: %s -c conf_file -h sync_host -p sync_port -i ethx \n", DA_VERSION, argv[0]);
		return 1;
	}
    
    /* libevent thread */
    evthread_use_pthreads();
    
    dcycle = cycle_init();
    dcycle->interface = (interface != NULL) ? strdup(interface) : NULL;
    dcycle->conf = (conf != NULL) ? strdup(conf) : NULL;
    
    /* set work mode */
    dcycle->port = port;
    dcycle->host = strdup(host);
    
    /* signal process */
    signal(SIGPIPE, SIG_IGN);
	
    /* load host */
    load_host_sample();
    
    /* init dcenter sock */
    dcenter_sock_init();
    
	pthread_t pt_health;
	pthread_create(&pt_health, NULL, health, NULL);
    
    /* work mode */
    capture(interface, DA_FILTER);
    
    void *pt_res;
	pthread_join(pt_health, &pt_res);
    
	return 0;
}