aboutsummaryrefslogtreecommitdiff
path: root/src/reducer/anastasis_api_recovery_redux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reducer/anastasis_api_recovery_redux.c')
-rw-r--r--src/reducer/anastasis_api_recovery_redux.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/reducer/anastasis_api_recovery_redux.c b/src/reducer/anastasis_api_recovery_redux.c
index 59f5ae3..94e5e10 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -83,6 +83,68 @@ json_t *
83ANASTASIS_recovery_start (const struct GNUNET_CONFIGURATION_Handle *cfg) 83ANASTASIS_recovery_start (const struct GNUNET_CONFIGURATION_Handle *cfg)
84{ 84{
85 json_t *initial_state; 85 json_t *initial_state;
86 const char *external_reducer = ANASTASIS_REDUX_probe_external_reducer ();
87
88 if (NULL != external_reducer)
89 {
90 int pipefd_stdout[2];
91 pid_t pid = 0;
92 int status;
93 FILE *reducer_stdout;
94
95 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
96 "Using external reducer '%s' for recovery start status\n",
97 external_reducer);
98
99 GNUNET_assert (0 == pipe (pipefd_stdout));
100 pid = fork ();
101 if (pid == 0)
102 {
103 close (pipefd_stdout[0]);
104 dup2 (pipefd_stdout[1], STDOUT_FILENO);
105 execlp (external_reducer,
106 external_reducer,
107 "-r",
108 NULL);
109 GNUNET_assert (0);
110 }
111
112 close (pipefd_stdout[1]);
113 reducer_stdout = fdopen (pipefd_stdout[0],
114 "r");
115 {
116 json_error_t err;
117
118 initial_state = json_loadf (reducer_stdout,
119 0,
120 &err);
121
122 if (NULL == initial_state)
123 {
124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
125 "External reducer did not output valid JSON: %s:%d:%d %s\n",
126 err.source,
127 err.line,
128 err.column,
129 err.text);
130 GNUNET_assert (0 == fclose (reducer_stdout));
131 waitpid (pid, &status, 0);
132 return NULL;
133 }
134 }
135
136 GNUNET_assert (NULL != initial_state);
137 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
138 "Waiting for external reducer to terminate.\n");
139 GNUNET_assert (0 == fclose (reducer_stdout));
140 reducer_stdout = NULL;
141 waitpid (pid, &status, 0);
142
143 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
144 "External reducer finished with exit status '%d'\n",
145 status);
146 return initial_state;
147 }
86 148
87 (void) cfg; 149 (void) cfg;
88 initial_state = ANASTASIS_REDUX_load_continents_ (); 150 initial_state = ANASTASIS_REDUX_load_continents_ ();