aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-12-25 16:02:06 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-12-25 16:02:06 +0200
commit7f204cc788de3e03a51087b1273deb5b59288cf2 (patch)
treeae0c96af85c24bd7d9e84ba954435db42b25f8f1
parentfcace3930fc35a1b7beea75dba0cd48a5b229b21 (diff)
downloadpies-7f204cc788de3e03a51087b1273deb5b59288cf2.tar.gz
pies-7f204cc788de3e03a51087b1273deb5b59288cf2.tar.bz2
ctl: use numeric type for PIDS and wakeup time values.
-rw-r--r--src/ctl.c39
-rw-r--r--src/pies.c19
2 files changed, 38 insertions, 20 deletions
diff --git a/src/ctl.c b/src/ctl.c
index 737da2b..1da1370 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -455,9 +455,15 @@ json_object_set_string (struct json_value *obj,
va_list ap;
- struct json_value *val;
+ char *s;
- val = json_value_create (json_string);
va_start (ap, fmt);
- val->v.s = xvasprintf (fmt, ap);
+ s = xvasprintf (fmt, ap);
va_end (ap);
- json_object_set (obj, name, val);
+ json_object_set (obj, name, json_new_string (s));
+ free (s);
+}
+
+static void
+json_object_set_number (struct json_value *obj, char const *name, double val)
+{
+ json_object_set (obj, name, json_new_number (val));
}
@@ -644,2 +650,12 @@ json_writer (void *closure, char const *text, size_t len)
static void
+ctlio_adjust_format (struct ctlio *io, struct json_format *fmt)
+{
+ char const *val = http_get_header (io->input.headers, "X-Pies-Output");
+ if (!val)
+ return;
+ if (strcasecmp (val, "pretty") == 0)
+ fmt->indent = 2;
+}
+
+static void
ctlio_finalize_reply (struct ctlio *io)
@@ -676,3 +692,3 @@ ctlio_finalize_reply (struct ctlio *io)
.indent = 0,
- .precision = -1,
+ .precision = 0,
.write = json_writer,
@@ -680,2 +696,4 @@ ctlio_finalize_reply (struct ctlio *io)
};
+
+ ctlio_adjust_format (io, &fmt);
json_format_value (io->output.reply, &fmt);
@@ -1182,4 +1200,3 @@ idfmt_pid (struct ctlio *io, char const *name, void *ptr)
{
- json_object_set_string (io->output.reply, name, "%lu",
- (unsigned long) getpid ());
+ json_object_set_number (io->output.reply, name, getpid ());
}
@@ -1367,3 +1384,3 @@ prog_serialize (struct prog *prog)
if (prog->pid)
- json_object_set_string (ret, "PID", "%lu", (unsigned long) prog->pid);
+ json_object_set_number (ret, "PID", prog->pid);
else if (prog->v.p.status == status_listener
@@ -1375,4 +1392,4 @@ prog_serialize (struct prog *prog)
{
- json_object_set_string (ret, "wakeup-time", "%lu",
- (unsigned long) (prog->v.p.timestamp + SLEEPTIME));
+ json_object_set_number (ret, "wakeup-time",
+ prog->v.p.timestamp + SLEEPTIME);
}
@@ -1386,3 +1403,3 @@ prog_serialize (struct prog *prog)
case TYPE_REDIRECTOR:
- json_object_set_string (ret, "PID", "%lu", (unsigned long) prog->pid);
+ json_object_set_number (ret, "PID", prog->pid);
break;
diff --git a/src/pies.c b/src/pies.c
index 5c3d7e6..7ff226a 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -31,11 +31,12 @@ int init_process;
-enum pies_command {
- COM_START,
- COM_RESTART,
- COM_RELOAD,
- COM_STATUS,
- COM_STOP,
- COM_DUMP_PREREQ,
- COM_DUMP_DEPMAP
-};
+enum pies_command
+ {
+ COM_START,
+ COM_RESTART,
+ COM_RELOAD,
+ COM_STATUS,
+ COM_STOP,
+ COM_DUMP_PREREQ,
+ COM_DUMP_DEPMAP
+ };

Return to:

Send suggestions and report system problems to the System administrator.