Exemple #1
0
void CManager::start()
{
	allExitFlag = false;
	
	writelogimmediatly("[log][Manager]程序启动.\n");
	readcfg();

	try
	{
		loader.init(&g_cfg);
		loader.start();
	}
	catch (...)
	{
		writelogimmediatly("[err][loader]数据库连接失败,请检查配置和数据库服务器是否正常.\n");
		setallthreadexitflag();
		return;
	}
	

	clientmanager.setworker(&worker); //for setevent to worker
	clientmanager.start();
	
	worker.init(&clientmanager,&loader);
	worker.start();

	server.init(&g_cfg,&clientmanager,&loader);	
	server.start();
	
}
int main(int argc, char **argv)
{
	char *cfgfile;
	
	if (sock_start())
		return -1;
	vlist_init(&pipes, pipe_destroy);
	cfg_init(&cfg, 0);
	atexit(cleanup);

	/* Look for the config file in the executable directory.  Windows
	 * uses it as the working directory, so we can use a relative
	 * filename.  On UNIX or the Mac, use the executable path and
	 * filename from argv[0].
	 */
#ifdef __WIN32__
	cfgfile = defcfgfile;
#else
	cfgfile = malloc(strlen(argv[0]) + 4 + 1);
	strcpy(cfgfile, argv[0]);
	strcat(cfgfile, ".cfg");
#endif
	/* Prefer a config file specified on the command line */
	readcfg(argc > 1 ? argv[argc - 1] : cfgfile);
#ifdef DEBUG
	debug();
#endif
	waitclients();
	
	return 0;
}
Exemple #3
0
int main(int argc, char **argv)
{
	if (sock_start())
		return -1;
	vlist_init(&pipes, pipe_destroy);
	cfg_init(&cfg, 0);
	atexit(cleanup);
	readcfg();
#ifdef DEBUG
	debug();
#endif
	waitclients();
	
	return 0;
}
Exemple #4
0
static cfgprm get_config_parameters(const char *relpath)
{
	char **cflines = readcfg(relpath);
	cfgprm prms;
	int cflidx = 0;
	while (cflidx < 3) {
		char *list[4] = {"check_interval", "monitor_level", "quit_level"
							,(char *)NULL };
		cfgdata cd = split_cfg_line(cflines[cflidx]);
		int res = inlist(cd.cfgname, list);
		check_set_config_values(res, &prms, cd);
		cflidx++;
	} // while()
	freelist(cflines);
	return prms;
} // get_config_parameters()
int main (int argc, char *argv[]) {
	struct my_pkthdr pheader;
	struct contents *z;
	char pktbuff[20000];
	int fd, bytes, i, b;
	long long sstart = 0, ustart = 0, timesec = 0, timeusec = 0;
    	struct eth_hdr *ethin;
	struct pcap_pkthdr h;
	struct tcp_hdr *tcphdr;
	next_ack=0;
	next_seq=0;
	int holder;
	char *progname="HOWDIDTHISGETHEREIAMNOTGOODWITHCOMPUTER";
	argv[0]=progname;
	if(argc !=3){
		fprintf(stderr, "USAGE: %s [log file] [config file]\n", argv[0]);
		return(-1);
	}

	if((fd = open(argv[1], O_RDONLY)) == -1){
		fprintf(stderr, "ERROR: on fd = open(argv[1], O_RDONLY)\n");
		return(-1);
	}

	if((bytes = read(fd, &pheader, 24)) !=24){
		fprintf(stderr, "ERROR: on bytes = read()\n");
		return(-1);
	}
	readcfg(argv[2]);	
	open_devices();
	setfilter();
	ethin = malloc(sizeof(struct eth_hdr));
	i = 0;
	while((bytes = read(fd, &pheader, 16)) == 16){
		if(i == 0){
			ustart = pheader.ts.tv_usec;
			sstart = pheader.ts.tv_sec;
		} else {
			timeusec = pheader.ts.tv_usec-ustart;
			timesec = pheader.ts.tv_sec-sstart;
			if (timeusec < 0){
				timeusec += 1000000;
				timesec--;
			}
		}


		printf("\nPacket %d\n%05lld.%06lld\nCaptured Packet Length = %d\n",i,timesec,timeusec,pheader.caplen);
		printf("Actual Packet Length = %d\n", pheader.len);

		if((bytes = read(fd, &pktbuff, pheader.caplen)) !=pheader.caplen){
			fprintf(stdout, "End of file or error on packet read\n");
			fprintf(stdout, "%d\n", pheader.caplen);
			return(-1);
		}
		retrans(&pheader, pktbuff);
	
		layer2((struct eth_hdr *) &pktbuff, bytes);
		i++;
		if(strcmp(timing,"delay")==0){
		  sleep(2);
		}
		b = 0;
	        if((b = pcap_next_ex(p, &h, (const u_char **)&ethin))==1){
		  //tcphdr=(struct tcp_hdr *)(ethin+ETH_HDR_LEN+TCP_HDR_LEN);
	/*	  if(tcphdr->th_seq==next_seq){
		    holder=next_ack;
		    next_ack=tcphdr->th_seq+1;
		    next_seq=holder+1;
		}*/
		}
		
	}

	return(0);
}
Exemple #6
0
int connect_host(/*int m, short event, void* arg*/)
{
	char ipaddr[30];
	char port[10];
	//free(arg);
	readcfg("ctosport",port);
	readcfg("ip",ipaddr);
	static int sec = 2;
	int sock = false;

	static int times_beatheart = 0;
	static int times_regist = 0;

DNS_label:
	if(dnsbyping(ipaddr) == false )
	{
		printf("dns fail");
		goto sleep_label;
	}

socket_label:
	if(	(sock = begin(ipaddr,port)) == false )
	{	
		printf("scoket fail");
		goto sleep_label;	
	}

checkcfg_label:
	if(extid == 0)
		goto regist_label;
	else
		goto beatheart_label;

regist_label:
	if(rgist(sock) == false)
	{
		printf("rgist fail");
		if(times_regist < 5)
		{
			times_regist++;
			sleep(5);
			goto socket_label;
		}
		else
		{
			times_regist = 0;
			goto sleep_label;
		}
	}

beatheart_label:
	if(beatheart(sock) == false)
	{
		printf("heart fail");
		if(times_beatheart < 5)
		{
			times_beatheart++;
			sleep(5);
			goto socket_label;
		}
		else
		{
			times_beatheart = 0;
			goto regist_label;		
		}
	}

waiting_label:
	sec = 2;
	if(waiting(sock) == false)
	{
		printf("task fail");
		goto sleep_label;			
	}

sleep_label:
	if(sock != false)
	{
		close(false);
		sock = false;
	}
	sec = 2;
	if(sec > 3600*24)
		sec = 3600*24;
	//Timer(sec,connect_host,NULL);
	printf("%d\n", sec);
	return sec;
}
Exemple #7
0
int main (int argc, char *argv[])
#endif
{
  char tmp[128];
#if defined(HAVE_FORK)
  char **saved_argv;

  mypid = getpid();
  /* save argv as setproctitle() under some systems will change it */
  saved_argv = mkargv (argc, argv);

  configpath = parseargs(argc, saved_argv);
#else
  configpath = parseargs(argc, argv);
#endif

  saved_envp = mkargv (-1, environ);

#ifdef WIN32
  if (service_flag==w32_installservice && !configpath)
    Log (0, "%s: invalid command line: config name must be specified", extract_filename(argv[0]));
  w32Init();
#ifdef BINKD9X
  {
    int win9x_rc;

    win9x_rc = win9x_process(argc, argv);
    if (win9x_rc != -1)
      return win9x_rc;
  }
#endif
#endif

  tzset();

  if (poll_flag && server_flag)
    Log (0, "-p and -s cannot be used together");

#if defined(WIN32) && !defined(BINKD9X)
  if (service_flag!=w32_noservice)
    if (service(argc, argv, environ) && service_flag!=w32_run_as_service) {
      Log(0, "Windows NT service error");
    }
  if (tray_flag)
     do_tray_flag();
  else
  {
    atexit(UnloadBinkdIcon);
    LoadBinkdIcon();
  }
#endif

  /* No command line options: run both client and server */
  if (!client_flag && !server_flag)
    client_flag = server_flag = 1;

  InitSem (&hostsem);
  InitSem (&resolvsem);
  InitSem (&lsem);
  InitSem (&blsem);
  InitSem (&varsem);
  InitSem (&config_sem);
  InitEventSem (&eothread);
  InitEventSem (&wakecmgr);
#ifdef OS2
  InitSem (&fhsem);
#endif

  /* Init for ftnnode.c */
  nodes_init ();

  if (configpath)
  {
    current_config = readcfg (configpath);
    if (!current_config)
      Log (0, "error in configuration, aborting");
    if (dumpcfg_flag)
    {
      debug_readcfg ();
      exit(0);
    }
    InitLog(current_config->loglevel, current_config->conlog,
            current_config->logpath, current_config->nolog.first);
  }
  else if (verbose_flag)
  {
#if defined(WIN32) && defined(BINKD9X)
    AllocTempConsole();
#endif

    printf ("Binkd " MYVER " (" __DATE__ " " __TIME__ "%s)\n", get_os_string ());
    if (verbose_flag>1)
    {
      printf ("Compilation flags: " _DBNKD ".\n");
      printf ("Facilities: "
#ifndef srv_getaddrinfo
              "fsp1035 "
#endif
#ifndef HAVE_GETADDRINFO
              "rfc2553emu "
#else
              "ipv6 "
#endif
              "\n");
    }
    exit (0);
  }
  else if (argc > 1)
    Log (0, "%s: invalid command line: config name must be specified", extract_filename(argv[0]));
  else
    usage ();

  print_args (tmp, sizeof (tmp), argv + 1);
#ifdef WIN32
  if (service_flag==w32_run_as_service)
    Log (4, "BEGIN service '%s', " MYNAME "/" MYVER "%s%s", service_name, get_os_string(), tmp);
  else
    Log (4, "BEGIN standalone, " MYNAME "/" MYVER "%s%s", get_os_string(), tmp);
#else
  Log (4, "BEGIN, " MYNAME "/" MYVER "%s%s", get_os_string(), tmp);
#endif
  if (sock_init ())
    Log (0, "sock_init: %s", TCPERR ());

  bsy_init ();
  rnd ();
  initsetproctitle (argc, argv, environ);
#ifdef WIN32
  SetFileApisToOEM();
#endif

  /* Set up break handler, set up exit list if needed */
  if (!set_break_handlers ())
    Log (0, "cannot install break handlers");

#if defined(SIGPIPE)
  signal(SIGPIPE, SIG_IGN);
#endif

#if defined(WITH_ZLIB) && defined(ZLIBDL)
  if (current_config->zlib_dll[0]) {
    if (!zlib_init(current_config->zlib_dll))
      Log (2, "cannot load %s, GZ compression disabled", current_config->zlib_dll);
    else
      Log (6, "%s loaded successfully", current_config->zlib_dll);
  } else
    Log (current_config->zrules.first ? 3 : 5, "zlib-dll not defined, GZ compression disabled");
#endif
#if defined(WITH_BZLIB2) && defined(ZLIBDL)
  if (current_config->bzlib2_dll[0]) {
    if (!bzlib2_init(current_config->bzlib2_dll))
      Log (2, "cannot load %s, BZ2 compression disabled", current_config->bzlib2_dll);
    else
      Log (6, "%s loaded successfully", current_config->bzlib2_dll);
  } else
    Log (current_config->zrules.first
#ifdef WITH_ZLIB
         && !zlib_loaded
#endif
         ? 3 : 5, "bzlib2-dll not defined, BZ2 compression disabled");
#endif

#ifdef WITH_PERL
  if (current_config->perl_script[0]) {
    if (!perl_init(current_config->perl_script, current_config)) {
      if (current_config->perl_strict)
        Log (0, "error parsing Perl script %s", current_config->perl_script);
    } else {
      perl_on_start(current_config);
      perl_config_loaded(current_config);
    }
  }
#endif

#ifdef HAVE_FORK
  signal (SIGCHLD, sighandler);
#endif

  { /* Create polls and release polls list */
    struct maskchain *psP;
    for (psP = psPolls.first; psP; psP = psP->next)
      poll_node (psP->mask, current_config);
    simplelist_free(&psPolls.linkpoint, destroy_maskchain);
  }

  if (no_flag)
    Log (0, "Exit on option '-n'");

  if (inetd_flag)
  {
    FTN_ADDR ftn_addr, *pftn_addr;
    int tempfd;

    pftn_addr = NULL;
    if (remote_node)
    {
      if (parse_ftnaddress (remote_node, &ftn_addr, current_config->pDomains.first))
      {
        char szFTNAddr[FTN_ADDR_SZ + 1];

        exp_ftnaddress (&ftn_addr, current_config->pAddr, current_config->nAddr, current_config->pDomains.first);
        pftn_addr = &ftn_addr;
        ftnaddress_to_str (szFTNAddr, pftn_addr);
        Log (3, "Session with %s", szFTNAddr);
      }
      else
        Log (1, "`%s' cannot be parsed as a Fido-style address", remote_node);
    }
    if (!remote_addr)
    {
      char *p = getenv("SSH_CONNECTION");

      if (p)
      {
	remote_addr = strdup(p);
	p = strchr(remote_addr, ' ');
	if (p) *p = '\0';
      }
    }
    /* not using stdin/stdout itself to avoid possible collisions */
    if (inetd_socket_in == -1)
      inetd_socket_in = dup(fileno(stdin));
    if (inetd_socket_out == -1)
      inetd_socket_out = dup(fileno(stdout));
#ifdef UNIX
    tempfd = open("/dev/null", O_RDWR);
#else
    tempfd = open("nul", O_RDWR);
#endif
    if (tempfd != -1)
    {
      dup2(tempfd, fileno(stdin));
      dup2(tempfd, fileno(stdout));
      close(tempfd);
    }
    protocol (inetd_socket_in, inetd_socket_out, NULL, pftn_addr, remote_addr, current_config);
    soclose (inetd_socket_out);
    exit (0);
  }

#ifdef BINKD_DAEMONIZE
  if (daemon_flag)
  {
    if (binkd_daemonize(1) < 0)
      Log (0, "Cannot daemonize");
    else
      mypid = getpid();
  }
#endif

#if defined(HAVE_FORK)
  signal (SIGHUP, sighandler);
#endif

  if (client_flag && !server_flag)
  {
    clientmgr (0);
    exit (0);
  }

  pidsmgr = (int) getpid ();
  if (client_flag && (pidcmgr = branch (clientmgr, 0, 0)) < 0)
  {
    Log (0, "cannot branch out");
  }

  if (*current_config->pid_file)
  {
    if ( unlink (current_config->pid_file) == 0 ) /* successfully unlinked, i.e.
	                                            an old pid_file was found */
	Log (1, "unexpected pid_file: %s: unlinked", current_config->pid_file);
    else
    {
	int current_log_level = 1;
	switch ( errno )
	{
	   case ENOENT :	/* file not found or null pathname */
		current_log_level = 8; /* it's ok */
		break;
	   default :
		break;
	}
	Log (current_log_level, "unlink_pid_file: %s: %s", current_config->pid_file, strerror (errno));
    }
    create_sem_file (current_config->pid_file, 1);
  }

  servmgr ();

  return 0;
}
Exemple #8
0
void mrbig(void)
{
	char *p;
	time_t t, lastrun;
	int sleeptime, i;
	char hostname[256];
	DWORD hostsize;

	/*
	 * install exception logging/stacktrace handler.
	 * We need to resolve the symbol at run time because windows 2000
	 * does not have it.
	 */
	do {
		HMODULE dll;
		PVOID (*ptr) (ULONG First,PVECTORED_EXCEPTION_HANDLER Handler) = NULL;
		dll = LoadLibraryEx("kernel32.dll", NULL, 0);
		if (dll == NULL)
			break;
		ptr = (typeof(ptr))GetProcAddress(dll, "AddVectoredExceptionHandler");
		if (ptr == NULL)
			break;
		ptr(1, VectoredExceptionHandler);
		mrlog("VectoredExceptionHandler handler has been installed");
	} while(0);

	if (debug) {
		mrlog("mrbig()");
	}
	for (i = 0; _environ[i]; i++) {
		startup_log("%s", _environ[i]);
	}
	for (;;) {
		if (debug) mrlog("main loop");
		read_cfg("mrbig", cfgfile);
		readcfg();
		t = time(NULL);
		strlcpy(now, ctime(&t), sizeof now);
		p = strchr(now, '\n');
		if (p) *p = '\0';
		hostsize = sizeof hostname;
		if (GetComputerName(hostname, &hostsize)) {
			for (i = 0; hostname[i]; i++)
				hostname[i] = tolower(hostname[i]);
			snprcat(now, sizeof now, " [%s]", hostname);
		}

		cpu();
		check_chunks("after cpu test");

		disk();
		check_chunks("after disk test");

		memory();
		check_chunks("after memory test");

		msgs();
		check_chunks("after msgs test");

		procs();
		check_chunks("after procs test");

		svcs();
		check_chunks("after svcs test");

		wmi();
		check_chunks("after wmi test");

		if (pickupdir[0]) ext_tests();

		lastrun = t;
		t = time(NULL);
		if (t < lastrun) {
			mrlog("mainloop: timewarp detected, sleep for %d",
				mrloop);
			sleeptime = mrloop;
		} else {
			sleeptime = mrloop-(t-lastrun);
		}
		if (sleeptime < SLEEP_MIN) sleeptime = SLEEP_MIN;
		if (debug) mrlog("started at %d, finished at %d, sleep for %d",
			(int)lastrun, (int)t, sleeptime);
		clear_cfg();
		if (debug) {
			dump_chunks();
			check_chunks("after main loop");
		}
		Sleep(sleeptime*1000);
	}
}
Exemple #9
0
int main (int argc, char *argv[]) {
	char pktbuff[20000];
	//struct pcap_file_header fheader;
	struct my_pkthdr pheader;
	int fd, bytes, i;
	long long sstart = 0, ustart = 0, timesec = 0, timeusec = 0;

	if(argc !=3){
		fprintf(stderr, "USAGE: ./executable [log file] [config file]\n");
		return(-1);
	}

	if((fd = open(argv[1], O_RDONLY)) == -1){
		fprintf(stderr, "ERROR: on fd = open(argv[1], O_RDONLY)\n");
		return(-1);
	}

	if((bytes = read(fd, &pheader, 24)) !=24){
		fprintf(stderr, "ERROR: on bytes = read()\n");
		return(-1);
	}

        readcfg(argv[2]);
	printf("config file opend\n");
	open_devices();


	i = 0;
	while((bytes = read(fd, &pheader, 16)) == 16){
		if(i == 0){
			ustart = pheader.ts.tv_usec;
			sstart = pheader.ts.tv_sec;
		} else {
			timeusec = pheader.ts.tv_usec-ustart;
			timesec = pheader.ts.tv_sec-sstart;
				if (timeusec < 0){
					timeusec += 1000000;
					timesec--;
				}
		}


		printf("\nPacket %d\n%05lld.%06lld\nCaptured Packet Length = %d\n",i,timesec,timeusec,pheader.caplen);
		printf("Actual Packet Length = %d\n", pheader.len);

		if((bytes = read(fd, &pktbuff, pheader.caplen)) !=pheader.caplen){
			fprintf(stdout, "End of file or error on packet read\n");
			fprintf(stdout, "%d\n", pheader.caplen);
			return(-1);
		}
		

		retrans(&pheader, pktbuff);

		layer2((struct eth_hdr *) &pktbuff, bytes);
		i++;
	}


	return(0);
}