The following commit has been merged in the master branch: commit abb9eea8d7fabf0d442d3e90d38c2a2ddafda114 Author: Marek Lindner lindner_marek@yahoo.de Date: Sat Jun 16 03:39:41 2012 +0800
batctl: check interface support and print corresponding error message
Signed-off-by: Marek Lindner lindner_marek@yahoo.de
diff --git a/functions.c b/functions.c index 8ce2419..36a4d40 100644 --- a/functions.c +++ b/functions.c @@ -107,6 +107,13 @@ char *get_name_by_macstr(char *mac_str, int read_opt) return get_name_by_macaddr(mac_addr, read_opt); }
+int file_exists(const char *fpath) +{ + struct stat st; + + return stat(fpath, &st) == 0; +} + static int check_sys_dir(char *dir) { struct stat st; diff --git a/functions.h b/functions.h index fe03dc0..92d6ae5 100644 --- a/functions.h +++ b/functions.h @@ -33,6 +33,7 @@ double end_timer(void); char *ether_ntoa_long(const struct ether_addr *addr); 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); int write_file(char *dir, char *fname, char *arg1, char *arg2); diff --git a/main.h b/main.h index 872a2fe..4819cf4 100644 --- a/main.h +++ b/main.h @@ -28,3 +28,5 @@ #define EXIT_NOSUCCESS 2
#define __packed __attribute((packed)) /* linux kernel compat */ + +extern char module_ver_path[]; diff --git a/sys.c b/sys.c index 0b4cac3..5702c6c 100644 --- a/sys.c +++ b/sys.c @@ -154,6 +154,23 @@ int interface(char *mesh_iface, int argc, char **argv) for (i = 2; i < argc; i++) { snprintf(path_buff, PATH_BUFF_LEN, SYS_MESH_IFACE_FMT, argv[i]);
+ if (!file_exists(path_buff)) { + snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_DIR, argv[i]); + + if (!file_exists(path_buff)) { + printf("Error - interface does not exist: %s\n", argv[i]); + continue; + } + + if (!file_exists(module_ver_path)) { + printf("Error - batman-adv module has not been loaded\n"); + goto err; + } + + printf("Error - interface type not supported by batman-adv: %s\n", argv[i]); + continue; + } + if (argv[1][0] == 'a') res = write_file("", path_buff, mesh_iface, NULL); else diff --git a/sys.h b/sys.h index 46a1159..f48902e 100644 --- a/sys.h +++ b/sys.h @@ -32,6 +32,7 @@ #define SYS_VIS_MODE "vis_mode" #define SYS_ORIG_INTERVAL "orig_interval" #define SYS_IFACE_PATH "/sys/class/net" +#define SYS_IFACE_DIR SYS_IFACE_PATH"/%s/" #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" #define SYS_FRAG "fragmentation"