[commits] [batctl] master: batctl: Allow to skip header in debug table output (9820b38)

postmaster at open-mesh.org postmaster at open-mesh.org
Tue Oct 16 20:00:28 CEST 2012


Repository : ssh://git@open-mesh.org/batctl

On branch  : master

>---------------------------------------------------------------

commit 9820b386612b238928d2c27748c29abfe0bd158d
Author: Sven Eckelmann <sven at narfation.org>
Date:   Sun Oct 14 22:20:54 2012 +0200

    batctl: Allow to skip header in debug table output
    
    Signed-off-by: Sven Eckelmann <sven at narfation.org>
    Signed-off-by: Marek Lindner <lindner_marek at yahoo.de>


>---------------------------------------------------------------

9820b386612b238928d2c27748c29abfe0bd158d
 debug.c      |   18 +++++++++++++++---
 debug.h      |    1 +
 functions.c  |    7 ++++++-
 functions.h  |    3 ++-
 main.c       |    2 +-
 man/batctl.8 |    3 +++
 sys.c        |   14 +++++++-------
 7 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/debug.c b/debug.c
index a230a12..260448b 100644
--- a/debug.c
+++ b/debug.c
@@ -38,36 +38,43 @@ const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM] = {
 		.opt_long = "originators",
 		.opt_short = "o",
 		.debugfs_name = "originators",
+		.header_lines = 2,
 	},
 	{
 		.opt_long = "gateways",
 		.opt_short = "gwl",
 		.debugfs_name = "gateways",
+		.header_lines = 1,
 	},
 	{
 		.opt_long = "translocal",
 		.opt_short = "tl",
 		.debugfs_name = "transtable_local",
+		.header_lines = 1,
 	},
 	{
 		.opt_long = "transglobal",
 		.opt_short = "tg",
 		.debugfs_name = "transtable_global",
+		.header_lines = 2,
 	},
 	{
 		.opt_long = "claimtable",
 		.opt_short = "cl",
 		.debugfs_name = "bla_claim_table",
+		.header_lines = 2,
 	},
 	{
 		.opt_long = "backbonetable",
 		.opt_short = "bbt",
 		.debugfs_name = "bla_backbone_table",
+		.header_lines = 2,
 	},
 	{
 		.opt_long = "dat_cache",
 		.opt_short = "dc",
 		.debugfs_name = "dat_cache",
+		.header_lines = 2,
 	},
 };
 
@@ -78,6 +85,7 @@ void debug_table_usage(int debug_table)
 	printf("parameters:\n");
 	printf(" \t -h print this help\n");
 	printf(" \t -n don't replace mac addresses with bat-host names\n");
+	printf(" \t -H don't show the header\n");
 	printf(" \t -w [interval] watch mode - refresh the table continuously\n");
 
 	if (debug_table == BATCTL_TABLE_ORIGINATORS)
@@ -93,7 +101,7 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 	float watch_interval = 1;
 	opterr = 0;
 
-	while ((optchar = getopt(argc, argv, "hnw:t:")) != -1) {
+	while ((optchar = getopt(argc, argv, "hnw:t:H")) != -1) {
 		switch (optchar) {
 		case 'h':
 			debug_table_usage(debug_table);
@@ -126,6 +134,9 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 				return EXIT_FAILURE;
 			}
 			break;
+		case 'H':
+			read_opt |= SKIP_HEADER;
+			break;
 		case '?':
 			if (optopt == 't')
 				printf("Error - option '-t' needs a number as argument\n");
@@ -152,7 +163,8 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 
 	debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", mesh_iface, full_path, sizeof(full_path));
 	return read_file(full_path, (char *)batctl_debug_tables[debug_table].debugfs_name,
-			 read_opt, orig_timeout, watch_interval);
+			 read_opt, orig_timeout, watch_interval,
+			 batctl_debug_tables[debug_table].header_lines);
 }
 
 static void log_usage(void)
@@ -190,6 +202,6 @@ int log_print(char *mesh_iface, int argc, char **argv)
 	}
 
 	debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", mesh_iface, full_path, sizeof(full_path));
-	res = read_file(full_path, DEBUG_LOG, read_opt, 0, 0);
+	res = read_file(full_path, DEBUG_LOG, read_opt, 0, 0, 0);
 	return res;
 }
diff --git a/debug.h b/debug.h
index 5bd7f3e..3fa2830 100644
--- a/debug.h
+++ b/debug.h
@@ -40,6 +40,7 @@ struct debug_table_data {
        const char opt_long[OPT_LONG_MAX_LEN];
        const char opt_short[OPT_SHORT_MAX_LEN];
        const char debugfs_name[DEBUG_TABLE_PATH_MAX_LEN];
+       size_t header_lines;
 };
 
 extern const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM];
diff --git a/functions.c b/functions.c
index a500444..57c2bba 100644
--- a/functions.c
+++ b/functions.c
@@ -162,7 +162,7 @@ static void file_open_problem_dbg(char *dir, char *fname, char *full_path)
 }
 
 int read_file(char *dir, char *fname, int read_opt,
-	      float orig_timeout, float watch_interval)
+	      float orig_timeout, float watch_interval, size_t header_lines)
 {
 	struct ether_addr *mac_addr;
 	struct bat_host *bat_host;
@@ -171,6 +171,7 @@ int read_file(char *dir, char *fname, int read_opt,
 	char full_path[500], *buff_ptr, *space_ptr, extra_char;
 	size_t len = 0;
 	FILE *fp = NULL;
+	size_t line;
 
 	if (read_opt & USE_BAT_HOSTS)
 		bat_hosts_init(read_opt);
@@ -180,6 +181,7 @@ int read_file(char *dir, char *fname, int read_opt,
 	strncat(full_path, fname, sizeof(full_path) - strlen(full_path));
 
 open:
+	line = 0;
 	fp = fopen(full_path, "r");
 
 	if (!fp) {
@@ -195,6 +197,9 @@ open:
 
 read:
 	while (getline(&line_ptr, &len, fp) != -1) {
+		if (line++ < header_lines && read_opt & SKIP_HEADER)
+			continue;
+
 		/* the buffer will be handled elsewhere */
 		if (read_opt & USE_READ_BUFF)
 			break;
diff --git a/functions.h b/functions.h
index 0ec1d1a..6e427f4 100644
--- a/functions.h
+++ b/functions.h
@@ -35,7 +35,7 @@ char *get_name_by_macaddr(struct ether_addr *mac_addr, int read_opt);
 char *get_name_by_macstr(char *mac_str, int read_opt);
 int file_exists(const char *fpath);
 int read_file(char *dir, char *path, int read_opt,
-	      float orig_timeout, float watch_interval);
+	      float orig_timeout, float watch_interval, size_t header_lines);
 int write_file(char *dir, char *fname, char *arg1, char *arg2);
 struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac);
 struct ether_addr *resolve_mac(const char *asc);
@@ -52,4 +52,5 @@ enum {
 	SILENCE_ERRORS = 0x20,
 	NO_OLD_ORIGS = 0x40,
 	COMPAT_FILTER = 0x80,
+	SKIP_HEADER = 0x100,
 };
diff --git a/main.c b/main.c
index 01a435b..647818d 100644
--- a/main.c
+++ b/main.c
@@ -118,7 +118,7 @@ int main(int argc, char **argv)
 	if (strcmp(argv[1], "-v") == 0) {
 		printf("batctl %s [batman-adv: ", SOURCE_VERSION);
 
-		ret = read_file("", module_ver_path, USE_READ_BUFF | SILENCE_ERRORS, 0, 0);
+		ret = read_file("", module_ver_path, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
 		if ((line_ptr) && (line_ptr[strlen(line_ptr) - 1] == '\n'))
 			line_ptr[strlen(line_ptr) - 1] = '\0';
 
diff --git a/man/batctl.8 b/man/batctl.8
index 804682e..feb1a17 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -168,6 +168,9 @@ All of the debug tables support the following options:
 .RS 10
 \-n     do not replace the MAC addresses with bat\-host names in the output
 .RE
+.RS 10
+\-H     do not show the header of the debug table
+.RE
 
 .RS 7
 The originator table also supports the "\-t" filter option to remove all originators from the output that have not been seen
diff --git a/sys.c b/sys.c
index 3d5e129..9591416 100644
--- a/sys.c
+++ b/sys.c
@@ -136,7 +136,7 @@ static int print_interfaces(char *mesh_iface)
 
 	while ((iface_dir = readdir(iface_base_dir)) != NULL) {
 		snprintf(path_buff, PATH_BUFF_LEN, SYS_MESH_IFACE_FMT, iface_dir->d_name);
-		res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0);
+		res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
 		if (res != EXIT_SUCCESS)
 			continue;
 
@@ -153,7 +153,7 @@ static int print_interfaces(char *mesh_iface)
 		line_ptr = NULL;
 
 		snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_STATUS_FMT, iface_dir->d_name);
-		res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0);
+		res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
 		if (res != EXIT_SUCCESS) {
 			printf("<error reading status>\n");
 			continue;
@@ -318,7 +318,7 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv)
 		goto out;
 	}
 
-	res = read_file(path_buff, SYS_LOG_LEVEL, USE_READ_BUFF, 0, 0);
+	res = read_file(path_buff, SYS_LOG_LEVEL, USE_READ_BUFF, 0, 0, 0);
 
 	if (res != EXIT_SUCCESS)
 		goto out;
@@ -382,7 +382,7 @@ int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv)
 
 	if (argc == 1) {
 		res = read_file(path_buff, (char *)batctl_settings[setting].sysfs_name,
-				NO_FLAGS, 0, 0);
+				NO_FLAGS, 0, 0, 0);
 		goto out;
 	}
 
@@ -445,7 +445,7 @@ int handle_gw_setting(char *mesh_iface, int argc, char **argv)
 	snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface);
 
 	if (argc == 1) {
-		res = read_file(path_buff, SYS_GW_MODE, USE_READ_BUFF, 0, 0);
+		res = read_file(path_buff, SYS_GW_MODE, USE_READ_BUFF, 0, 0, 0);
 
 		if (res != EXIT_SUCCESS)
 			goto out;
@@ -465,10 +465,10 @@ int handle_gw_setting(char *mesh_iface, int argc, char **argv)
 
 		switch (gw_mode) {
 		case GW_MODE_CLIENT:
-			res = read_file(path_buff, SYS_GW_SEL, USE_READ_BUFF, 0, 0);
+			res = read_file(path_buff, SYS_GW_SEL, USE_READ_BUFF, 0, 0, 0);
 			break;
 		case GW_MODE_SERVER:
-			res = read_file(path_buff, SYS_GW_BW, USE_READ_BUFF, 0, 0);
+			res = read_file(path_buff, SYS_GW_BW, USE_READ_BUFF, 0, 0, 0);
 			break;
 		default:
 			printf("off\n");



More information about the commits mailing list