[commits] r1627 - branches/batctl-0.2.x

postmaster at open-mesh.net postmaster at open-mesh.net
Wed Apr 7 13:15:39 CEST 2010


Author: marek
Date: 2010-04-07 13:15:20 +0200 (Wed, 07 Apr 2010)
New Revision: 1627

Modified:
   branches/batctl-0.2.x/functions.c
   branches/batctl-0.2.x/functions.h
   branches/batctl-0.2.x/main.c
   branches/batctl-0.2.x/proc.c
   branches/batctl-0.2.x/proc.h
   branches/batctl-0.2.x/sys.c
   branches/batctl-0.2.x/sys.h
   branches/batctl-0.2.x/vis.c
Log:
batctl: adjust to new /sysfs paths

Signed-off-by: Marek Lindner <lindner_marek at yahoo.de>

Modified: branches/batctl-0.2.x/functions.c
===================================================================
--- branches/batctl-0.2.x/functions.c	2010-04-07 11:15:17 UTC (rev 1626)
+++ branches/batctl-0.2.x/functions.c	2010-04-07 11:15:20 UTC (rev 1627)
@@ -268,7 +268,7 @@
 	return res;
 }
 
-int write_file(char *dir, char *fname, char *value)
+int write_file(char *dir, char *fname, char *arg1, char *arg2)
 {
 	int fd = 0, res = EXIT_FAILURE;
 	char full_path[500];
@@ -293,7 +293,10 @@
 		goto out;
 	}
 
-	write_len = write(fd, value, strlen(value) + 1);
+	if (arg2)
+		write_len = dprintf(fd, "%s %s", arg1, arg2);
+	else
+		write_len = write(fd, arg1, strlen(arg1) + 1);
 
 	if (write_len < 0) {
 		printf("Error - can't write to file '%s': %s\n", full_path, strerror(errno));

Modified: branches/batctl-0.2.x/functions.h
===================================================================
--- branches/batctl-0.2.x/functions.h	2010-04-07 11:15:17 UTC (rev 1626)
+++ branches/batctl-0.2.x/functions.h	2010-04-07 11:15:20 UTC (rev 1627)
@@ -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 read_file(char *dir, char *path, int read_opt);
-int write_file(char *dir, char *path, char *value);
+int write_file(char *dir, char *fname, char *arg1, char *arg2);
 int check_proc_dir(char *dir);
 
 extern char *line_ptr;

Modified: branches/batctl-0.2.x/main.c
===================================================================
--- branches/batctl-0.2.x/main.c	2010-04-07 11:15:17 UTC (rev 1626)
+++ branches/batctl-0.2.x/main.c	2010-04-07 11:15:20 UTC (rev 1627)
@@ -41,16 +41,16 @@
 void print_usage(void) {
 	printf("Usage: batctl [options] commands \n");
 	printf("commands:\n");
-	printf(" \tinterface|if  [none|interface]  \tdisplay or modify the interface settings\n");
-	printf(" \toriginators|o                   \tdisplay the originator table\n");
-	printf(" \tinterval|it   [orig_interval]   \tdisplay or modify the originator interval in ms\n");
-	printf(" \tloglevel|ll   [level]           \tdisplay or modify the log level\n");
-	printf(" \tlog|l                           \tread the log produced by the kernel module\n");
-	printf(" \ttranslocal|tl                   \tdisplay the local translation table\n");
-	printf(" \ttransglobal|tg                  \tdisplay the global translation table\n");
-	printf(" \tvis_server|vs [enabled|disabled]\tdisplay or modify the status of the VIS server\n");
-	printf(" \tvis_data|vd [dot|JSON]          \tdisplay the VIS data in dot or JSON format\n");
-	printf(" \taggregation|ag   [0|1]          \tdisplay or modify the packet aggregation setting\n");
+	printf(" \tinterface|if   [none|interface]  \tdisplay or modify the interface settings\n");
+	printf(" \toriginators|o                    \tdisplay the originator table\n");
+	printf(" \tinterval|it    [orig_interval]   \tdisplay or modify the originator interval in ms\n");
+	printf(" \tloglevel|ll    [level]           \tdisplay or modify the log level\n");
+	printf(" \tlog|l                            \tread the log produced by the kernel module\n");
+	printf(" \ttranslocal|tl                    \tdisplay the local translation table\n");
+	printf(" \ttransglobal|tg                   \tdisplay the global translation table\n");
+	printf(" \tvis_mode|vm    [mode]            \tdisplay or modify the status of the VIS server\n");
+	printf(" \tvis_data|vd    [dot|JSON]        \tdisplay the VIS data in dot or JSON format\n");
+	printf(" \taggregation|ag [0|1]             \tdisplay or modify the packet aggregation setting\n");
 	printf("\n");
 	printf(" \tping|p        <destination>     \tping another batman adv host via layer 2\n");
 	printf(" \ttraceroute|tr <destination>     \ttraceroute another batman adv host via layer 2\n");
@@ -122,9 +122,9 @@
 
 		ret = handle_proc_setting(argc - 1, argv + 1, PROC_ORIG_INTERVAL, orig_interval_usage);
 
-	} else if ((strcmp(argv[1], "vis_server") == 0) || (strcmp(argv[1], "vs") == 0)) {
+	} else if ((strcmp(argv[1], "vis_mode") == 0) || (strcmp(argv[1], "vm") == 0)) {
 
-		ret = handle_proc_setting(argc - 1, argv + 1, PROC_VIS_SERVER, vis_server_usage);
+		ret = handle_sys_setting(argc - 1, argv + 1, SYS_VIS_MODE, vis_mode_usage);
 
 	} else if ((strcmp(argv[1], "vis_data") == 0) || (strcmp(argv[1], "vd") == 0)) {
 

Modified: branches/batctl-0.2.x/proc.c
===================================================================
--- branches/batctl-0.2.x/proc.c	2010-04-07 11:15:17 UTC (rev 1626)
+++ branches/batctl-0.2.x/proc.c	2010-04-07 11:15:20 UTC (rev 1627)
@@ -57,9 +57,9 @@
 
 	for (i = 1; i < argc; i++) {
 		if (strcmp(argv[i], "none") == 0)
-			res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, "");
+			res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, "", NULL);
 		else
-			res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, argv[i]);
+			res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, argv[i], NULL);
 
 		if (res != EXIT_SUCCESS)
 			return res;
@@ -75,13 +75,6 @@
 	printf(" \t -h print this help\n");
 }
 
-void vis_server_usage(void)
-{
-	printf("Usage: batctl [options] vis_server \n");
-	printf("options:\n");
-	printf(" \t -h print this help\n");
-}
-
 int handle_table(int argc, char **argv, char *file_path, void table_usage(void))
 {
 	int optchar, read_opt = USE_BAT_HOSTS;
@@ -124,5 +117,5 @@
 	if (argc == 1)
 		return read_file(PROC_ROOT_PATH, file_path, SINGLE_READ);
 
-	return write_file(PROC_ROOT_PATH, file_path, argv[1]);
+	return write_file(PROC_ROOT_PATH, file_path, argv[1], NULL);
 }

Modified: branches/batctl-0.2.x/proc.h
===================================================================
--- branches/batctl-0.2.x/proc.h	2010-04-07 11:15:17 UTC (rev 1626)
+++ branches/batctl-0.2.x/proc.h	2010-04-07 11:15:20 UTC (rev 1627)
@@ -24,12 +24,9 @@
 #define PROC_ROOT_PATH "/proc/net/batman-adv/"
 #define PROC_INTERFACES "interfaces"
 #define PROC_ORIG_INTERVAL "orig_interval"
-#define PROC_VIS_SERVER "vis_server"
-#define PROC_VIS_DATA "vis_data"
 
 int interface(int argc, char **argv);
 
 void orig_interval_usage(void);
-void vis_server_usage(void);
 int handle_table(int argc, char **argv, char *file_path, void table_usage(void));
 int handle_proc_setting(int argc, char **argv, char *file_path, void setting_usage(void));

Modified: branches/batctl-0.2.x/sys.c
===================================================================
--- branches/batctl-0.2.x/sys.c	2010-04-07 11:15:17 UTC (rev 1626)
+++ branches/batctl-0.2.x/sys.c	2010-04-07 11:15:20 UTC (rev 1627)
@@ -73,7 +73,7 @@
 
 static void log_level_usage(void)
 {
-	printf("Usage: batctl [options] loglevel \n");
+	printf("Usage: batctl [options] loglevel [level]\n");
 	printf("options:\n");
 	printf(" \t -h print this help\n");
 }
@@ -94,7 +94,7 @@
 	}
 
 	if (argc != 1) {
-		res = write_file(SYS_MODULE_PATH, SYS_LOG_LEVEL, argv[1]);
+		res = write_file(SYS_MODULE_PATH, SYS_LOG_LEVEL, argv[1], NULL);
 		goto out;
 	}
 
@@ -172,11 +172,18 @@
 
 void aggregation_usage(void)
 {
-	printf("Usage: batctl [options] aggregation \n");
+	printf("Usage: batctl [options] aggregation [0|1]\n");
 	printf("options:\n");
 	printf(" \t -h print this help\n");
 }
 
+void vis_mode_usage(void)
+{
+	printf("Usage: batctl [options] vis_mode [mode]\n");
+	printf("options:\n");
+	printf(" \t -h print this help\n");
+}
+
 int handle_sys_setting(int argc, char **argv, char *file_path, void setting_usage(void))
 {
 	int optchar, res;
@@ -233,5 +240,5 @@
 	return EXIT_FAILURE;
 
 write_file:
-	return write_file(SYS_BATIF_PATH, file_path, argv[1]);
+	return write_file(SYS_BATIF_PATH, file_path, argv[1], argc > 2 ? argv[2] : NULL);
 }

Modified: branches/batctl-0.2.x/sys.h
===================================================================
--- branches/batctl-0.2.x/sys.h	2010-04-07 11:15:17 UTC (rev 1626)
+++ branches/batctl-0.2.x/sys.h	2010-04-07 11:15:20 UTC (rev 1627)
@@ -28,11 +28,14 @@
 #define SYS_TRANSTABLE_LOCAL "transtable_local"
 #define SYS_TRANSTABLE_GLOBAL "transtable_global"
 #define SYS_AGGR "aggregate_ogm"
+#define SYS_VIS_MODE "vis_mode"
+#define SYS_VIS_DATA "vis_data"
 
 void originators_usage(void);
 void trans_local_usage(void);
 void trans_global_usage(void);
 void aggregation_usage(void);
+void vis_mode_usage(void);
 int log_print(int argc, char **argv);
 int handle_loglevel(int argc, char **argv);
 int handle_sys_table(int argc, char **argv, char *file_path, void table_usage(void));

Modified: branches/batctl-0.2.x/vis.c
===================================================================
--- branches/batctl-0.2.x/vis.c	2010-04-07 11:15:17 UTC (rev 1626)
+++ branches/batctl-0.2.x/vis.c	2010-04-07 11:15:20 UTC (rev 1627)
@@ -31,7 +31,7 @@
 #include "vis.h"
 #include "functions.h"
 #include "bat-hosts.h"
-#include "proc.h"
+#include "sys.h"
 
 #define TQ_MAX_VALUE 255
 
@@ -170,9 +170,9 @@
 	if (check_proc_dir("/proc") != EXIT_SUCCESS)
 		return NULL;
 
-	strncpy(full_path, PROC_ROOT_PATH, strlen(PROC_ROOT_PATH));
-	full_path[strlen(PROC_ROOT_PATH)] = '\0';
-	strncat(full_path, PROC_VIS_DATA,
+	strncpy(full_path, SYS_BATIF_PATH, strlen(SYS_BATIF_PATH));
+	full_path[strlen(SYS_BATIF_PATH)] = '\0';
+	strncat(full_path, SYS_VIS_DATA,
 		sizeof(full_path) - strlen(full_path));
 
 	return fopen(full_path, "r");



More information about the commits mailing list