ifctrstat: Add -n option to omit label printing
This commit is contained in:
parent
6106164d7c
commit
7b45d3939d
1 changed files with 21 additions and 3 deletions
|
@ -14,9 +14,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
|
||||||
#include "libifupdown/libifupdown.h"
|
#include "libifupdown/libifupdown.h"
|
||||||
#include "cmd/multicall.h"
|
#include "cmd/multicall.h"
|
||||||
|
|
||||||
|
@ -25,6 +26,8 @@ extern int avail_counters_count;
|
||||||
|
|
||||||
extern const char *read_counter(const char *interface, const char *counter);
|
extern const char *read_counter(const char *interface, const char *counter);
|
||||||
|
|
||||||
|
static bool show_label = true;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
counter_is_valid(const char *candidate)
|
counter_is_valid(const char *candidate)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +43,10 @@ counter_is_valid(const char *candidate)
|
||||||
static void
|
static void
|
||||||
print_counter(const char *iface, const char *name, const char *value)
|
print_counter(const char *iface, const char *name, const char *value)
|
||||||
{
|
{
|
||||||
|
if (show_label)
|
||||||
fprintf(stdout, "%s: %s\n", name, value);
|
fprintf(stdout, "%s: %s\n", name, value);
|
||||||
|
else
|
||||||
|
fprintf(stdout, "%s\n", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -81,6 +87,17 @@ ifctrstat_list_counters(int short_opt, const struct if_option *opt, const char *
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ifctrstat_set_nolabel(int short_opt, const struct if_option *opt, const char *opt_arg, const struct if_applet *applet)
|
||||||
|
{
|
||||||
|
(void) short_opt;
|
||||||
|
(void) opt;
|
||||||
|
(void) opt_arg;
|
||||||
|
(void) applet;
|
||||||
|
|
||||||
|
show_label = false;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ifctrstat_main(int argc, char *argv[])
|
ifctrstat_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -125,7 +142,8 @@ ifctrstat_main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct if_option local_options[] = {
|
static struct if_option local_options[] = {
|
||||||
{'L', "list", NULL, "List available counters", false, ifctrstat_list_counters}
|
{'L', "list", NULL, "List available counters", false, ifctrstat_list_counters},
|
||||||
|
{'n', "no-label", NULL, "Print value without counter label", false, ifctrstat_set_nolabel}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct if_option_group local_option_group = {
|
static struct if_option_group local_option_group = {
|
||||||
|
|
Loading…
Reference in a new issue