Browse Source

functions.sh: Also check for -c support in 'stat' before using

Turns out it's not enough to check for the presence of the 'stat' binary;
OpenWrt also by default compiles it without support for the -c option. So
add a check for the option as well and bail out if it doesn't work.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
Toke Høiland-Jørgensen 1 year ago
parent
commit
54131540c8
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/functions.sh

+ 4 - 3
src/functions.sh

@@ -277,9 +277,10 @@ check_state_dir() {
         exit 1
     fi
 
-    # OpenWrt doesn't have stat; for now just skip the remaining tests if it's
-    # not available
-    command -v stat >/dev/null 2>&1 || return 0
+    # OpenWrt doesn't have stat by default, and if it does have it, stat is
+    # usually built without support for the -c parameter. Check for these and
+    # skip the remaining tests if we don't have a usable 'stat' binary.
+    (command -v stat && stat -c '%a' /) >/dev/null 2>&1 || return 0
 
     PERM="0$(stat -L -c '%a' "${SQM_STATE_DIR}")"
     if [ "$((PERM & 0002))" -ne 0 ]; then