Skip to content
This repository was archived by the owner on Jan 5, 2025. It is now read-only.

Commit 238d47b

Browse files
committed
Improve handling of interface waiting with single argument
The previous code wasn't using $# to count the number of arguments, which triggered the interface waiting code for any number of arguments. The interface waiting code is not run if the single parameter is the name of a file found in $PATH. Minor code cleanup.
1 parent 94b2a3c commit 238d47b

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

util/entrypoint.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
#!/bin/bash
2+
23
set -e
34

5+
6+
init="/usr/bin/dumb-init"
7+
48
# Single argument to command line is interface name
5-
if [ -n "$1" ]; then
6-
# loop until interface is found, or we give up
7-
NEXT_WAIT_TIME=1
8-
until [ -e "/sys/class/net/$1" ] || [ $NEXT_WAIT_TIME -eq 4 ]; do
9-
sleep $(( NEXT_WAIT_TIME++ ))
10-
echo "Waiting for $1 to become available.... ${NEXT_WAIT_TIME}"
11-
done
12-
if [ -e "/sys/class/net/$1" ]; then
13-
IFACE=$1
9+
if [ $# -eq 1 -a -n "$1" ]; then
10+
# skip wait-for-interface behavior if found in path
11+
if ! which "$1" >/dev/null; then
12+
# loop until interface is found, or we give up
13+
NEXT_WAIT_TIME=1
14+
until [ -e "/sys/class/net/$1" ] || [ $NEXT_WAIT_TIME -eq 4 ]; do
15+
sleep $(( NEXT_WAIT_TIME++ ))
16+
echo "Waiting for interface '$1' to become available... ${NEXT_WAIT_TIME}"
17+
done
18+
if [ -e "/sys/class/net/$1" ]; then
19+
IFACE="$1"
20+
fi
1421
fi
1522
fi
1623

@@ -19,8 +26,6 @@ if [ -z "$1" ]; then
1926
IFACE=" "
2027
fi
2128

22-
init="/usr/bin/dumb-init"
23-
2429
if [ -n "$IFACE" ]; then
2530
# Run dhcpd for specified interface or all interfaces
2631

0 commit comments

Comments
 (0)