Author: marek
Date: 2010-03-21 23:05:42 +0100 (Sun, 21 Mar 2010)
New Revision: 1609
Modified:
trunk/batctl/functions.c
trunk/batctl/functions.h
trunk/batctl/main.c
trunk/batctl/proc.c
trunk/batctl/proc.h
trunk/batctl/sys.c
trunk/batctl/sys.h
trunk/batctl/vis.c
Log:
batctl: adjust to new /sysfs paths
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
Modified: trunk/batctl/functions.c
===================================================================
--- trunk/batctl/functions.c 2010-03-21 22:05:34 UTC (rev 1608)
+++ trunk/batctl/functions.c 2010-03-21 22:05:42 UTC (rev 1609)
@@ -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: trunk/batctl/functions.h
===================================================================
--- trunk/batctl/functions.h 2010-03-21 22:05:34 UTC (rev 1608)
+++ trunk/batctl/functions.h 2010-03-21 22:05:42 UTC (rev 1609)
@@ -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: trunk/batctl/main.c
===================================================================
--- trunk/batctl/main.c 2010-03-21 22:05:34 UTC (rev 1608)
+++ trunk/batctl/main.c 2010-03-21 22:05:42 UTC (rev 1609)
@@ -47,10 +47,10 @@
printf(" \tloglevel|ll [level] \tdisplay or modify the log level\n");
printf(" \tlog|l \tread the log produced by the kernel module\n");
printf(" \tgw_mode|gw [mode] \tdisplay or modify the gateway mode\n");
- printf(" \tgw_srv_list|gwl \tdisplay the gateway server list\n");
+ printf(" \tgateways|gwl \tdisplay the gateway server list\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_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(" \tbonding|b [0|1] \tdisplay or modify the bonding mode setting\n");
@@ -125,9 +125,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)) {
@@ -135,11 +135,11 @@
} else if ((strcmp(argv[1], "gw_mode") == 0) || (strcmp(argv[1], "gw") == 0)) {
- ret = handle_proc_setting(argc - 1, argv + 1, PROC_GW_MODE, gw_mode_usage);
+ ret = handle_sys_setting(argc - 1, argv + 1, SYS_GW_MODE, gw_mode_usage);
- } else if ((strcmp(argv[1], "gw_srv_list") == 0) || (strcmp(argv[1], "gwl") == 0)) {
+ } else if ((strcmp(argv[1], "gateways") == 0) || (strcmp(argv[1], "gwl") == 0)) {
- ret = handle_table(argc - 1, argv + 1, PROC_GW_SRV_LIST, gw_srv_list_usage);
+ ret = handle_sys_table(argc - 1, argv + 1, SYS_GATEWAYS, gateways_usage);
} else if ((strcmp(argv[1], "aggregation") == 0) || (strcmp(argv[1], "ag") == 0)) {
Modified: trunk/batctl/proc.c
===================================================================
--- trunk/batctl/proc.c 2010-03-21 22:05:34 UTC (rev 1608)
+++ trunk/batctl/proc.c 2010-03-21 22:05:42 UTC (rev 1609)
@@ -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;
@@ -68,15 +68,6 @@
return EXIT_SUCCESS;
}
-void gw_srv_list_usage(void)
-{
- printf("Usage: batctl [options] gw_srv_list \n");
- printf("options:\n");
- printf(" \t -h print this help\n");
- printf(" \t -n don't replace mac addresses with bat-host names\n");
- printf(" \t -w watch mode - refresh the gateway server list continuously\n");
-}
-
void orig_interval_usage(void)
{
printf("Usage: batctl [options] interval \n");
@@ -84,20 +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");
-}
-
-void gw_mode_usage(void)
-{
- printf("Usage: batctl [options] gw_mode [mode]\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;
@@ -140,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: trunk/batctl/proc.h
===================================================================
--- trunk/batctl/proc.h 2010-03-21 22:05:34 UTC (rev 1608)
+++ trunk/batctl/proc.h 2010-03-21 22:05:42 UTC (rev 1609)
@@ -22,16 +22,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"
-#define PROC_GW_MODE "gateway_mode"
-#define PROC_GW_SRV_LIST "gateway_srv_list"
int interface(int argc, char **argv);
void orig_interval_usage(void);
-void vis_server_usage(void);
-void gw_mode_usage(void);
-void gw_srv_list_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: trunk/batctl/sys.c
===================================================================
--- trunk/batctl/sys.c 2010-03-21 22:05:34 UTC (rev 1608)
+++ trunk/batctl/sys.c 2010-03-21 22:05:42 UTC (rev 1609)
@@ -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;
}
@@ -146,6 +146,15 @@
printf(" \t -w watch mode - refresh the global translation table continuously\n");
}
+void gateways_usage(void)
+{
+ printf("Usage: batctl [options] gateways \n");
+ printf("options:\n");
+ printf(" \t -h print this help\n");
+ printf(" \t -n don't replace mac addresses with bat-host names\n");
+ printf(" \t -w watch mode - refresh the gateway server list continuously\n");
+}
+
int handle_sys_table(int argc, char **argv, char *file_path, void table_usage(void))
{
int optchar, read_opt = USE_BAT_HOSTS;
@@ -172,18 +181,32 @@
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 bonding_usage(void)
{
- printf("Usage: batctl [options] bonding \n");
+ printf("Usage: batctl [options] bonding [0|1]\n");
printf("options:\n");
printf(" \t -h print this help\n");
}
+void gw_mode_usage(void)
+{
+ printf("Usage: batctl [options] gw_mode [mode]\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;
@@ -240,5 +263,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: trunk/batctl/sys.h
===================================================================
--- trunk/batctl/sys.h 2010-03-21 22:05:34 UTC (rev 1608)
+++ trunk/batctl/sys.h 2010-03-21 22:05:42 UTC (rev 1609)
@@ -29,12 +29,19 @@
#define SYS_TRANSTABLE_GLOBAL "transtable_global"
#define SYS_AGGR "aggregate_ogm"
#define SYS_BONDING "bonding"
+#define SYS_GW_MODE "gw_mode"
+#define SYS_GATEWAYS "gateways"
+#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 bonding_usage(void);
+void gw_mode_usage(void);
+void gateways_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: trunk/batctl/vis.c
===================================================================
--- trunk/batctl/vis.c 2010-03-21 22:05:34 UTC (rev 1608)
+++ trunk/batctl/vis.c 2010-03-21 22:05:42 UTC (rev 1609)
@@ -29,7 +29,7 @@
#include "vis.h"
#include "functions.h"
#include "bat-hosts.h"
-#include "proc.h"
+#include "sys.h"
#define TQ_MAX_VALUE 255
@@ -168,9 +168,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");