#include "c.h"
#include "list.h"
#include "closestream.h"
+#include "optutils.h"
/* column IDs */
enum {
/* basic output flags */
static int no_headings;
static int raw;
+static int json;
struct lock {
struct list_head locks;
return -1;
}
scols_table_enable_raw(table, raw);
+ scols_table_enable_json(table, json);
scols_table_enable_noheadings(table, no_headings);
+ if (json)
+ scols_table_set_name(table, "locks");
+
for (i = 0; i < ncolumns; i++) {
struct colinfo *col = get_column_info(i);
fputs(_("List local system locks.\n"), out);
fputs(USAGE_OPTIONS, out);
- fputs(_(" -p, --pid <pid> process id\n"
+ fputs(_(" -J, --json use JSON output format\n"
+ " -p, --pid <pid> process id\n"
" -o, --output <list> define which output columns to use\n"
" -n, --noheadings don't print headings\n"
" -r, --raw use the raw output format\n"
struct list_head locks;
char *outarg = NULL;
static const struct option long_opts[] = {
+ { "json", no_argument, NULL, 'J' },
{ "pid", required_argument, NULL, 'p' },
{ "help", no_argument, NULL, 'h' },
{ "output", required_argument, NULL, 'o' },
{ NULL, 0, NULL, 0 }
};
+ static const ul_excl_t excl[] = { /* rows and cols in ASCII order */
+ { 'J','r' },
+ { 0 }
+ };
+ int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
atexit(close_stdout);
while ((c = getopt_long(argc, argv,
- "p:o:nruhV", long_opts, NULL)) != -1) {
+ "Jp:o:nruhV", long_opts, NULL)) != -1) {
+
+ err_exclusive_options(c, long_opts, excl, excl_st);
switch(c) {
+ case 'J':
+ json = 1;
+ break;
case 'p':
pid = strtos32_or_err(optarg, _("invalid PID argument"));
break;