]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/lsirq.c
Merge branch 'patch-23' of https://github.com/mariobl/util-linux
[thirdparty/util-linux.git] / sys-utils / lsirq.c
index 7853af0eee060b57a45f350aa7b47da8c725b581..36164c96bb685d3b0e9fe0bb9d8767e87343038e 100644 (file)
@@ -1,4 +1,6 @@
 /*
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
  * lsirq - utility to display kernel interrupt information.
  *
  * Copyright (C) 2019 zhenwei pi <pizhenwei@bytedance.com>
@@ -8,15 +10,6 @@
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 #include <ctype.h>
 #include <errno.h>
 #include <libsmartcols.h>
 
 #include "closestream.h"
+#include "optutils.h"
 #include "strutils.h"
 #include "xalloc.h"
 
 #include "irq-common.h"
 
-static int print_irq_data(struct irq_output *out)
+static int print_irq_data(struct irq_output *out, int softirq)
 {
        struct libscols_table *table;
 
-       table = get_scols_table(out, NULL, NULL);
+       table = get_scols_table(out, NULL, NULL, softirq, 0, NULL);
        if (!table)
                return -1;
 
@@ -56,19 +50,22 @@ static void __attribute__((__noreturn__)) usage(void)
        printf(_(" %s [options]\n"), program_invocation_short_name);
        fputs(USAGE_SEPARATOR, stdout);
 
-       puts(_("Utility to display kernel interrupt information."));
+       fputs(_("Utility to display kernel interrupt information."), stdout);
 
        fputs(USAGE_OPTIONS, stdout);
        fputs(_(" -J, --json           use JSON output format\n"), stdout);
+       fputs(_(" -P, --pairs          use key=\"value\" output format\n"), stdout);
+       fputs(_(" -n, --noheadings     don't print headings\n"), stdout);
        fputs(_(" -o, --output <list>  define which output columns to use\n"), stdout);
        fputs(_(" -s, --sort <column>  specify sort column\n"), stdout);
+       fputs(_(" -S, --softirq        show softirqs instead of interrupts\n"), stdout);
        fputs(USAGE_SEPARATOR, stdout);
-       printf(USAGE_HELP_OPTIONS(22));
+       fprintf(stdout, USAGE_HELP_OPTIONS(22));
 
        fputs(USAGE_COLUMNS, stdout);
        irq_print_columns(stdout, 1);
 
-       printf(USAGE_MAN_TAIL("lsirq(1)"));
+       fprintf(stdout, USAGE_MAN_TAIL("lsirq(1)"));
        exit(EXIT_SUCCESS);
 }
 
@@ -79,28 +76,48 @@ int main(int argc, char **argv)
        };
        static const struct option longopts[] = {
                {"sort", required_argument, NULL, 's'},
+               {"noheadings", no_argument, NULL, 'n'},
                {"output", required_argument, NULL, 'o'},
+               {"softirq", no_argument, NULL, 'S'},
                {"json", no_argument, NULL, 'J'},
+               {"pairs", no_argument, NULL, 'P'},
                {"help", no_argument, NULL, 'h'},
                {"version", no_argument, NULL, 'V'},
                {NULL, 0, NULL, 0}
        };
        int c;
        const char *outarg = NULL;
+       static const ul_excl_t excl[] = {       /* rows and cols in ASCII order */
+               {'J', 'P'},
+               {0}
+       };
+       int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
+       int softirq = 0;
 
        setlocale(LC_ALL, "");
 
-       while ((c = getopt_long(argc, argv, "o:s:hJV", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "no:s:ShJPV", longopts, NULL)) != -1) {
+               err_exclusive_options(c, longopts, excl, excl_st);
+
                switch (c) {
                case 'J':
                        out.json = 1;
                        break;
+               case 'P':
+                       out.pairs = 1;
+                       break;
+               case 'n':
+                       out.no_headings = 1;
+                       break;
                case 'o':
                        outarg = optarg;
                        break;
                case 's':
                        set_sort_func_by_name(&out, optarg);
                        break;
+               case 'S':
+                       softirq = 1;
+                       break;
                case 'V':
                        print_version(EXIT_SUCCESS);
                case 'h':
@@ -124,5 +141,5 @@ int main(int argc, char **argv)
                                irq_column_name_to_id) < 0)
                exit(EXIT_FAILURE);
 
-       return print_irq_data(&out) == 0 ?  EXIT_SUCCESS : EXIT_FAILURE;
+       return print_irq_data(&out, softirq) == 0 ?  EXIT_SUCCESS : EXIT_FAILURE;
 }