Ver código fonte

Silence errors when running during boot.

Oftentimes, the configured interface will not be available during boot,
and so we will output an error message. This is fine, as the script will
be re-run later by hotplug, but it gives misleading error messages in
the boot logs. However, we can't get rid of the start-at-boot entirely,
since there can be cases where no hotplug event will be sent for an
interface (e.g. bridge interfaces). So instead, we just silence errors
during boot.

This adds an SQM_VERBOSITY_MIN setting (and renames the old
SQM_VERBOSITY to SQM_VERBOSITY_MAX), and sets it during boot in the init
script.

Closes #46.
Toke Høiland-Jørgensen 7 anos atrás
pai
commit
1202ada922
5 arquivos alterados com 18 adições e 9 exclusões
  1. 4 4
      README.md
  2. 6 0
      platform/openwrt/sqm-init
  3. 3 1
      src/defaults.sh
  4. 2 2
      src/functions.sh
  5. 3 2
      src/run-openwrt.sh

+ 4 - 4
README.md

@@ -47,7 +47,7 @@ Note this method relies on the presence of the required qdiscs on the router/des
 
 ## Run-time debugging
 
-SQM_VERBOSITY controls the verbosity of sqm's output to the shell and syslog (0: no logging; 8: full debug output).
+SQM_VERBOSITY_MAX controls the verbosity of sqm's output to the shell and syslog (0: no logging; 8: full debug output).
 SQM_DEBUG controls whether sqm will log all binary invocations, their output and its shell output into a log file in `/var/run/sqm`.
 The log files are named `/var/run/sqm/${interface_name}.debug.log` e.g. `/var/run/sqm/pppoe-ge00.debug.log`.
 
@@ -55,15 +55,15 @@ The log files are named `/var/run/sqm/${interface_name}.debug.log` e.g. `/var/ru
 
 - Log only the binary invocations and their output:
 
-    `/etc/init.d/sqm stop ; SQM_DEBUG=1 SQM_VERBOSITY=0 /etc/init.d/sqm start`
+    `/etc/init.d/sqm stop ; SQM_DEBUG=1 SQM_VERBOSITY_MAX=0 /etc/init.d/sqm start`
 
 - Log verbose debug output and all the binary invocations and their output:
 
-    `/etc/init.d/sqm stop ; SQM_DEBUG=1 SQM_VERBOSITY=8 /etc/init.d/sqm start`
+    `/etc/init.d/sqm stop ; SQM_DEBUG=1 SQM_VERBOSITY_MAX=8 /etc/init.d/sqm start`
 
 - Log both start and stop:
 
-    `SQM_DEBUG=1 SQM_VERBOSITY=8 /etc/init.d/sqm stop ; SQM_DEBUG=1 SQM_VERBOSITY=8 /etc/init.d/sqm start`
+    `SQM_DEBUG=1 SQM_VERBOSITY_MAX=8 /etc/init.d/sqm stop ; SQM_DEBUG=1 SQM_VERBOSITY_MAX=8 /etc/init.d/sqm start`
 
 Note: This always appends to the log file(s). If you just run a one-off
 command with debugging enabled from the command line this is fine, but

+ 6 - 0
platform/openwrt/sqm-init

@@ -21,3 +21,9 @@ stop()
 {
     /usr/lib/sqm/run.sh stop
 }
+
+boot()
+{
+    export SQM_VERBOSITY_MIN=5 # Silence errors
+    /usr/lib/sqm/run.sh start
+}

+ 3 - 1
src/defaults.sh

@@ -44,7 +44,9 @@ VERBOSITY_WARNING=2
 VERBOSITY_INFO=5
 VERBOSITY_DEBUG=8
 VERBOSITY_TRACE=10
-[ -z "$SQM_VERBOSITY" ] && SQM_VERBOSITY=$VERBOSITY_INFO
+[ -z "$SQM_VERBOSITY_MAX" ] && SQM_VERBOSITY_MAX=$VERBOSITY_INFO
+# For silencing only errors
+[ -z "$SQM_VERBOSITY_MIN" ] && SQM_VERBOSITY_MIN=$VERBOSITY_SILENT
 
 [ -z "$SQM_DEBUG" ] && SQM_DEBUG=0
 if [ "$SQM_DEBUG" -eq "1" ]

+ 2 - 2
src/functions.sh

@@ -27,7 +27,7 @@ sqm_logger() {
         *) LEVEL=$1; shift ;;
     esac
 
-    if [ "$SQM_VERBOSITY" -ge "$LEVEL" ] ; then
+    if [ "$SQM_VERBOSITY_MAX" -ge "$LEVEL" ] && [ "$SQM_VERBOSITY_MIN" -le "$LEVEL" ] ; then
         if [ "$SQM_SYSLOG" -eq "1" ]; then
             logger -t SQM -s "$*"
         else
@@ -36,7 +36,7 @@ sqm_logger() {
     fi
     # slightly dangerous as this will keep adding to the log file
     if [ -n "${SQM_DEBUG}" -a "${SQM_DEBUG}" -eq "1" ]; then
-        if [ "$SQM_VERBOSITY" -ge "$LEVEL" -o "$LEVEL" -eq "$VERBOSITY_TRACE" ]; then
+        if [ "$SQM_VERBOSITY_MAX" -ge "$LEVEL" -o "$LEVEL" -eq "$VERBOSITY_TRACE" ]; then
             echo "$@" >> ${SQM_DEBUG_LOG}
         fi
     fi

+ 3 - 2
src/run-openwrt.sh

@@ -61,10 +61,11 @@ run_sqm_scripts() {
     export SCRIPT=$(config_get "$section" script)
 
 
-    #sm: if SQM_DEBUG or SQM_VERBOSITY were passed in via the command line make them available to the other scripts
+    #sm: if SQM_DEBUG or SQM_VERBOSITY_* were passed in via the command line make them available to the other scripts
     #	this allows to override sqm's log level as set in the GUI for quick debugging without GUI accesss.
     [ -n "$SQM_DEBUG" ] && export SQM_DEBUG || export SQM_DEBUG=$(config_get "$section" debug_logging)
-    [ -n "$SQM_VERBOSITY" ] && export SQM_VERBOSITY || export SQM_VERBOSITY=$(config_get "$section" verbosity)
+    [ -n "$SQM_VERBOSITY_MAX" ] && export SQM_VERBOSITY_MAX || export SQM_VERBOSITY_MAX=$(config_get "$section" verbosity)
+    [ -n "$SQM_VERBOSITY_MIN" ] && export SQM_VERBOSITY_MIN
 
     #sm: only stop-sqm if there is something running
     CUR_STATE_FILE="${SQM_STATE_DIR}/${IFACE}.state"