wl: only invoke nvram executable if it exists
authorJo-Philipp Wich <jo@mein.io>
Tue, 31 Jul 2018 18:09:02 +0000 (20:09 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 31 Jul 2018 18:09:02 +0000 (20:09 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
iwinfo_wl.c

index c7517ecea661b6f753700288917d17c4f8ac7093..80d3d7eec3e0fc8c077453a67d16832dd32ec705 100644 (file)
@@ -18,6 +18,9 @@
  * This code is based on the wlc.c utility published by OpenWrt.org .
  */
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include "iwinfo.h"
 #include "api/broadcom.h"
 
@@ -702,15 +705,19 @@ static int wl_get_txpower_offset(const char *ifname, int *buf)
 {
        FILE *p;
        char off[8];
+       struct stat s;
 
        *buf = 0;
 
-       if ((p = popen("/usr/sbin/nvram get opo", "r")) != NULL)
+       if (!stat("/usr/sbin/nvram", &s) && (s.st_mode & S_IXUSR))
        {
-               if (fread(off, 1, sizeof(off), p))
-                       *buf = strtoul(off, NULL, 16);
+               if ((p = popen("/usr/sbin/nvram get opo", "r")) != NULL)
+               {
+                       if (fread(off, 1, sizeof(off), p))
+                               *buf = strtoul(off, NULL, 16);
 
-               pclose(p);
+                       pclose(p);
+               }
        }
 
        return 0;