Skip to content

Commit

Permalink
libsubprocess: stop using json-c
Browse files Browse the repository at this point in the history
Problem: libsubprocess library still uses json-c.

Convert to jansson.

Drop extraneous json-c includes from subprocess/zio
unit tests as well.
  • Loading branch information
garlick committed May 3, 2018
1 parent 9def9f7 commit 852d53b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
31 changes: 23 additions & 8 deletions src/common/libsubprocess/subprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
#include <czmq.h>
#include <argz.h>
#include <envz.h>
#include <jansson.h>

#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"
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/common/libsubprocess/test/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include <czmq.h>
#include <flux/core.h>

#include "src/common/libjson-c/json.h"

#include "tap.h"
#include "subprocess.h"

Expand Down
1 change: 0 additions & 1 deletion src/common/libsubprocess/test/socketpair.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <czmq.h>
#include <flux/core.h>

#include "src/common/libjson-c/json.h"
#include "tap.h"
#include "subprocess.h"

Expand Down
1 change: 0 additions & 1 deletion src/common/libsubprocess/test/subprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include "src/common/libjson-c/json.h"

#include "tap.h"
#include "subprocess.h"
Expand Down
1 change: 0 additions & 1 deletion src/common/libsubprocess/test/zio.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <flux/core.h>

#include "src/common/libtap/tap.h"
#include "src/common/libjson-c/json.h"

#include "zio.h"

Expand Down

0 comments on commit 852d53b

Please sign in to comment.