Пример #1
0
int main(int argc, char *argv[]) {
  // Catch signals
  signal(SIGINT, mh_sigint);
  signal(SIGTERM, mh_sigint);

  // Initialise LEDs
  if (matrix_init() < 0) return 1;

  // Set up OSC server
  const char *path;
  lo_server_thread st;
  int chmod_err = 0;

  if (argc > 1) {
    path = argv[1];
  } else {
    path = SOCKET_PATH;
  }

  unlink(path);
  st = lo_server_thread_new(path, mh_osc_error);
  chmod_err = chmod_socket(path);

  if (chmod_err != 0) {
    fprintf(stderr, "Error changing socket permissions\n");
    return 1;
  }

  // Set up OSC message handlers
  lo_server_thread_add_method(st, "/set", "iii", mh_osc_set, NULL);
  lo_server_thread_add_method(st, "/render", NULL, mh_osc_render, NULL);
  lo_server_thread_add_method(st, "/clear", NULL, mh_osc_clear, NULL);
  lo_server_thread_start(st);

  // Ready
  printf("Listening on socket: %s\n", path);

  while (1) {
    usleep(1000);
  }

  // Cleanup
  lo_server_thread_free(st);
  mh_cleanup();

  return 0;
}
Пример #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;
}
Пример #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;
}
Пример #4
0
static void mh_sigint(int sig) {
  mh_cleanup();
}