Author: marek Date: 2010-05-21 19:05:05 +0200 (Fri, 21 May 2010) New Revision: 1675
Modified: trunk/batctl/functions.c trunk/batctl/functions.h trunk/batctl/main.c trunk/batctl/sys.c trunk/batctl/sys.h Log: batctl: follow single value conversion of sysfs files
Since the kernel module does not print the allowed input values for each sysfs file anylonger, these values have to be hard-coded.
Signed-off-by: Marek Lindner lindner_marek@yahoo.de
Modified: trunk/batctl/functions.c =================================================================== --- trunk/batctl/functions.c 2010-05-21 17:05:04 UTC (rev 1674) +++ trunk/batctl/functions.c 2010-05-21 17:05:05 UTC (rev 1675) @@ -174,14 +174,6 @@
read: while ((read = getline(&line_ptr, &len, fp)) != -1) { - if (read_opt & SEARCH_ARGS) { - /* omit log lines which don't start with the correct tag */ - if (strncmp(line_ptr, SEARCH_ARGS_TAG, strlen(SEARCH_ARGS_TAG)) == 0) - break; - - continue; - } - /* the buffer will be handled elsewhere */ if (read_opt & USE_READ_BUFF) break;
Modified: trunk/batctl/functions.h =================================================================== --- trunk/batctl/functions.h 2010-05-21 17:05:04 UTC (rev 1674) +++ trunk/batctl/functions.h 2010-05-21 17:05:05 UTC (rev 1675) @@ -26,7 +26,6 @@
#define ETH_STR_LEN 17 #define BATMAN_ADV_TAG "batman-adv:" -#define SEARCH_ARGS_TAG "commands:"
/* return time delta from start to end in milliseconds */ void start_timer(void); @@ -48,6 +47,5 @@ USE_BAT_HOSTS = 0x04, LOG_MODE = 0x08, USE_READ_BUFF = 0x10, - SEARCH_ARGS = 0x20, - SILENCE_ERRORS = 0x40, + SILENCE_ERRORS = 0x20, };
Modified: trunk/batctl/main.c =================================================================== --- trunk/batctl/main.c 2010-05-21 17:05:04 UTC (rev 1674) +++ trunk/batctl/main.c 2010-05-21 17:05:05 UTC (rev 1675) @@ -123,11 +123,11 @@
} else if ((strcmp(argv[1], "interval") == 0) || (strcmp(argv[1], "it") == 0)) {
- ret = handle_sys_setting(argc - 1, argv + 1, SYS_ORIG_INTERVAL, orig_interval_usage); + ret = handle_sys_setting(argc - 1, argv + 1, SYS_ORIG_INTERVAL, orig_interval_usage, NULL);
} else if ((strcmp(argv[1], "vis_mode") == 0) || (strcmp(argv[1], "vm") == 0)) {
- ret = handle_sys_setting(argc - 1, argv + 1, SYS_VIS_MODE, vis_mode_usage); + ret = handle_sys_setting(argc - 1, argv + 1, SYS_VIS_MODE, vis_mode_usage, sysfs_param_server);
} else if ((strcmp(argv[1], "vis_data") == 0) || (strcmp(argv[1], "vd") == 0)) {
@@ -135,7 +135,7 @@
} else if ((strcmp(argv[1], "gw_mode") == 0) || (strcmp(argv[1], "gw") == 0)) {
- ret = handle_sys_setting(argc - 1, argv + 1, SYS_GW_MODE, gw_mode_usage); + ret = handle_sys_setting(argc - 1, argv + 1, SYS_GW_MODE, gw_mode_usage, sysfs_param_server);
} else if ((strcmp(argv[1], "gateways") == 0) || (strcmp(argv[1], "gwl") == 0)) {
@@ -143,11 +143,11 @@
} else if ((strcmp(argv[1], "aggregation") == 0) || (strcmp(argv[1], "ag") == 0)) {
- ret = handle_sys_setting(argc - 1, argv + 1, SYS_AGGR, aggregation_usage); + ret = handle_sys_setting(argc - 1, argv + 1, SYS_AGGR, aggregation_usage, sysfs_param_enable);
} else if ((strcmp(argv[1], "bonding") == 0) || (strcmp(argv[1], "b") == 0)) {
- ret = handle_sys_setting(argc - 1, argv + 1, SYS_BONDING, bonding_usage); + ret = handle_sys_setting(argc - 1, argv + 1, SYS_BONDING, bonding_usage, sysfs_param_enable);
} else if ((strcmp(argv[1], "bisect") == 0)) {
Modified: trunk/batctl/sys.c =================================================================== --- trunk/batctl/sys.c 2010-05-21 17:05:04 UTC (rev 1674) +++ trunk/batctl/sys.c 2010-05-21 17:05:05 UTC (rev 1675) @@ -34,6 +34,21 @@
#define PATH_BUFF_LEN 200
+const char *sysfs_param_enable[] = { + "enable", + "disable", + "1", + "0", + 0, +}; + +const char *sysfs_param_server[] = { + "off", + "client", + "server", + 0, +}; + static void interface_usage(void) { printf("Usage: batctl interface [options] [add|del iface(s)] \n"); @@ -277,11 +292,12 @@ printf(" \t -h print this help\n"); }
-int handle_sys_setting(int argc, char **argv, char *file_path, void setting_usage(void)) +int handle_sys_setting(int argc, char **argv, + char *file_path, void setting_usage(void), + const char *sysfs_param[]) { - int optchar, res; - char space_char; - char *space_ptr, *comma_char, *cmds = NULL; + int optchar; + const char **ptr;
while ((optchar = getopt(argc, argv, "h")) != -1) { switch (optchar) { @@ -297,44 +313,26 @@ if (argc == 1) return read_file(SYS_BATIF_PATH, file_path, SINGLE_READ);
- res = read_file(SYS_BATIF_PATH, file_path, SEARCH_ARGS); - if (res != EXIT_SUCCESS) - return res; + if (!sysfs_param) + goto write_file;
- while ((space_ptr = strchr_anyof(line_ptr, " \n")) != NULL) { - space_char = *space_ptr; - *space_ptr = '\0'; - comma_char = NULL; - - if (strncmp(line_ptr, SEARCH_ARGS_TAG, strlen(SEARCH_ARGS_TAG)) == 0) { - cmds = space_ptr + 1; - goto next; - } - - if (strlen(line_ptr) == 0) - goto next; - - if (line_ptr[strlen(line_ptr) - 1] == ',') { - comma_char = line_ptr + strlen(line_ptr) - 1; - *comma_char = '\0'; - } - - if (strcmp(line_ptr, argv[1]) == 0) + ptr = sysfs_param; + while (*ptr) { + if (strcmp(*ptr, argv[1]) == 0) goto write_file;
-next: - *space_ptr = space_char; - if (comma_char) - *comma_char = ','; - - line_ptr = space_ptr + 1; + ptr++; }
- if (!cmds) - goto write_file; - printf("Error - the supplied argument is invalid: %s\n", argv[1]); - printf("The following values are allowed: %s", cmds); + printf("The following values are allowed:\n"); + + ptr = sysfs_param; + while (*ptr) { + printf(" * %s\n", *ptr); + ptr++; + } + return EXIT_FAILURE;
write_file:
Modified: trunk/batctl/sys.h =================================================================== --- trunk/batctl/sys.h 2010-05-21 17:05:04 UTC (rev 1674) +++ trunk/batctl/sys.h 2010-05-21 17:05:05 UTC (rev 1675) @@ -24,7 +24,7 @@ #define SYS_BATIF_PATH "/sys/class/net/bat0/mesh/" #define SYS_LOG_LEVEL "parameters/debug" #define SYS_LOG "log" -#define SYS_AGGR "aggregate_ogm" +#define SYS_AGGR "aggregated_ogms" #define SYS_BONDING "bonding" #define SYS_GW_MODE "gw_mode" #define SYS_VIS_MODE "vis_mode" @@ -33,6 +33,9 @@ #define SYS_MESH_IFACE_FMT SYS_IFACE_PATH"/%s/batman_adv/mesh_iface" #define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status"
+extern const char *sysfs_param_enable[]; +extern const char *sysfs_param_server[]; + void aggregation_usage(void); void bonding_usage(void); void gw_mode_usage(void); @@ -41,4 +44,6 @@ int log_print(int argc, char **argv); int interface(int argc, char **argv); int handle_loglevel(int argc, char **argv); -int handle_sys_setting(int argc, char **argv, char *file_path, void setting_usage(void)); +int handle_sys_setting(int argc, char **argv, char *file_path, + void setting_usage(void), + const char *sysfs_param[]);