]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsipc: improve JSON output
authorKarel Zak <kzak@redhat.com>
Wed, 1 Jul 2015 10:27:48 +0000 (12:27 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Jul 2015 09:48:09 +0000 (11:48 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lsipc.c

index edbd3b5acd9db807438d606959af68d09de175f1..38c232a35c1ab7d50a795b5c5d1e65fee0522e63 100644 (file)
@@ -121,6 +121,7 @@ enum {
        OUT_NEWLINE,
        OUT_RAW,
        OUT_NUL,
+       OUT_JSON,
        OUT_PRETTY
 };
 
@@ -128,7 +129,6 @@ struct lsipc_control {
        int outmode;
        unsigned int noheadings : 1,            /* don't print header line */
                     notrunc : 1,               /* don't truncate columns */
-                    json : 1,                  /* JSON output */
                     bytes : 1,                 /* SIZE in bytes */
                     numperms : 1,              /* numeric permissions */
                     time_mode : 2;
@@ -324,8 +324,6 @@ static struct libscols_table *setup_table(struct lsipc_control *ctl)
                errx(EXIT_FAILURE, _("failed to initialize output table"));
        if (ctl->noheadings)
                scols_table_enable_noheadings(table, 1);
-       if (ctl->json)
-               scols_table_enable_json(table, 1);
 
        switch(ctl->outmode) {
        case OUT_COLON:
@@ -346,6 +344,10 @@ static struct libscols_table *setup_table(struct lsipc_control *ctl)
                break;
        case OUT_PRETTY:
                scols_table_enable_noheadings(table, 1);
+               break;
+       case OUT_JSON:
+               scols_table_enable_json(table, 1);
+               break;
        default:
                break;
        }
@@ -504,6 +506,8 @@ static void do_sem(int id, struct lsipc_control *ctl, struct libscols_table *tb)
        struct sem_data *semds, *semdsp;
        char *arg = NULL, *time;
 
+       scols_table_set_name(tb, "semaphores");
+
        if (ipc_sem_get_info(id, &semds) < 1) {
                if (id > -1)
                        warnx(_("id %d not found"), id);
@@ -680,6 +684,7 @@ static void do_msg(int id, struct lsipc_control *ctl, struct libscols_table *tb)
                        warnx(_("id %d not found"), id);
                return;
        }
+       scols_table_set_name(tb, "messages");
 
        for (msgdsp = msgds; msgdsp->next != NULL || id > -1 ; msgdsp = msgdsp->next) {
                size_t n;
@@ -852,6 +857,8 @@ static void do_shm(int id, struct lsipc_control *ctl, struct libscols_table *tb)
                return;
        }
 
+       scols_table_set_name(tb, "sharedmemory");
+
        for (shmdsp = shmds; shmdsp->next != NULL || id > -1 ; shmdsp = shmdsp->next) {
                size_t n;
                ln = scols_table_new_line(tb, NULL);
@@ -1194,7 +1201,7 @@ int main(int argc, char *argv[])
                        ctl->time_mode = parse_time_mode(optarg);
                        break;
                case 'J':
-                       ctl->json = 1;
+                       ctl->outmode = OUT_JSON;
                        break;
                case 't':
                        show_time = 1;
@@ -1265,6 +1272,10 @@ int main(int argc, char *argv[])
        tb = setup_table(ctl);
        if (!tb)
                return EXIT_FAILURE;
+
+       if (global)
+               scols_table_set_name(tb, "ipclimits");
+
        if (msg) {
                if (global)
                        do_msg_global(tb);