summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2015-12-25 14:02:06 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2015-12-25 14:02:06 (GMT)
commit7f204cc788de3e03a51087b1273deb5b59288cf2 (patch) (side-by-side diff)
treeae0c96af85c24bd7d9e84ba954435db42b25f8f1
parentfcace3930fc35a1b7beea75dba0cd48a5b229b21 (diff)
downloadpies-7f204cc788de3e03a51087b1273deb5b59288cf2.tar.gz
pies-7f204cc788de3e03a51087b1273deb5b59288cf2.tar.bz2
ctl: use numeric type for PIDS and wakeup time values.
Diffstat (more/less context) (ignore whitespace changes)
-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
@@ -453,13 +453,19 @@ json_object_set_string (struct json_value *obj,
char const *name, char const *fmt, ...)
{
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));
}
static struct json_value *
@@ -642,6 +648,16 @@ 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)
{
size_t size;
@@ -674,10 +690,12 @@ ctlio_finalize_reply (struct ctlio *io)
{
struct json_format fmt = {
.indent = 0,
- .precision = -1,
+ .precision = 0,
.write = json_writer,
.data = &tmpbuf
};
+
+ ctlio_adjust_format (io, &fmt);
json_format_value (io->output.reply, &fmt);
size = ctlbuf_rdsize (&tmpbuf);
if (size)
@@ -1180,8 +1198,7 @@ idfmt_string_ptr (struct ctlio *io, char const *name, void *ptr)
static void
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 ());
}
static void
@@ -1365,7 +1382,7 @@ prog_serialize (struct prog *prog)
FORMAT_IDX (ret, "status", status_str, prog->v.p.status);
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
&& prog->v.p.comp->socket_url)
json_object_set_string (ret, "URL", "%s",
@@ -1373,8 +1390,8 @@ prog_serialize (struct prog *prog)
if (prog->v.p.status == status_sleeping)
{
- 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);
}
v = json_new_array ();
@@ -1384,7 +1401,7 @@ prog_serialize (struct prog *prog)
break;
case TYPE_REDIRECTOR:
- json_object_set_string (ret, "PID", "%lu", (unsigned long) prog->pid);
+ json_object_set_number (ret, "PID", prog->pid);
break;
case TYPE_COMMAND:
diff --git a/src/pies.c b/src/pies.c
index 5c3d7e6..7ff226a 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -29,15 +29,16 @@ struct pies_privs pies_privs;
int foreground;
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
+ };
enum pies_command command;
char *statedir = DEFAULT_STATE_DIR;

Return to:

Send suggestions and report system problems to the System administrator.