示例#1
0
文件: api_common.c 项目: neufbox/misc
void api_init( void )
{
    api_signal_setup(  );
    nbu_log_open( "fastcgi" );

    nbu_log_info( "api starting" );

#ifdef DMALLOC
    dmalloc_debug_setup( "log-stats,log-non-free,check-fence,log=/tmp/apid.%p" );
#endif

    nbd_connect(  );

    nbu_log_info( "api started" );
}
示例#2
0
文件: malloc.c 项目: gabrielsk/Cronus
void malloc_init (void)
{
#if defined(DMALLOC) && defined(CYGWIN)
	// http://dmalloc.com/docs/latest/online/dmalloc_19.html
	dmalloc_debug_setup(getenv("DMALLOC_OPTIONS"));
#endif
#ifdef GCOLLECT
	// don't garbage collect, only report inaccessible memory that was not deallocated
	GC_find_leak = 1;
	GC_INIT();
#endif
#ifdef USE_MEMMGR
	memmgr_init ();
#endif
}
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved)
{
#ifdef DMALLOC
    char *options =
        getenv("DMALLOC_OPTIONS");
    if (!options) {
        options = 
            "debug=0x4f47d03,"
            "lockon=20,"
            "log=dmalloc-sigar.log";
    }
    dmalloc_debug_setup(options);
#endif
    return JNI_VERSION_1_2;
}
int main(int argc, char* argv[]) {
	properties[0] = "IsMobile";
	properties[1] = "PlatformName";
	properties[2] = "PlatformVersion";
	int propertiesCount = 3;
	const char* fileName = argc > 1 ? argv[1] : "../../../data/51Degrees-LiteV3.2.dat";
	const char* inputFile = argc > 2 ? argv[2] : "../../../data/20000 User Agents.csv";

#ifdef _DEBUG
#ifndef _MSC_VER
	dmalloc_debug_setup("log-stats,log-non-free,check-fence,log=dmalloc.log");
#endif
#endif

	// Create a pool of 4 worksets with a cache for 1000 items.
	fiftyoneDegreesDataSetInitStatus status =
		fiftyoneDegreesInitProviderWithPropertyArray(
		fileName, &provider, (const char**)properties, propertiesCount, 4, 1000);
	if (status != DATA_SET_INIT_STATUS_SUCCESS) {
		reportDatasetInitStatus(status, fileName);
		fgetc(stdin);
		return 1;
	}

	run(&provider, properties, propertiesCount, inputFile);

	// Free the pool, dataset and cache.
	fiftyoneDegreesProviderFree(&provider);

#ifdef _DEBUG
#ifdef _MSC_VER
	_CrtDumpMemoryLeaks();
#else
	printf("Log file is %s\r\n", dmalloc_logpath);
#endif
#endif

	// Wait for a character to be pressed.
	fgetc(stdin);

	return 0;
}
示例#5
0
/*--------------------------------------------------------- */
void 
clish_startup(int argc, const char **argv)
{
#ifdef DMALLOC
  /*
   * Get environ variable DMALLOC_OPTIONS and pass the settings string
   * on to dmalloc_debug_setup to setup the dmalloc debugging flags.
   */
  dmalloc_debug_setup(getenv("DMALLOC_OPTIONS"));
#endif

    if(argc > 1)
    {
        const char *help_switch = "-help";
        if(strstr(help_switch,argv[1]) == help_switch)
        {
            usage(argv[0]);
            exit(1);
        }
    }
}
int main(int argc, char* argv[]) {

	// Required properties. Empty string initializes all properties.
	const char* requiredProperties = "IsMobile,BrowserName";

	// Path to 51Degrees data files. Or use default paths.
	const char* fileName = argc > 1 ? argv[1] :
		"../../../data/51Degrees-LiteV3.2.dat";
	// Path to file containing HTTP User-Agent strings.
	const char* inputFile = argc > 2 ? argv[2] :
		"../../../data/20000 User Agents.csv";

#ifdef _DEBUG
#ifndef _MSC_VER
	dmalloc_debug_setup("log-stats,log-non-free,check-fence,log=dmalloc.log");
#else
	_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif
#endif

	// How many times the dataset was reloaded.
	int numberOfReloads = 0;

#ifndef FIFTYONEDEGREES_NO_THREADING
	printf("** Multi Threaded Reload Example **\r\n");
#else
	printf("** Single Threaded Reload Example **\r\n");
#endif

	// Create a pool of 4 worksets with a cache for 1000 items.
	fiftyoneDegreesDataSetInitStatus status =
		fiftyoneDegreesInitProviderWithPropertyString(
		fileName, &provider, requiredProperties, 4, 1000);
	if (status != DATA_SET_INIT_STATUS_SUCCESS) {
		reportDatasetInitStatus(status, fileName);
		fgetc(stdin);
		return 1;
	}

#ifndef FIFTYONEDEGREES_NO_THREADING
	FIFTYONEDEGREES_MUTEX_CREATE(lock);
	if (FIFTYONEDEGREES_MUTEX_VALID(&lock)) {
		startThreads(inputFile);

		char *fileInMemory;
		long currentFileSize;

		while (threadsFinished < numberOfThreads) {
			// Load file into memory.
			currentFileSize = loadFile(fileName, &fileInMemory);
			// Refresh the current dataset.
			fiftyoneDegreesProviderReloadFromMemory(&provider, (void*)fileInMemory, currentFileSize);
			fiftyoneDegreesDataSet *ds = (fiftyoneDegreesDataSet*)provider.activePool->dataSet;
			// Tell the API to free the memory occupied by the data file when the dataset is freed.
			ds->memoryToFree = (void*)fileInMemory;

			numberOfReloads++;
#ifdef _MSC_VER
			Sleep(1000); // milliseconds
#else
			sleep(1); // seconds
#endif
		}
		stopThreads();
		FIFTYONEDEGREES_MUTEX_CLOSE(lock);
	}
#else
	numberOfReloads = runRequest(inputFile);
#endif

	// Free the pool, dataset and cache.
	fiftyoneDegreesProviderFree(&provider);

	// Finish execution.
	printf("Reloaded '%i' times.\r\n", numberOfReloads);

#ifdef _DEBUG
#ifdef _MSC_VER
	_CrtDumpMemoryLeaks();
#else
	printf("Log file is %s\r\n", dmalloc_logpath);
#endif
#endif

	printf("Program execution complete. Press any Return to exit.");
	fgetc(stdin);

	return 0;
}
示例#7
0
int			main(int ac, char **av)
{
  pcap_t		*handle;
  char			errbuf[PCAP_ERRBUF_SIZE];
  struct bpf_program	fp;
  char			filter_exp[FILTER_MAX_SIZE];
  bpf_u_int32		mask;
  bpf_u_int32		net;
  u_char		*packet;
  pthread_t		scheduler;

  signal_prep();
  packet=0;
  e=init_env();
  get_opt(ac, av);
#ifndef __APPLE__
  if (!(e->option & OPT_VERBOSE))
    daemon(ZERO,ZERO);
  if (e->option & OPT_GARBAGE)
    new_process(ac, av);
#endif
  write_pid_number(e->pidfile_path);
  if (IS_VERBOSE)
    {
      send_log(LOG_INFO, "[1] verbose : on\n");
      send_log(LOG_DEBUG, "[2] Preallocate msg mem size (alignement not include) : %d x %u = %u\n",
	       e->max_tab_size,sizeof(t_msg),e->max_tab_size * (sizeof(t_msg)));
      send_log(LOG_DEBUG, "[3] device : [%s]\n",e->dev);
      send_log(LOG_DEBUG, "[4] filter : [%s]\n",e->filter);
    }
  if (pthread_mutex_init(&gl_lock_set_rmq, NULL) != 0)
    {
      send_log(LOG_CRIT, "[5] Mutex init failed\n");
      mooner_exit(EXIT_MUTEX_ERR);
    }
  set_rmq_server_list();
  if (pthread_mutex_init(&gl_lock_garbage, NULL) != 0)
    {
      send_log(LOG_CRIT, "[5] Mutex init failed\n");
      mooner_exit(EXIT_MUTEX_ERR);
    }
  if (pthread_mutex_init(&gl_lock_send_data, NULL) != 0)
    {
      send_log(LOG_CRIT, "[44] Mutex init failed\n");
      mooner_exit(EXIT_MUTEX_ERR);
    }
  if (pthread_create(&scheduler,NULL,th_scheduler,NULL) != ZERO)
    {
      send_log(LOG_CRIT, "[6] Can't create Thread for scheduling\n");
      mooner_exit(EXIT_THREAD_CREA);
    }
  if (!IS_DEVICE)
    e->dev = pcap_lookupdev(errbuf);
  if (e->dev== NULL) {
    send_log(LOG_ERR, "[7] Couldn't find default dev: %s\n", errbuf);
    mooner_exit(2);
  }
  if (pcap_lookupnet(e->dev, &net, &mask, errbuf) == -1) {
    send_log(LOG_ERR, "[8] Couldn't get netmask for dev %s: %s\n", e->dev, errbuf);
    net = 0;
    mask = 0;
  }
  handle = pcap_open_live(e->dev, BUFSIZ, 1, 1000, errbuf);
  if (handle == NULL) {
    send_log(LOG_ERR, "[9] Couldn't open dev %s: %s\n", e->dev, errbuf);
    mooner_exit(2);
  }
  if (pcap_compile(handle, &fp, e->filter, 0, net) == -1) {
    send_log(LOG_ERR, "[10] Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle));
    mooner_exit(2);
  }
  if (pcap_setfilter(handle, &fp) == -1) {
    send_log(LOG_ERR, "[11] Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle));
    mooner_exit(2);
  }
#ifdef DMALLOC
  dmalloc_debug_setup("debug=0x4f47d03,log=logfile");
#endif
  while(!(EXITING))
    {
      if (IS_VERBOSE)
	send_log(LOG_DEBUG, "[12] entering loop\n");
      pcap_loop(handle, -1, handle_packet, packet);
    }
  pcap_close(handle);
  mooner_exit(ZERO);
  return(ZERO);
}