Skip to content

openconnect: off-by-0=true and 1=false logic #28015

@chunkeey

Description

@chunkeey

Package Name

openconnect

Maintainer

@nmav

OpenWrt Version

SNAPSHOT

OpenWrt Target/Subtarget

all

Steps to Reproduce

while resolveip -t 10 "$server" > "$tmpfile" && [ "$trials" -gt 0 ]; do
sleep 5
trials=$((trials - 1))
done

This took me a really long time to finally understand. But there's a subtle error hiding in plain sight here, that needlessly delays the startup of openconnect (i.e. all tries are exhausted on a system with a working connection).

The issue is that while-loop continues to run if resolveip -t 10 "$server" succeeds (i.e. it returns with 0). But it should stop once it was successful resolving the IP address.

I found that I also suck at explaining things. So please entertain this reproducer example:

while resolveip google.com; do echo repeat; sleep 1;done
We expect that on a system connected to the internet, this should not print "repeat" even once.
But when testing, it will endlessly repeat "repeat" unless it can't resolve the address:

142.251.36.174
repeat
142.251.36.174
repeat
142.251.36.174
repeat
...

whereas adding the "!" in front of resolveip:
while ! resolveip google.com; do echo repeat; sleep 1;done
Will do just what we all want in the same circumstance described above.
The problem here is that this now "looks odd".

From what I can tell, this issue came about in commit:
20ea726

But it's already really late, so sorry for not providing the fix myself at this moment.

Actual Behaviour

Not delay openconnects startup.

Confirmation Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions