Author: marek Date: 2010-05-21 19:17:23 +0200 (Fri, 21 May 2010) New Revision: 1676
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/sys.c branches/batctl-0.2.x/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: branches/batctl-0.2.x/functions.c =================================================================== --- branches/batctl-0.2.x/functions.c 2010-05-21 17:05:05 UTC (rev 1675) +++ branches/batctl-0.2.x/functions.c 2010-05-21 17:17:23 UTC (rev 1676) @@ -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: branches/batctl-0.2.x/functions.h =================================================================== --- branches/batctl-0.2.x/functions.h 2010-05-21 17:05:05 UTC (rev 1675) +++ branches/batctl-0.2.x/functions.h 2010-05-21 17:17:23 UTC (rev 1676) @@ -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: branches/batctl-0.2.x/main.c =================================================================== --- branches/batctl-0.2.x/main.c 2010-05-21 17:05:05 UTC (rev 1675) +++ branches/batctl-0.2.x/main.c 2010-05-21 17:17:23 UTC (rev 1676) @@ -120,11 +120,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)) {
@@ -132,7 +132,7 @@
} 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], "bisect") == 0)) {
Modified: branches/batctl-0.2.x/sys.c =================================================================== --- branches/batctl-0.2.x/sys.c 2010-05-21 17:05:05 UTC (rev 1675) +++ branches/batctl-0.2.x/sys.c 2010-05-21 17:17:23 UTC (rev 1676) @@ -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"); @@ -263,11 +278,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) { @@ -283,44 +299,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: branches/batctl-0.2.x/sys.h =================================================================== --- branches/batctl-0.2.x/sys.h 2010-05-21 17:05:05 UTC (rev 1675) +++ branches/batctl-0.2.x/sys.h 2010-05-21 17:17:23 UTC (rev 1676) @@ -24,17 +24,22 @@ #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_VIS_MODE "vis_mode" #define SYS_ORIG_INTERVAL "orig_interval" #define SYS_IFACE_PATH "/sys/class/net" #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 vis_mode_usage(void); void orig_interval_usage(void); 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[]);