[PATCH] batctl: don't stop on missing batman-adv version file

Sven Eckelmann <[email protected]>
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
The system doesn't have to expose the /sys/module/batman_adv/version to the
userspace. This can either happen because:

* batman-adv was not loaded
* container doesn't expose the root namespace's /sys/modules
* distribution (like OpenWrt with `CONFIG_MODULE_STRIPPED`) decided to
  strip out this information and therefore the file
* kernel removed the version support at all
* ...

The check does therefore more harm and is not helping a lot to identify the
a missing batman-adv kernel module.

Signed-off-by: Sven Eckelmann <[email protected]>
---
 functions.c | 12 ------------
 functions.h |  1 -
 interface.c | 11 -----------
 main.c      |  4 ++--
 main.h      |  2 --
 5 files changed, 2 insertions(+), 28 deletions(-)

diff --git a/functions.c b/functions.c
index f7a3080..771b065 100644
--- a/functions.c
+++ b/functions.c
@@ -110,20 +110,8 @@ 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 void file_open_problem_dbg(const char *full_path)
 {
-	if (!file_exists(module_ver_path)) {
-		fprintf(stderr, "Error - batman-adv module has not been loaded\n");
-		return;
-	}
-
 	fprintf(stderr, "Error - can't open file '%s': %s\n", full_path, strerror(errno));
 	fprintf(stderr,
 		"The option you called seems not to be compiled into your batman-adv kernel module.\n");
diff --git a/functions.h b/functions.h
index 33b57da..c2ce1b8 100644
--- a/functions.h
+++ b/functions.h
@@ -42,7 +42,6 @@ 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(const char *full_path, int read_opt);
 struct ether_addr *translate_mac(struct state *state,
 				 const struct ether_addr *mac);
diff --git a/interface.c b/interface.c
index dfe5ad4..dc77ad4 100644
--- a/interface.c
+++ b/interface.c
@@ -154,11 +154,6 @@ static int print_interfaces(struct state *state)
 {
 	int ret;
 
-	if (!file_exists(module_ver_path)) {
-		fprintf(stderr, "Error - batman-adv module has not been loaded\n");
-		return EXIT_FAILURE;
-	}
-
 	/* duplicated code here from the main() because interface doesn't always
 	 * need COMMAND_FLAG_MESH_IFACE and COMMAND_FLAG_NETLINK
 	 */
@@ -524,12 +519,6 @@ static int interface(struct state *state, int argc, char **argv)
 		goto err;
 	}
 
-	/* make sure that batman-adv is loaded or was loaded by create_interface */
-	if (!file_exists(module_ver_path)) {
-		fprintf(stderr, "Error - batman-adv module has not been loaded\n");
-		goto err;
-	}
-
 	pre_cnt = count_interfaces(state->mesh_iface);
 
 	for (i = 1; i < rest_argc; i++) {
diff --git a/main.c b/main.c
index 9516dee..921b3af 100644
--- a/main.c
+++ b/main.c
@@ -20,7 +20,7 @@
 #include "netlink.h"
 
 char mesh_dfl_iface[] = "bat0";
-char module_ver_path[] = "/sys/module/batman_adv/version";
+static const char module_ver_path[] = "/sys/module/batman_adv/version";
 
 extern const struct command *__start___command[];
 extern const struct command *__stop___command[];
@@ -138,7 +138,7 @@ static void version(void)
 	if (ret == EXIT_SUCCESS)
 		printf("%s]\n", line_ptr);
 	else
-		printf("module not loaded]\n");
+		printf("module version unknown]\n");
 
 	free(line_ptr);
 	exit(EXIT_SUCCESS);
diff --git a/main.h b/main.h
index bbac4c2..e6a08d3 100644
--- a/main.h
+++ b/main.h
@@ -33,8 +33,6 @@
 #define __maybe_unused __attribute__((unused))
 #define BIT(nr)                 (1UL << (nr)) /* linux kernel compat */
 
-extern char module_ver_path[];
-
 #ifndef VLAN_VID_MASK
 #define VLAN_VID_MASK   0xfff
 #endif

---
base-commit: a77a273d30a2fff8027e0b2382b4759740435f8c
change-id: 20260515-no-version-file-check-7f5b797c430c

Best regards,
--  
Sven Eckelmann <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.