summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-10-04 18:08:34 +0200
committerFlorian Dold <florian@dold.me>2021-10-04 18:08:34 +0200
commit61ea83cbc019db5c000baf4debf873be59528e63 (patch)
tree7525d1329423659983e764b5571f23a5537500a2
parenta4b3524111d176d7374db1340f0d996eecfadff1 (diff)
downloadanastasis-61ea83cbc019db5c000baf4debf873be59528e63.tar.gz
anastasis-61ea83cbc019db5c000baf4debf873be59528e63.tar.bz2
anastasis-61ea83cbc019db5c000baf4debf873be59528e63.zip
report reducer error instead of crashing
-rw-r--r--src/reducer/anastasis_api_redux.c61
1 files changed, 55 insertions, 6 deletions
diff --git a/src/reducer/anastasis_api_redux.c b/src/reducer/anastasis_api_redux.c
index 796e60d..92801f4 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -1491,6 +1491,31 @@ dummy_cleanup (void *cls)
/**
+ * Closure for external_redux_done.
+ */
+struct ExternalReduxCls
+{
+ ANASTASIS_ActionCallback cb;
+ void *cb_cls;
+ json_t *new_state;
+};
+
+
+/**
+ * Callback called when the redux action has been processed by
+ * the external reducer.
+ */
+static void
+external_redux_done (void *cls)
+{
+ struct ExternalReduxCls *erc = cls;
+ erc->cb (erc->cb_cls,
+ TALER_EC_NONE,
+ erc->new_state);
+}
+
+
+/**
* Handle an action using an external reducer, i.e.
* by shelling out to another process.
*/
@@ -1563,9 +1588,26 @@ redux_action_external (const char *ext_reducer,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Wrote old state to reducer stdin.\n");
- next_state = json_loadf (reducer_stdout,
- 0,
- NULL);
+ {
+ json_error_t err;
+
+ next_state = json_loadf (reducer_stdout,
+ 0,
+ &err);
+
+ if (NULL == next_state)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "External reducer did not output valid JSON: %s:%d:%d %s\n",
+ err.source,
+ err.line,
+ err.column,
+ err.text);
+ GNUNET_assert (0 == fclose (reducer_stdout));
+ waitpid (pid, &status, 0);
+ return NULL;
+ }
+ }
/* FIXME: report error instead! */
GNUNET_assert (NULL != next_state);
@@ -1584,9 +1626,16 @@ redux_action_external (const char *ext_reducer,
/* Callback is called immediately, cleanup must never be called */
act->cleanup = &dummy_cleanup;
- cb (cb_cls,
- TALER_EC_NONE,
- next_state);
+ {
+ struct ExternalReduxCls *sched_cls = GNUNET_new (struct ExternalReduxCls);
+
+ sched_cls->cb = cb;
+ sched_cls->cb_cls = cb_cls;
+ sched_cls->new_state = next_state;
+ GNUNET_SCHEDULER_add_now (external_redux_done,
+ sched_cls);
+ }
+
return act;
}