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; }
/** * 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; }
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"); }
/** * 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); }
/** * Task triggered whenever we receive a SIGCHLD (child * process died). * * @param cls closure, NULL if we need to self-restart * @param tc context */ static void child_death_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { const struct GNUNET_DISK_FileHandle *pr; char c[16]; pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); child_death_task_id = NULL; if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) { child_death_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, &child_death_task, NULL); return; } /* consume the signal */ GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); LOG_DEBUG ("Child died\n"); GNUNET_SCHEDULER_cancel (terminate_task_id); terminate_task_id = NULL; GNUNET_assert (GNUNET_OK == GNUNET_OS_process_status (child, &child_status, &child_exit_code)); GNUNET_OS_process_destroy (child); child = NULL; shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); }
/** * 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; }
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; }
/** * Display the result of the test. * * @param tc test context * @param result GNUNET_YES on success */ static void display_test_result (struct TestContext *tc, int result) { if (GNUNET_YES != result) { FPRINTF (stderr, "Configuration for plugin `%s' did not work!\n", tc->name); } else { FPRINTF (stderr, "Configuration for plugin `%s' is working!\n", tc->name); } if (GNUNET_SCHEDULER_NO_TASK != tc->tsk) { GNUNET_SCHEDULER_cancel (tc->tsk); tc->tsk = GNUNET_SCHEDULER_NO_TASK; } if (NULL != tc->tst) { GNUNET_NAT_test_stop (tc->tst); tc->tst = NULL; } GNUNET_free (tc); resolver_users--; if ((0 == resolver_users) && (NULL != resolver)) { GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM)); GNUNET_OS_process_destroy (resolver); resolver = NULL; } }
/** * 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); }
/** * Task triggered whenever we receive a SIGCHLD (child * process died) or when user presses CTRL-C. * * @param cls closure, NULL * @param tc scheduler context */ static void maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { enum GNUNET_OS_ProcessStatusType type; if ( (GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) || (type != GNUNET_OS_PROCESS_EXITED) ) GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); GNUNET_OS_process_destroy (p); }
/** * Task for checking whether a host is habitable or not * * @param cls GNUNET_TESTBED_HostHabitableCheckHandle * @param tc the scheduler task context */ static void habitability_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls; void *cb_cls; GNUNET_TESTBED_HostHabitableCallback cb; const struct GNUNET_TESTBED_Host *host; unsigned long code; enum GNUNET_OS_ProcessStatusType type; int ret; h->habitability_check_task = NULL; ret = GNUNET_OS_process_status (h->auxp, &type, &code); if (GNUNET_SYSERR == ret) { GNUNET_break (0); ret = GNUNET_NO; goto call_cb; } if (GNUNET_NO == ret) { h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); h->habitability_check_task = GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); return; } GNUNET_OS_process_destroy (h->auxp); h->auxp = NULL; ret = (0 != code) ? GNUNET_NO : GNUNET_YES; call_cb: if (NULL != h->auxp) GNUNET_OS_process_destroy (h->auxp); cb = h->cb; cb_cls = h->cb_cls; host = h->host; free_argv (h->helper_argv); GNUNET_free (h); if (NULL != cb) cb (cb_cls, host, ret); }
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; } }
/** * 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); }
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; }
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); }
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 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); }
/** * 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; }
/** * Cancel operation. * * @param eh operation to cancel */ void GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh) { if (NULL != eh->eip) { (void) GNUNET_OS_process_kill (eh->eip, SIGKILL); GNUNET_OS_process_destroy (eh->eip); } if (NULL != eh->opipe) { GNUNET_DISK_pipe_close (eh->opipe); eh->opipe = NULL; } if (NULL != eh->task) { GNUNET_SCHEDULER_cancel (eh->task); eh->task = NULL; } GNUNET_free (eh); }
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; }
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); }
/** * Task triggered whenever we receive a SIGCHLD (child * process died). * * @param cls closure, NULL if we need to self-restart * @param tc context */ static void maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ServiceList *pos; struct ServiceList *next; struct ServiceListeningInfo *sli; const char *statstr; int statcode; int ret; char c[16]; enum GNUNET_OS_ProcessStatusType statusType; unsigned long statusCode; const struct GNUNET_DISK_FileHandle *pr; pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); child_death_task = GNUNET_SCHEDULER_NO_TASK; if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) { /* shutdown scheduled us, ignore! */ child_death_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, &maint_child_death, NULL); return; } /* consume the signal */ GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); /* check for services that died (WAITPID) */ next = running_head; while (NULL != (pos = next)) { next = pos->next; if (pos->proc == NULL) { if (GNUNET_YES == in_shutdown) free_service (pos); continue; } if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc, &statusType, &statusCode))) || ((ret == GNUNET_NO) || (statusType == GNUNET_OS_PROCESS_STOPPED) || (statusType == GNUNET_OS_PROCESS_RUNNING))) continue; if (statusType == GNUNET_OS_PROCESS_EXITED) { statstr = _( /* process termination method */ "exit"); statcode = statusCode; } else if (statusType == GNUNET_OS_PROCESS_SIGNALED) { statstr = _( /* process termination method */ "signal"); statcode = statusCode; } else { statstr = _( /* process termination method */ "unknown"); statcode = 0; } if (0 != pos->killed_at.abs_value) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Service `%s' took %llu ms to terminate\n"), pos->name, GNUNET_TIME_absolute_get_duration (pos->killed_at).rel_value); } GNUNET_OS_process_destroy (pos->proc); pos->proc = NULL; if (NULL != pos->killing_client) { signal_result (pos->killing_client, pos->name, GNUNET_ARM_PROCESS_DOWN); GNUNET_SERVER_client_drop (pos->killing_client); pos->killing_client = NULL; /* process can still be re-started on-demand, ensure it is re-started if there is demand */ for (sli = pos->listen_head; NULL != sli; sli = sli->next) { GNUNET_break (GNUNET_SCHEDULER_NO_TASK == sli->accept_task); sli->accept_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sli->listen_socket, &accept_connection, sli); } continue; } if (GNUNET_YES != in_shutdown) { if ((statusType == GNUNET_OS_PROCESS_EXITED) && (statcode == 0)) { /* process terminated normally, allow restart at any time */ pos->restart_at.abs_value = 0; } else { if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Service `%s' terminated with status %s/%d, will restart in %llu ms\n"), pos->name, statstr, statcode, pos->backoff.rel_value); /* schedule restart */ pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff); pos->backoff = GNUNET_TIME_relative_min (EXPONENTIAL_BACKOFF_THRESHOLD, GNUNET_TIME_relative_multiply (pos->backoff, 2)); } if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) GNUNET_SCHEDULER_cancel (child_restart_task); child_restart_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &delayed_restart_task, NULL); } else { free_service (pos); } } child_death_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, &maint_child_death, NULL); if ((NULL == running_head) && (GNUNET_YES == in_shutdown)) do_shutdown (); }
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[]) { #if START_DAEMON struct GNUNET_OS_Process *daemon; #endif int ok; struct GNUNET_ECRS_URI *uri; char *filename = NULL; char *keywords[] = { "fsui_foo", "fsui_bar", }; char keyword[40]; char *fn; int prog; struct GNUNET_MetaData *meta; struct GNUNET_ECRS_URI *kuri; struct GNUNET_GC_Configuration *cfg; struct GNUNET_FSUI_UploadList *upload = NULL; struct GNUNET_FSUI_SearchList *search = NULL; struct GNUNET_FSUI_UnindexList *unindex = NULL; struct GNUNET_FSUI_DownloadList *download = NULL; cfg = GNUNET_GC_create (); if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) { GNUNET_GC_free (cfg); return -1; } #if START_DAEMON daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); GNUNET_GE_ASSERT (NULL, daemon != NULL); CHECK (GNUNET_OK == GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS)); #endif GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ ok = GNUNET_YES; /* ACTUAL TEST CODE */ ctx = GNUNET_FSUI_start (NULL, cfg, "basic_fsui_test", 32, /* thread pool size */ GNUNET_NO, /* no resume */ &eventCallback, NULL); CHECK (ctx != NULL); filename = makeName (42); GNUNET_disk_file_write (NULL, filename, "foo bar test!", strlen ("foo bar test!"), "600"); meta = GNUNET_meta_data_create (); kuri = GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2, (const char **) keywords); /* upload */ upload = GNUNET_FSUI_upload_start (ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ 0, /* priority */ GNUNET_YES, GNUNET_NO, GNUNET_NO, GNUNET_get_time () + 5 * GNUNET_CRON_HOURS, meta, kuri, kuri); CHECK (upload != NULL); GNUNET_ECRS_uri_destroy (kuri); GNUNET_meta_data_destroy (meta); prog = 0; while (lastEvent != GNUNET_FSUI_upload_completed) { prog++; CHECK (prog < 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); if (GNUNET_shutdown_test () == GNUNET_YES) break; } /* search */ GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]); uri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword); search = GNUNET_FSUI_search_start (ctx, 0, uri); GNUNET_ECRS_uri_destroy (uri); CHECK (search != NULL); prog = 0; while (lastEvent != GNUNET_FSUI_search_result) { prog++; CHECK (prog < 10000); GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); if (GNUNET_shutdown_test () == GNUNET_YES) break; } GNUNET_FSUI_search_abort (search); GNUNET_FSUI_search_stop (search); /* download */ fn = makeName (43); download = GNUNET_FSUI_download_start (ctx, 0, GNUNET_NO, search_uri, search_meta, fn, NULL, NULL); GNUNET_free (fn); prog = 0; while (lastEvent != GNUNET_FSUI_download_completed) { prog++; CHECK (prog < 10000); GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); if (GNUNET_shutdown_test () == GNUNET_YES) break; } GNUNET_FSUI_download_stop (download); download = NULL; GNUNET_ECRS_uri_destroy (search_uri); GNUNET_meta_data_destroy (search_meta); /* unindex */ unindex = GNUNET_FSUI_unindex_start (ctx, filename); prog = 0; while (lastEvent != GNUNET_FSUI_unindex_completed) { prog++; CHECK (prog < 10000); GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); if (GNUNET_shutdown_test () == GNUNET_YES) break; } if (lastEvent != GNUNET_FSUI_unindex_completed) GNUNET_FSUI_unindex_abort (unindex); GNUNET_FSUI_unindex_stop (unindex); /* END OF TEST CODE */ FAILURE: if (ctx != NULL) GNUNET_FSUI_stop (ctx); if (filename != NULL) { UNLINK (filename); GNUNET_free (filename); } if (download != NULL) { GNUNET_FSUI_download_abort (download); GNUNET_FSUI_download_stop (download); } filename = makeName (43); /* TODO: verify file 'filename(42)' == file 'filename(43)' */ UNLINK (filename); GNUNET_free (filename); #if START_DAEMON GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); GNUNET_OS_process_destroy (daemon); #endif GNUNET_GC_free (cfg); return (ok == GNUNET_YES) ? 0 : 1; }
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; }