* @param tc unused
*/
static void
-start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+start_fsm (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TESTING_Daemon *d = cls;
GNUNET_TESTING_NotifyDaemonRunning cb;
unsigned long code;
char *dst;
int bytes_read;
- static char hostkeybuf[105];
- static const char temphostkey[104];
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
#endif
d->phase = SP_HOSTKEY_CREATE;
d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
+ = GNUNET_SCHEDULER_add_read_file (d->sched,
+ GNUNET_TIME_absolute_get_remaining(d->max_timeout),
+ GNUNET_DISK_pipe_handle(d->pipe_stdout,
+ GNUNET_DISK_PIPE_END_READ),
+ &start_fsm,
+ d);
break;
case SP_HOSTKEY_CREATE:
-
- bytes_read = GNUNET_DISK_file_read(GNUNET_DISK_pipe_handle(d->pipe_stdout, GNUNET_DISK_PIPE_END_READ), &hostkeybuf, sizeof(hostkeybuf));
- if (bytes_read == 104) /* Success, we have read in the hostkey */
- {
- if (hostkeybuf[103] == '\n')
- hostkeybuf[103] = '\0';
- else
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Malformed output from gnunet-peerinfo!\n");
- memcpy(&temphostkey, &hostkeybuf, bytes_read);
-
- if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (&temphostkey[0],
- &d->id.hashPubKey))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to peer identity!\n");
- }
- else
- {
- GNUNET_DISK_pipe_close(d->pipe_stdout);
- d->pipe_stdout = NULL;
- }
- }
-
- if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
- {
- if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("`gnunet-peerinfo' does not seem to terminate.\n")
- : _("`ssh' does not seem to terminate.\n"));
-
- GNUNET_DISK_pipe_close(d->pipe_stdout);
- return;
- }
- /* wait some more */
+ bytes_read = GNUNET_DISK_file_read(GNUNET_DISK_pipe_handle(d->pipe_stdout,
+ GNUNET_DISK_PIPE_END_READ),
+ &d->hostkeybuf[d->hostkeybufpos],
+ sizeof(d->hostkeybuf) - d->hostkeybufpos);
+ if (bytes_read > 0)
+ d->hostkeybufpos += bytes_read;
+
+ if ( (d->hostkeybufpos < 104) &&
+ (bytes_read > 0) )
+ {
+ /* keep reading */
d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
+ = GNUNET_SCHEDULER_add_read_file (d->sched,
+ GNUNET_TIME_absolute_get_remaining(d->max_timeout),
+ GNUNET_DISK_pipe_handle(d->pipe_stdout,
+ GNUNET_DISK_PIPE_END_READ),
+ &start_fsm,
+ d);
return;
- }
-#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully got hostkey!\n");
-#endif
- if (d->pipe_stdout != NULL)
- {
+ }
+ d->hostkeybuf[103] = '\0';
+ if ( (bytes_read < 0) ||
+ (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
+ &d->id.hashPubKey)) )
+ {
+ /* error */
+ if (bytes_read < 0)
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+ _("Error reading from gnunet-peerinfo: %s\n"),
+ STRERROR (errno));
+ else
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+ _("Malformed output from gnunet-peerinfo!\n"));
cb = d->cb;
d->cb = NULL;
+ GNUNET_DISK_pipe_close(d->pipe_stdout);
+ d->pipe_stdout = NULL;
+ (void) PLIBC_KILL (d->pid, SIGKILL);
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->pid));
+ d->pid = 0;
if (NULL != cb)
cb (d->cb_cls,
NULL,
d->cfg,
d,
_("`Failed to get hostkey!\n"));
- GNUNET_DISK_pipe_close(d->pipe_stdout);
- return;
- }
-
+ return;
+ }
+ GNUNET_DISK_pipe_close(d->pipe_stdout);
+ d->pipe_stdout = NULL;
+ (void) PLIBC_KILL (d->pid, SIGKILL);
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->pid));
+ d->pid = 0;
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully got hostkey!\n");
+#endif
if (d->hostkey_callback != NULL)
{
d->hostkey_callback(d->hostkey_cls, &d->id, d, NULL);
{
d->phase = SP_TOPOLOGY_SETUP;
}
-
/* Fall through */
case SP_HOSTKEY_CREATED:
/* wait for topology finished */
GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
- int delete_files, int allow_restart)
+ int delete_files,
+ int allow_restart)
{
char *arg;
char *del_arg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
#endif
-
d->phase = SP_SHUTDOWN_START;
d->running = GNUNET_NO;
-
if (allow_restart == GNUNET_YES)
d->churn = GNUNET_YES;
-
if (d->th != NULL)
{
GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d);
#endif
"-c", d->cfgfile, "-e", "-q", del_arg, NULL);
/* Use -e to end arm, and -d to remove temp files */
-
GNUNET_free (arg);
}
else