int
main (int argc, char **argv)
{
    struct GNUNET_OS_Process *openssl;

    if (argc != 3)
        return 1;
    removecerts (argv[1], argv[2]);
    close (2);                    /* eliminate stderr */
    /* Create RSA Private Key */
    /* openssl genrsa -out $1 1024 2> /dev/null */
    openssl =
        GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "openssl", "openssl", "genrsa",
                                 "-out", argv[1], "1024", NULL);
    if (openssl == NULL)
        return 2;
    GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
    GNUNET_OS_process_destroy (openssl);

    /* Create a self-signed certificate in batch mode using rsa key */
    /* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */
    openssl =
        GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "openssl", "openssl", "req",
                                 "-batch", "-days", "365", "-out", argv[2],
                                 "-new", "-x509", "-key", argv[1], NULL);
    if (openssl == NULL)
        return 3;
    GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
    GNUNET_OS_process_destroy (openssl);
    CHMOD (argv[1], S_IRUSR);
    CHMOD (argv[2], S_IRUSR);
    return 0;
}
static void
end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending phase %d, ok is %d\n", phase,
              ok);
  if (NULL != proc)
  {
    if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
    {
      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
    }
    GNUNET_OS_process_wait (proc);
    GNUNET_OS_process_destroy (proc);
    proc = NULL;
  }
  if (NULL != read_task)
  {
    GNUNET_SCHEDULER_cancel (read_task);
    read_task = NULL;
  }
  GNUNET_DISK_pipe_close (pipe_stdout);
  if (ok == 1)
  {
    if (phase < 9)
    {
      phase += 1;
      runone ();
    }
    else
      ok = 0;
  }
  else
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failing\n");
}
/**
 * Test killing via pipe.
 */
static int
check_instant_kill ()
{
  char *fn;
#if !WINDOWS
  GNUNET_asprintf (&fn, "cat");
#else
  GNUNET_asprintf (&fn, "w32cat");
#endif
  hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
  hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
  if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL))
  {
    GNUNET_free (fn);
    return 1;
  }
  proc =
    GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn,
			     "gnunet-service-resolver", "-", NULL); 
  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  }
  GNUNET_free (fn);
  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc));
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  GNUNET_DISK_pipe_close (hello_pipe_stdout);
  GNUNET_DISK_pipe_close (hello_pipe_stdin);
  return 0;
}
/**
 * Test killing via pipe.
 */
static int
check_instant_kill ()
{
  char *fn;

  hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
  hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
  if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL))
  {
    return 1;
  }
  fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
  proc =
    GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR,
                             hello_pipe_stdin, hello_pipe_stdout, NULL,
                             fn,
			     "gnunet-service-resolver", "-", NULL);
  if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  }
  GNUNET_free (fn);
  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc));
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  GNUNET_DISK_pipe_close (hello_pipe_stdout);
  GNUNET_DISK_pipe_close (hello_pipe_stdin);
  return 0;
}
/**
 * Shutdown nicely
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n");
  if (0 != abort_task)
  {
    GNUNET_SCHEDULER_cancel (abort_task);
  }
  if (NULL != t)
  {
    GNUNET_MESH_tunnel_destroy(t);
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: D1\n");
  if (NULL != mesh_peer_1)
  {
    GNUNET_MESH_disconnect (mesh_peer_1);
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: D2\n");
  if (NULL != mesh_peer_2)
  {
    GNUNET_MESH_disconnect (mesh_peer_2);
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
  if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
  GNUNET_OS_process_destroy (arm_pid);
}
/**
 * Shutdown nicely
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_STREAM_close (peer1.socket);
  if (NULL != peer2.socket)
    GNUNET_STREAM_close (peer2.socket);
  if (NULL != peer2_listen_socket)
    GNUNET_STREAM_listen_close (peer2_listen_socket);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n");
  if (0 != abort_task)
  {
    GNUNET_SCHEDULER_cancel (abort_task);
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
  if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
  /* Free the duplicated configuration */
  GNUNET_CONFIGURATION_destroy (config_peer1);
  GNUNET_CONFIGURATION_destroy (config_peer2);
  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
  GNUNET_OS_process_destroy (arm_pid);
}
Exemple #7
0
static int
check ()
{
  char *const argv[] = { "test-sensor-api", NULL };
  struct GNUNET_GETOPT_CommandLineOption options[] = {
    GNUNET_GETOPT_OPTION_END
  };
  struct GNUNET_OS_Process *proc;
  char *path = GNUNET_OS_get_libexec_binary_path ("gnunet-service-sensor");

  if (NULL == path)
  {
    fprintf (stderr, "Service executable not found `%s'\n",
             "gnunet-service-sensor");
    return -1;
  }

  proc =
      GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, NULL,
                               NULL, path, "gnunet-service-sensor", NULL);

  GNUNET_free (path);
  GNUNET_assert (NULL != proc);
  GNUNET_PROGRAM_run (1, argv, "test-sensor-api", "nohelp", options, &run, &ok);
  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
    ok = 1;
  }
  GNUNET_OS_process_wait (proc);
  GNUNET_OS_process_destroy (proc);
  return ok;
}
static void
stop_arm ()
{
  if (NULL != arm)
  {
    if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
    GNUNET_OS_process_wait (arm);
    GNUNET_OS_process_destroy (arm);
    arm = NULL;
  }
}
Exemple #9
0
/**
 * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
 *
 * @param handle the habitability check handle
 */
void
GNUNET_TESTBED_is_host_habitable_cancel (struct
                                         GNUNET_TESTBED_HostHabitableCheckHandle
                                         *handle)
{
  GNUNET_SCHEDULER_cancel (handle->habitability_check_task);
  (void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG);
  (void) GNUNET_OS_process_wait (handle->auxp);
  GNUNET_OS_process_destroy (handle->auxp);
  free_argv (handle->helper_argv);
  GNUNET_free (handle);
}
Exemple #10
0
int
main (int argc, char *const argv[])
{
  struct GNUNET_GETOPT_CommandLineOption options[] = {
      GNUNET_GETOPT_OPTION_END
  };
  char *const argv_prog[] = {
      "test-stun",
      "-c",
      "test_stun.conf",
      NULL
  };
  char *fn;
  struct GNUNET_OS_Process *proc;

  GNUNET_log_setup ("test-stun",
                    "WARNING",
                    NULL);

  /* Lets start resolver */
  fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
  proc = GNUNET_OS_start_process (GNUNET_YES,
                                  GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
                                  NULL, NULL, NULL,
                                  fn,
                                  "gnunet-service-resolver",
                                  "-c", "test_stun.conf", NULL);

  if (NULL == proc)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                "This test was unable to start gnunet-service-resolver, and it is required to run ...\n");
    exit(1);
  }

  GNUNET_PROGRAM_run (3, argv_prog,
                      "test-stun", "nohelp",
                      options,
                      &run, NULL);

  /* Now kill the resolver */
  if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  }
  GNUNET_OS_process_wait (proc);
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  GNUNET_free (fn);

  return ret;
}
Exemple #11
0
static void
end_task (void *cls)
{
  if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  }
  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc));
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  GNUNET_DISK_pipe_close (hello_pipe_stdout);
  GNUNET_DISK_pipe_close (hello_pipe_stdin);
}
static void
end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  }
  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc));
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  GNUNET_DISK_pipe_close (hello_pipe_stdout);
  GNUNET_DISK_pipe_close (hello_pipe_stdin);
}
static void
stop_arm (struct PeerContext *p)
{
  if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
              GNUNET_OS_process_get_pid (p->arm_proc));
  GNUNET_OS_process_destroy (p->arm_proc);
  p->arm_proc = NULL;
  GNUNET_CONFIGURATION_destroy (p->cfg);
}
Exemple #14
0
/**
 * Reap the helper process.  This call is blocking(!).  The helper process
 * should either be sent a termination signal before or should be dead before
 * calling this function
 *
 * @param h the helper handle
 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
 */
int
GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h)
{
  struct GNUNET_HELPER_SendHandle *sh;
  int ret;

  ret = GNUNET_SYSERR;
  if (NULL != h->helper_proc)
  {
    ret = GNUNET_OS_process_wait (h->helper_proc);
    GNUNET_OS_process_destroy (h->helper_proc);
    h->helper_proc = NULL;
  }
  if (NULL != h->read_task)
  {
    GNUNET_SCHEDULER_cancel (h->read_task);
    h->read_task = NULL;
  }
  if (NULL != h->write_task)
  {
    GNUNET_SCHEDULER_cancel (h->write_task);
    h->write_task = NULL;
  }
  if (NULL != h->helper_in)
  {
    GNUNET_DISK_pipe_close (h->helper_in);
    h->helper_in = NULL;
    h->fh_to_helper = NULL;
  }
  if (NULL != h->helper_out)
  {
    GNUNET_DISK_pipe_close (h->helper_out);
    h->helper_out = NULL;
    h->fh_from_helper = NULL;
  }
  while (NULL != (sh = h->sh_head))
  {
    GNUNET_CONTAINER_DLL_remove (h->sh_head,
				 h->sh_tail,
				 sh);
    if (NULL != sh->cont)
      sh->cont (sh->cont_cls, GNUNET_NO);
    GNUNET_free (sh);
  }
  /* purge MST buffer */
  if (NULL != h->mst)
    (void) GNUNET_SERVER_mst_receive (h->mst, NULL, NULL, 0, GNUNET_YES, GNUNET_NO);
  return ret;
}
static void
waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct PeerContext *p = cls;

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n");
  if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
              GNUNET_OS_process_get_pid (p->arm_proc));
  GNUNET_OS_process_destroy (p->arm_proc);
  p->arm_proc = NULL;
  GNUNET_CONFIGURATION_destroy (p->cfg);
}
static void
gather_log_data ()
{
  char *peer_number;
  char *connect_number;
  struct GNUNET_OS_Process *mem_process;

  GNUNET_asprintf (&peer_number, "%llu", num_peers);
  GNUNET_asprintf (&connect_number, "%llu", expected_connections);
  mem_process =
      GNUNET_OS_start_process (NULL, NULL, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, "./memsize.pl", "memsize.pl",
                               "totals.txt", peer_number, connect_number, NULL);
  GNUNET_OS_process_wait (mem_process);
  GNUNET_OS_process_destroy (mem_process);
  mem_process = NULL;
}
static int
check ()
{
  struct GNUNET_OS_Process *proc;
  char cfg_name[128];

  char *const argv[] = {
    "test-datastore-api-management",
    "-c",
    cfg_name,
#if VERBOSE
    "-L", "DEBUG",
#endif
    NULL
  };
  struct GNUNET_GETOPT_CommandLineOption options[] = {
    GNUNET_GETOPT_OPTION_END
  };
  GNUNET_snprintf (cfg_name, sizeof (cfg_name),
                   "test_datastore_api_data_%s.conf", plugin_name);
  proc =
    GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
                               "gnunet-service-arm",
#if VERBOSE
                               "-L", "DEBUG",
#endif
                               "-c", cfg_name, NULL);
  GNUNET_assert (NULL != proc);
  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
                      "test-datastore-api-management", "nohelp", options, &run,
                      NULL);
  sleep (1);                    /* give datastore chance to process 'DROP' request */
  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
    ok = 1;
  }
  GNUNET_OS_process_wait (proc);
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  if (ok != 0)
    FPRINTF (stderr, "Missed some testcases: %u\n", ok);
  return ok;
}
int
main (int argc, char *argv_ign[])
{
  char *const argv[] = { "test-statistics-api",
    "-c",
    "test_statistics_api_data.conf",
    NULL
  };
  struct GNUNET_GETOPT_CommandLineOption options[] = {
    GNUNET_GETOPT_OPTION_END
  };
  struct GNUNET_OS_Process *proc;
  char *binary;

  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
  proc =
    GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL,
			     binary,
			     "gnunet-service-statistics",
			     "-c", "test_statistics_api_data.conf", NULL);
  GNUNET_assert (NULL != proc);
  ok = 3;
  ok2 = 1;
  GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run,
                      NULL);
  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
    ok = 1;
  }
  GNUNET_OS_process_wait (proc);
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  GNUNET_free (binary);
  if ((0 == ok) && (0 == ok2))
    return 0;
  return 1;
}
/**
 * Test killing via pipe.
 */
static int
check_instant_kill ()
{
  hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
  hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
  if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL))
  {
    return 1;
  }
  proc =
    GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, "cat",
			     "gnunet-service-resolver", "-", NULL); 
  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  }
  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc));
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  GNUNET_DISK_pipe_close (hello_pipe_stdout);
  GNUNET_DISK_pipe_close (hello_pipe_stdin);
  return 0;
}
Exemple #20
0
static void
do_shutdown ()
{
  if (mhd_task_id != NULL)
  {
    GNUNET_SCHEDULER_cancel (mhd_task_id);
    mhd_task_id = NULL;
  }
  if (curl_task_id != NULL)
  {
    GNUNET_SCHEDULER_cancel (curl_task_id);
    curl_task_id = NULL;
  }
  if (NULL != mhd)
  {
    MHD_stop_daemon (mhd);
    mhd = NULL;
  }
  GNUNET_free_non_null (url);

  if (NULL != tmp_cfgfile)
    {
      if (0 != remove (tmp_cfgfile))
	GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "remove", tmp_cfgfile);
      GNUNET_free (tmp_cfgfile);
      tmp_cfgfile = NULL;
    }
  if (NULL != proxy_proc)
    {
      (void) GNUNET_OS_process_kill (proxy_proc, SIGKILL);
      GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proxy_proc));
      GNUNET_OS_process_destroy (proxy_proc);
      proxy_proc = NULL;
    }
  url = NULL;
  GNUNET_SCHEDULER_shutdown ();
}
/**
 * Shutdown nicely
 *
 * @param cls
 * @param tc the task context
 */
static void
do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
    {
      GNUNET_SCHEDULER_cancel (abort_task_id);
      abort_task_id = GNUNET_SCHEDULER_NO_TASK;
    }
  if (NULL != request)
    GNUNET_LOCKMANAGER_cancel_request (request);
  if (NULL != request2)
    GNUNET_LOCKMANAGER_cancel_request (request2);
  GNUNET_LOCKMANAGER_disconnect (handle);
  if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
    {
      LOG (GNUNET_ERROR_TYPE_DEBUG,
           "Kill gnunet-service-arm manually\n");
    }
  GNUNET_OS_process_wait (arm_pid);
  GNUNET_OS_process_destroy (arm_pid);

  if (NULL != config)
    GNUNET_CONFIGURATION_destroy (config);
}
static void
shutdown_testcase ()
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown testcase....\n");
  if (timeout_task != NULL)
  {
    GNUNET_SCHEDULER_cancel (timeout_task);
    timeout_task = NULL;
  }
  if (NULL != download_stats)
  {
    GNUNET_STATISTICS_get_cancel (download_stats);
    download_stats = NULL;
  }
  if (NULL != urisrecv_stat)
  {
    GNUNET_STATISTICS_get_cancel (urisrecv_stat);
    urisrecv_stat = NULL;
  }
  if (NULL != advsent_stat)
  {
    GNUNET_STATISTICS_get_cancel (advsent_stat);
    advsent_stat = NULL;
  }
  if (NULL != adv_peer.stats)
  {
    GNUNET_STATISTICS_destroy (adv_peer.stats, GNUNET_NO);
    adv_peer.stats = NULL;
  }
  if (NULL != learn_peer.stats)
  {
    GNUNET_STATISTICS_destroy (learn_peer.stats, GNUNET_NO);
    learn_peer.stats = NULL;
  }
  if (check_task != NULL)
  {
    GNUNET_SCHEDULER_cancel (check_task);
    check_task = NULL;
  }
  if (NULL != current_adv_uri)
  {
    GNUNET_free (current_adv_uri);
    current_adv_uri = NULL;
  }
  if (adv_peer.th != NULL)
  {
    GNUNET_TRANSPORT_disconnect (adv_peer.th);
    adv_peer.th = NULL;
  }
  if (learn_peer.th != NULL)
  {
    GNUNET_TRANSPORT_disconnect (learn_peer.th);
    learn_peer.th = NULL;
  }
  if (adv_peer.core != NULL)
  {
    GNUNET_CORE_disconnect (adv_peer.core);
    adv_peer.core = NULL;
  }
  if (learn_peer.core != NULL)
  {
    GNUNET_CORE_disconnect (learn_peer.core);
    learn_peer.core = NULL;
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Killing hostlist server ARM process.\n");
  if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, GNUNET_TERM_SIG))
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  if (GNUNET_OS_process_wait (adv_peer.arm_proc) != GNUNET_OK)
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
  GNUNET_OS_process_destroy (adv_peer.arm_proc);
  adv_peer.arm_proc = NULL;
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Killing hostlist client ARM process.\n");
  if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, GNUNET_TERM_SIG))
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  if (GNUNET_OS_process_wait (learn_peer.arm_proc) != GNUNET_OK)
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
  GNUNET_OS_process_destroy (learn_peer.arm_proc);
  learn_peer.arm_proc = NULL;
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown complete....\n");
}
int
main (int argc, char *argv_ign[])
{
  int ok = 1;

  char *const argv[] = { "test-statistics-api",
    "-c",
    "test_statistics_api_data.conf",
    "-L", "WARNING",
    NULL
  };
  struct GNUNET_GETOPT_CommandLineOption options[] = {
    GNUNET_GETOPT_OPTION_END
  };
  struct GNUNET_OS_Process *proc;
  char *binary;

  GNUNET_log_setup ("test_statistics_api",
                    "WARNING",
                    NULL);
  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
  proc =
      GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, 
			       binary,
                               "gnunet-service-statistics",
                               "-c", "test_statistics_api_data.conf", NULL);
  GNUNET_assert (NULL != proc);
  GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run,
                      &ok);
  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
    ok = 1;
  }
  GNUNET_OS_process_wait (proc);
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  if (ok != 0)
  {
    GNUNET_free (binary);
    return ok;
  }
  ok = 1;
  /* restart to check persistence! */
  proc =
      GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, 
			       binary,
                               "gnunet-service-statistics",
                               "-c", "test_statistics_api_data.conf", NULL);
  GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options,
                      &run_more, &ok);
  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
  {
    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
    ok = 1;
  }
  GNUNET_OS_process_wait (proc);
  GNUNET_OS_process_destroy (proc);
  proc = NULL;
  GNUNET_free (binary);
  return ok;
}