From patchwork Fri Jun 15 19:39:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 2016 Return-Path: Received: from nm24.bullet.mail.ukl.yahoo.com (nm24.bullet.mail.ukl.yahoo.com [217.146.177.233]) by open-mesh.org (Postfix) with SMTP id ACFB26007DD for ; Fri, 15 Jun 2012 21:39:50 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key; insecure key) header.i=@yahoo.de; dkim-adsp=pass Received: from [217.146.183.211] by nm24.bullet.mail.ukl.yahoo.com with NNFMP; 15 Jun 2012 19:39:49 -0000 Received: from [77.238.184.64] by tm4.bullet.mail.ukl.yahoo.com with NNFMP; 15 Jun 2012 19:39:49 -0000 Received: from [127.0.0.1] by smtp133.mail.ukl.yahoo.com with NNFMP; 15 Jun 2012 19:39:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1339789189; bh=vsVKWyRq6XetZ+AbHc6ZJr5EgtTubmXaOyxkgWQR+j8=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer; b=UEcVtcUYwZB/r9vh6j5dBzal1EoFXvuOJCNKNESZEW71glVZklPED1GAkhi+36nTiJWUwCANeYeBxhGyAfV2QzicWr98X72qQWSCMd9CDqOyQRCoNzv+b5cRQD9rY34WJvWw76s7Nzfq6v6xE5sDeFoKMvGlaWsmEioMH5zAr34= X-Yahoo-Newman-Id: 929335.14947.bm@smtp133.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: PLbtYo8VM1kj7WzorAMHhIj2EbDQF3wHj2zNGp7clCCiO8A zrw2CVYbnb3H4glStK_elIVvlPCcR8FkLaIauUVwHsSc8UaCIRHuaaYICLyK T3Jjq.NLnxezpGf164DGGRktk73yZfeayFrizYWbCqkhidCSzr6D0ohC2ndT Nd4j.df8aslK0n8GDpL0pDAQWG8FH_5rX1wKdfF1VMgX7QZm8Abs3Q6SLtHH kGeMofQdo9kN5c5zxngAALebv1ienOs79SKi6sR5vTP.UA_GEYk8ByEiRK5q ur9HnQyChynO8CT7K4FB9Z583ve1MG_FAw.qaCjZ.lvFNkS2vD7_51Ijx2dZ mrDaDc.Dgh6GS0S9_xUentKTv1Y9J2KHpA4F4PiowLNsgl_m2CsmSxc.h81s eBW449bv7lfUgIJfI2c_5w5E45eK0TDTClaLCxgsYsqiJ9ycJ22w.IO4PENP A55pP9A-- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@210.177.7.38 with plain) by smtp133.mail.ukl.yahoo.com with SMTP; 15 Jun 2012 19:39:48 +0000 GMT From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Sat, 16 Jun 2012 03:39:41 +0800 Message-Id: <1339789181-27122-1-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.9.1 Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH] batctl: check interface support and print corresponding error message X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2012 19:39:50 -0000 Signed-off-by: Marek Lindner --- functions.c | 7 +++++++ functions.h | 1 + main.h | 2 ++ sys.c | 17 +++++++++++++++++ sys.h | 1 + 5 files changed, 28 insertions(+), 0 deletions(-) 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"