- d->proc_arm_start =
- GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", "-p",
- d->ssh_port_str,
- "-q",
- dst, "gnunet-arm",
- "-c", d->cfgfile, "-s", "-q", "-T",
- GNUNET_TIME_relative_to_string
- (GNUNET_TIME_absolute_get_remaining
- (d->max_timeout)), NULL);
- }
- GNUNET_free (dst);
- }
- if (NULL == d->proc_arm_start)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start `%s' process to start GNUnet.\n"),
- (NULL == d->hostname) ? "gnunet-arm" : "ssh");
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls, NULL, d->cfg, d,
- (NULL ==
- d->hostname) ? _("Failed to start `gnunet-arm' process.\n") :
- _("Failed to start `ssh' process.\n"));
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Started `%s', waiting for `%s' to be up.\n", "gnunet-arm",
- "gnunet-service-core");
- d->phase = SP_START_ARMING;
- d->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
- d);
- // FIXME: busy wait?
- break;
- case SP_START_ARMING:
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc_arm_start, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls, NULL, d->cfg, d,
- (NULL ==
- d->hostname) ? _("`gnunet-arm' does not seem to terminate.\n") :
- _("`ssh' does not seem to terminate.\n"));
- if (d->cfg != NULL)
- {
- GNUNET_CONFIGURATION_destroy (d->cfg);
- d->cfg = NULL;
- }
- if (d->cfgfile != NULL)
- {
- GNUNET_free (d->cfgfile);
- d->cfgfile = NULL;
- }
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_OS_process_destroy (d->proc_arm_start);
- d->proc_arm_start = NULL;
- d->username = NULL;
- d->hostname = NULL; // Quick hack to avoid crashing (testing need to be
- d->cfg = NULL; // overhauled anyway, and the error managing is
- // GNUNET_free (d); // FIXME (could this leak)
- // pretty broken anyway.
- return;
- }
- /* wait some more */
- d->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
- d);
- // FIXME: busy wait?
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully started `%s'.\n",
- "gnunet-arm");
- GNUNET_OS_process_destroy (d->proc_arm_start);
- d->proc_arm_start = NULL;
- d->phase = SP_START_CORE;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling CORE_connect\n");
- /* Fall through */
- case SP_START_CORE:
- if (d->server != NULL)
- GNUNET_CORE_disconnect (d->server);
-
- d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
- if (d->th == NULL)
- {
- if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d,
- GNUNET_TIME_absolute_get_remaining
- (d->max_timeout), d->dead_cb,
- d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
- else if (NULL != d->cb)
- d->cb (d->cb_cls, &d->id, d->cfg, d,
- _("Failed to connect to transport service!\n"));
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to transport service `%s', getting HELLO\n",
- GNUNET_i2s (&d->id));
- d->ghh = GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
- /* FIXME: store task ID somewhere! */
- GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d);
- /*cb = d->cb;
- * d->cb = NULL;
- * if (NULL != cb)
- * cb (d->cb_cls, &d->id, d->cfg, d, NULL); */
- d->running = GNUNET_YES;
- d->phase = SP_GET_HELLO;
- break;
- case SP_GET_HELLO:
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
- {
- if (d->server != NULL)
- GNUNET_CORE_disconnect (d->server);
- if (d->th != NULL)
- GNUNET_TRANSPORT_disconnect (d->th);
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls, NULL, d->cfg, d, _("Unable to get HELLO for peer!\n"));
- GNUNET_CONFIGURATION_destroy (d->cfg);
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free (d);
- return;
- }
- if (d->hello != NULL)
- return;
- GNUNET_assert (d->task == GNUNET_SCHEDULER_NO_TASK);
- d->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_CONSTANTS_SERVICE_RETRY, 2),
- &start_fsm, d);
- break;
- case SP_START_DONE:
- GNUNET_break (0);
- break;
- case SP_SERVICE_START:
- /* confirm gnunet-arm exited */
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc_arm_srv_start, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls, NULL, d->cfg, d,
- (NULL ==
- d->hostname) ? _("`gnunet-arm' does not seem to terminate.\n") :
- _("`ssh' does not seem to terminate.\n"));
- return;
- }
- /* wait some more */
- d->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
- d);
- return;
- }
-#if EXTRA_CHECKS
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls, NULL, d->cfg, d,
- (NULL ==
- d->hostname) ?
- _
- ("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n")
- : _("`ssh' does not seem to terminate.\n"));
- return;
- }
-#endif
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n");
- cb = d->cb;
- d->cb = NULL;
- d->phase = SP_START_DONE;
- if (NULL != cb)
- cb (d->cb_cls, &d->id, d->cfg, d, NULL);
- GNUNET_OS_process_destroy (d->proc_arm_srv_start);
- d->proc_arm_srv_start = NULL;
- break;
- case SP_SERVICE_SHUTDOWN_START:
- /* confirm copying complete */
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc_arm_srv_stop, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _
- ("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
- return;
- }
- /* wait some more */
- d->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
- d);
- return;
- }
-#if EXTRA_CHECKS
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _
- ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n"));
- return;
- }
-#endif
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls, NULL);
- break;
- case SP_SHUTDOWN_START:
- /* confirm copying complete !??? */
- if (GNUNET_OK != GNUNET_OS_process_status (d->proc_arm_stop, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _
- ("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
- if (d->th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (d->ghh);
- d->ghh = NULL;
- GNUNET_TRANSPORT_disconnect (d->th);
- d->th = NULL;
- }
- if (d->cfg != NULL)
- {
- GNUNET_CONFIGURATION_destroy (d->cfg);
- d->cfg = NULL;
- }
- if (d->cfgfile != NULL)
- {
- GNUNET_free (d->cfgfile);
- d->cfgfile = NULL;
- }
- GNUNET_free_non_null (d->hello);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free_non_null (d->shortname);
- GNUNET_OS_process_destroy (d->proc_arm_stop);
- d->proc_arm_stop = NULL;
- GNUNET_free (d);
- return;
- }
- /* wait some more */
- d->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
- d);
- return;
- }
- if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _
- ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n"));
- if (d->th != NULL)
- {
- GNUNET_TRANSPORT_get_hello_cancel (d->ghh);
- d->ghh = NULL;
- GNUNET_TRANSPORT_disconnect (d->th);
- d->th = NULL;
- }
- if (d->server != NULL)
- {
- GNUNET_CORE_disconnect (d->server);
- d->server = NULL;
- }
- GNUNET_CONFIGURATION_destroy (d->cfg);
- d->cfg = NULL;
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hello);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free_non_null (d->shortname);
- GNUNET_OS_process_destroy (d->proc_arm_stop);
- d->proc_arm_stop = NULL;
- GNUNET_free (d);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
- if (d->server != NULL)
- {
- GNUNET_CORE_disconnect (d->server);
- d->server = NULL;
- }