Exemplo n.º 1
0
/**
 * @brief Destroys a hash table structure 
 *
 * @param hash_table Hash table structure
 */
void mh_destroy(HashTable *hash_table)
{
     free(hash_table->permutations);
     free(hash_table->buckets);
     free(hash_table->a);
     free(hash_table->b);
     list_destroy(&hash_table->used_buckets);
     mh_init(hash_table);
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	pthread_t sigth;
	sigset_t sigblock;
	int logflags = 0;
	int ret = 1;

	debug_init();

	sigemptyset(&sigblock);
	sigaddset(&sigblock, SIGHUP);
	sigaddset(&sigblock, SIGINT);
	sigaddset(&sigblock, SIGTERM);
#ifdef ENABLE_VT
	sigaddset(&sigblock, SIGPIPE);
#endif
	pthread_sigmask(SIG_BLOCK, &sigblock, NULL);

	if (conf_parse(&conf, argc, argv))
		return 1;

	if (conf.debug_level > 0)
		logflags = LOG_PERROR;

	openlog(basename(argv[0]), LOG_PID|logflags, LOG_DAEMON);

	syslog(LOG_INFO, "%s v%s started (%s)", PACKAGE_NAME, PACKAGE_VERSION,
	       entity_string[conf.mip6_entity]);
#ifdef ENABLE_VT
	if (vt_init() < 0)
		goto vt_failed;
#endif

	/* if not debugging, detach from tty */
	if (conf.debug_level == 0)
		daemon_start(1);
	else {
		/* if debugging with debug log file, detach from tty */
		if (conf.debug_log_file) {
			daemon_start(1);

			ret = debug_open(conf.debug_log_file);
			if (ret < 0) {
				fprintf(stderr, "can't init debug log:%s\n",
					strerror(-ret));
				goto debug_failed;
			}
			dbg("%s started in debug mode\n", PACKAGE_NAME);
		} else {
			dbg("%s started in debug mode, not detaching from terminal\n",
			    PACKAGE_NAME);
		}
		conf_show(&conf);
	}

	srandom(time(NULL));

	if (rr_cn_init() < 0)
		goto rr_cn_failed;
	if (policy_init() < 0)
		goto policy_failed;
	if (taskqueue_init() < 0)
		goto taskqueue_failed;
	if (bcache_init() < 0)
		goto bcache_failed;
	if (mh_init() < 0)
		goto mh_failed;
	if (icmp6_init() < 0)
		goto icmp6_failed;
	if (xfrm_init() < 0)
		goto xfrm_failed;
	cn_init();
	if ((is_ha() || is_mn()) && tunnelctl_init() < 0)
		goto tunnelctl_failed;
	if (is_ha() && ha_init() < 0) 
		goto ha_failed;
	if (is_mn() && mn_init() < 0)
		goto mn_failed;
#ifdef ENABLE_VT
	if (vt_start(conf.vt_hostname, conf.vt_service) < 0)
		goto vt_start_failed;
#endif
	if (pthread_create(&sigth, NULL, sigh, NULL))
		goto sigth_failed;
	pthread_join(sigth, NULL);
	ret = 0;
sigth_failed:
#ifdef ENABLE_VT
	vt_fini();
vt_start_failed:
#endif
	if (is_mn())
		mn_cleanup();
mn_failed:
	if (is_ha())
		ha_cleanup();
ha_failed:
	if (is_ha() || is_mn())
		tunnelctl_cleanup();
tunnelctl_failed:
	cn_cleanup();
	xfrm_cleanup();
xfrm_failed:
	icmp6_cleanup();
icmp6_failed:
	mh_cleanup();
mh_failed:
	bcache_cleanup();
bcache_failed:
	taskqueue_destroy();
taskqueue_failed:
	policy_cleanup();
policy_failed:
rr_cn_failed:
	debug_close();
debug_failed:
#ifdef ENABLE_VT
vt_failed:
#endif
	syslog(LOG_INFO, "%s v%s stopped (%s)", PACKAGE_NAME, PACKAGE_VERSION,
	       entity_string[conf.mip6_entity]);
	closelog();
	return ret;
}
Exemplo n.º 3
0
int main()
{
  HeapType *heap;
  void  *ptr1, *ptr2, *ptr3, *ptr4;

  heap = (HeapType *) malloc(sizeof(HeapType));
  mh_init(heap);

  ptr1 = mh_alloc(heap, 5*sizeof(int), "ints");
  ptr2 = mh_alloc(heap, 10*sizeof(double), "doubles");
  ptr3 = mh_alloc(heap, 8*sizeof(char), "chars");
  ptr4 = mh_alloc(heap, 12*sizeof(StudentType), "Students");

  printf("\nDUMP 1, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_dealloc(heap, ptr1);
  mh_dealloc(heap, ptr2);
  mh_dealloc(heap, ptr3);

  printf("\nDUMP 2, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_collect(heap);

  printf("\nDUMP 3, byte count = %d\n", mh_count(heap));
  mh_dump(heap);


  /* Additional tests:
   *    70  floats
   *     9  MatrixTypes
   *    20  ServerEntryTypes
   *  32+2  Point3DTypes
   *    10  longs
   *    64  HeapTypes (lol)
   **/
  printf("\n--> ADDITIONAL TESTING:\n");

  mh_alloc(heap, 70*sizeof(float), "floats");

  printf("\nDUMP 4, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  void *server_entries;
  server_entries = mh_alloc(heap, 20*sizeof(ServerEntryType), "ServerEntries");
  mh_alloc(heap, 9*sizeof(MatrixType), "Matrices");

  printf("\nDUMP 5, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_dealloc(heap, server_entries);
  mh_alloc(heap, 32*sizeof(Point3DType), "3D points");
  mh_alloc(heap, 2*sizeof(Point3DType), "3D Points");

  printf("\nDUMP 6, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_collect(heap);
  mh_alloc(heap, 10*sizeof(long), "longs");

  printf("\nDUMP 7, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  mh_alloc(heap, 64*sizeof(HeapType), "heaps"); // not initialized

  printf("\nDUMP 8, byte count = %d\n", mh_count(heap));
  mh_dump(heap);

  printf("\n\n");
  mh_cleanup(heap);
  free(heap);

  return 0;
}