diff --git a/src/common/libsubprocess/subprocess.c b/src/common/libsubprocess/subprocess.c index 01a5d5eba27d..798027342bfa 100644 --- a/src/common/libsubprocess/subprocess.c +++ b/src/common/libsubprocess/subprocess.c @@ -35,10 +35,10 @@ #include #include #include +#include #include "src/common/libutil/log.h" #include "src/common/libutil/xzmalloc.h" -#include "src/common/libutil/shortjson.h" #include "src/common/libutil/fdwalk.h" #include "zio.h" #include "subprocess.h" @@ -212,18 +212,29 @@ static int check_completion (struct subprocess *p) static int output_handler (zio_t *z, const char *json_str, int len, void *arg) { struct subprocess *p = (struct subprocess *) arg; - json_object *o; + json_t *o = NULL; + json_t *new_o; + char *json_str_amended; if (p->io_cb) { - if (!(o = json_tokener_parse (json_str))) { + if (!(o = json_loads (json_str, 0, NULL))) { errno = EINVAL; return -1; } - Jadd_int (o, "pid", subprocess_pid (p)); - Jadd_str (o, "type", "io"); - Jadd_str (o, "name", zio_name (z)); - p->io_cb (p, json_object_to_json_string (o)); - json_object_put (o); + if (!(new_o = json_pack ("{s:i s:s s:s}", "pid", subprocess_pid (p), + "type", "io", + "name", zio_name (z)))) + goto error; + if (json_object_update (o, new_o) < 0) { + json_decref (new_o); + goto error; + } + json_decref (new_o); + if (!(json_str_amended = json_dumps (o, JSON_COMPACT))) + goto error; + p->io_cb (p, json_str_amended); + free (json_str_amended); + json_decref (o); } else send_output_to_stream (zio_name (z), json_str); @@ -234,6 +245,10 @@ static int output_handler (zio_t *z, const char *json_str, int len, void *arg) */ check_completion (p); return (0); +error: + json_decref (o); + errno = EINVAL; + return -1; } static int hooks_table_init (struct subprocess *p) diff --git a/src/common/libsubprocess/test/loop.c b/src/common/libsubprocess/test/loop.c index df09deec52a4..f59d7bd32b35 100644 --- a/src/common/libsubprocess/test/loop.c +++ b/src/common/libsubprocess/test/loop.c @@ -29,8 +29,6 @@ #include #include -#include "src/common/libjson-c/json.h" - #include "tap.h" #include "subprocess.h" diff --git a/src/common/libsubprocess/test/socketpair.c b/src/common/libsubprocess/test/socketpair.c index 9b24a169bcba..450505697cb5 100644 --- a/src/common/libsubprocess/test/socketpair.c +++ b/src/common/libsubprocess/test/socketpair.c @@ -29,7 +29,6 @@ #include #include -#include "src/common/libjson-c/json.h" #include "tap.h" #include "subprocess.h" diff --git a/src/common/libsubprocess/test/subprocess.c b/src/common/libsubprocess/test/subprocess.c index a801a20d4d53..d7b29083b287 100644 --- a/src/common/libsubprocess/test/subprocess.c +++ b/src/common/libsubprocess/test/subprocess.c @@ -25,7 +25,6 @@ #include #include #include -#include "src/common/libjson-c/json.h" #include "tap.h" #include "subprocess.h" diff --git a/src/common/libsubprocess/test/zio.c b/src/common/libsubprocess/test/zio.c index ac89855f157f..85671a04f193 100644 --- a/src/common/libsubprocess/test/zio.c +++ b/src/common/libsubprocess/test/zio.c @@ -32,7 +32,6 @@ #include #include "src/common/libtap/tap.h" -#include "src/common/libjson-c/json.h" #include "zio.h"