batctl: check interface support and print corresponding error message
Commit Message
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
functions.c | 7 +++++++
functions.h | 1 +
main.h | 2 ++
sys.c | 17 +++++++++++++++++
sys.h | 1 +
5 files changed, 28 insertions(+), 0 deletions(-)
Comments
On Friday, June 15, 2012 21:39:41 Marek Lindner wrote:
> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
> ---
> functions.c | 7 +++++++
> functions.h | 1 +
> main.h | 2 ++
> sys.c | 17 +++++++++++++++++
> sys.h | 1 +
> 5 files changed, 28 insertions(+), 0 deletions(-)
Applied in revision abb9eea.
Regards,
Marek
@@ -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;
@@ -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);
@@ -28,3 +28,5 @@
#define EXIT_NOSUCCESS 2
#define __packed __attribute((packed)) /* linux kernel compat */
+
+extern char module_ver_path[];
@@ -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
@@ -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"