What's new

My experience with the RT-AC86U

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

wl wrapper

Bash:
#!/bin/sh

# copy original wl executable to /tmp
cp /usr/sbin/wl /tmp/_wl

# create wl wrapper that calls original wl executable in /tmp
cat << 'EOF' > /tmp/wl
#!/bin/sh
#set -x # comment/uncomment to disable/enable debug mode
# required for serialization when reentry is possible
LOCK="/tmp/$(basename "$0").lock"
acquire_lock() { until mkdir "$LOCK" &>/dev/null; do touch /tmp/wl; done; }
release_lock() { rmdir "$LOCK" &>/dev/null; }

# one instance at a time
acquire_lock

# catch premature exit and cleanup
trap 'release_lock; exit 1' SIGHUP SIGINT SIGTERM

# make the new function accessible
#export PATH=/opt/bin:/opt/sbin:$PATH

# clear rc variable
rc=""

# keep count of total session usage
if [ ! -f "/tmp/wluse" ]; then
   echo 0 > /tmp/wluse
fi
usecount=$(cat /tmp/wluse)
usecount=$((usecount + 1 ))
echo $usecount > /tmp/wluse

#INTERVAL="100"
MAXCOUNT="3"
run_cmd () {
    local to
    local start
    local child
    # here as the interval number increases, the longer we wait..
    to="$1"
    to="$((to*INTERVAL))"; shift
    $@ & local child="$!" start=0
    touch /tmp/wl
    while { [ "$(kill -0 $child >/dev/null 2>&1; printf "%s" "$?")" = "0" ] && [ "$start" -le "$to" ]; }; do
        # to account for killing too soon, as the number of tries required increases our count requirement increases before we attempt to kill the process.
        touch /tmp/wl
        start="$((start+1))"
        if [ $start -gt $to ]; then
            kill -s 9 $child 2>/dev/null
            wait $child
            return 1
        fi
    done
    return 0
}

for INTERVAL in 25 50 75 100; do
# make the new function accessible, on the first run we want to exit right away if successful.
i="1"
if { run_cmd "$i" /tmp/_wl "$@"; }; then
  rc="0"
else
  rc="1"
fi
logger -t "wl-override" "Executed wl $@ (at $INTERVAL), use count: $usecount, exit status: $rc"
# here we add an interval check and allow up to 3 retries.
while [ "$i" -le "$MAXCOUNT" ] && [ "$rc" != "0" ]; do
  touch /tmp/wl
  if { run_cmd "$i" /tmp/_wl "$@"; }; then
    rc="0"
  else
    rc="1"
    errcount="$rc"
    if [ ! -f "/tmp/wlerr" ]; then
       echo 0 > /tmp/wlerr
    else
       errcount=$(cat /tmp/wlerr)
    fi
    errcount=$((errcount + 1 ))
    echo $errcount > /tmp/wlerr
    logger -t "wl-override" "Error detected at use count: $usecount (at $INTERVAL), error count: $errcount"
    logger -t "wl-override" "Couldn't execute wl $@ (at $INTERVAL), exit status: $rc (124=timeout)"
  fi
  logger -t "wl-override" "Retried executing wl $@ (at $INTERVAL), attempt ${i}/${MAXCOUNT}, exit status: $rc"
  i="$((i+1))"
done
[ "$rc" = "0" ] && break || logger -t "wl-override" "wl remained locked too long; continuing anyway."
done
# any concurrent instance(s) may now run
release_lock

exit $rc
EOF
chmod +x /tmp/wl

# replace wl in /usr/sbin w/ wl wrapper in /tmp
mount -o bind /tmp/wl /usr/sbin/wl

So if I understand the code correctly, this script does not loop continuously, but instead, somehow replaces wl and then tells wl to run after setting conditions that help to ensure (but don't guarantee) that wl will run successfully. Is that correct?
 
So if I understand the code correctly, this script does not loop continuously, but instead, somehow replaces wl and then tells wl to run after setting conditions that help to ensure (but don't guarantee) that wl will run successfully. Is that correct?
For me, this is pretty old stuff. I'd have to sit down, play with it, and get back with you. When I tried this out, I was not having any of these issues so I had to devise away to create a "stuck" condition. I suggest reading through the thread on the people who actually had this problem and tested using this wrapper. IIRC it is a somewhat effective method that does not require entware binaries or dependencies. The other method was to incorporate timeout which required entware binaries. In comparison, the wrapper was pretty effective. YMMV.
 
For me, this is pretty old stuff. I'd have to sit down, play with it, and get back with you. When I tried this out, I was not having any of these issues so I had to devise away to create a "stuck" condition. I suggest reading through the thread on the people who actually had this problem and tested using this wrapper. IIRC it is a somewhat effective method that does not require entware binaries or dependencies. The other method was to incorporate timeout which required entware binaries. In comparison, the wrapper was pretty effective. YMMV.

Yes, this script is the one that does not require entware. Working fine. Even with all the logging enabled, it has essentially no effect router performance. I'm somewhat surprised no one seems to have interest in this anymore. I thought a lot of the people running scripts would want to use this fix.
 
Hi guys,

I’m an novice at this and would like to request a step by step guide please for dumbkoff’s like me lol to implement this script if it’s possible?

Thank you for your hard work guys but a lot of this goes over my head though do try to learn and make sense of what I can and the pastebin link is very hard to follow.

Thanks again

Sub
 
Hi guys,

I’m an novice at this and would like to request a step by step guide please for dumbkoff’s like me lol to implement this script if it’s possible?

Thank you for your hard work guys but a lot of this goes over my head though do try to learn and make sense of what I can and the pastebin link is very hard to follow.

Thanks again

Sub

If you aren't running scripts, there may not be much value to using this script. I only run a few simple scripts, and the only thing this script seems to be catching is wl getting stuck on some commands related to channel quality surveys. No issues with nvram.

However, if you want to run this script, you pretty much just need to copy-paste the script I listed in post #382 into the JFFS/scripts folder, make it executable, and the run it from the command line. If you want to have it run automatically at boot, then you'll need to add a cron job to services-start. I think your immediate goal should be just getting it to run. Then can worry about adding it to services-start.
 
If you aren't running scripts, there may not be much value to using this script. I only run a few simple scripts, and the only thing this script seems to be catching is wl getting stuck on some commands related to channel quality surveys. No issues with nvram.

However, if you want to run this script, you pretty much just need to copy-paste the script I listed in post #382 into the JFFS/scripts folder, make it executable, and the run it from the command line. If you want to have it run automatically at boot, then you'll need to add a cron job to services-start. I think your immediate goal should be just getting it to run. Then can worry about adding it to services-start.

Ok, thank you. I’ll start with that first and the scripts I use are FlexQOS and Skynet, or are these addons and not scripts?
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top