File: ifplugd.udev.agent

package info (click to toggle)
ifplugd 0.28-19.4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,472 kB
  • sloc: ansic: 2,068; sh: 1,454; makefile: 134
file content (86 lines) | stat: -rw-r--r-- 2,192 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
# udev agent script

if [ -z "$INTERFACE" ]; then
    echo 'Bad invocation: $INTERFACE is not set' >&2
    exit 1
fi

DAEMON_NAME=ifplugd
DAEMON=/usr/sbin/$DAEMON_NAME
if [ ! -x $DAEMON ]; then
    echo "No $DAEMON_NAME executable: $DAEMON" >&2
    exit 1
fi

CFG=/etc/default/$DAEMON_NAME
if [ -f $CFG ]; then
    . $CFG
else
    echo "No $DAEMON_NAME configuration file" >&2
    exit 1
fi

# return true (0) if searchifc ($1) is in argument list ($@)
# return false (1) otherwise
search_interfaces () {
    searchifc=$1
    shift

    for i in $@; do
        if [ "$i" = "$searchifc" ] || [ "$i" = "all" ]; then
            return 0
        fi
    done

    return 1
}

# wait for networking to be available, taken from net.agent (ifupdown)
wait_for_interface () {
    waitifc=$1

    while :; do
        ifcstate="$(cat /sys/class/net/${waitifc}/operstate 2>/dev/null || true)"
        if [ "$ifcstate" != down ]; then
                return 0
        fi
        sleep 1
    done
}

ifplugd_daemon () {
    search_interfaces "$INTERFACE" $INTERFACES
    if [ $? -gt 0 ]; then
        # Interface isn't statically managed by ifplugd
        search_interfaces "$INTERFACE" $HOTPLUG_INTERFACES
        if [ $? -eq 0 ]; then
            # Interface is in hotplug allowed list
            case "$ACTION" in
            add|register)
                logger -t ifplugd -p daemon.debug "Invoking $DAEMON_NAME for $INTERFACE"

                # check for interface specific arguments
                IF1=$(echo $INTERFACE | sed "s/-/_/")
                A=$(eval echo \$\{ARGS_${IF1}\})
                [ -z "$A" ] && A="$ARGS"

                # wait for loopback interface to exist, we may have
                # been invoked very early in boot sequence
                wait_for_interface lo

                # spawn ifplugd daemon
                exec $DAEMON -i $INTERFACE $A
                ;;
            remove|unregister)
                logger -t ifplugd -p daemon.debug "Stopping $DAEMON_NAME for $INTERFACE"

                # kill a running ifplugd daemon
                exec $DAEMON -k -i $INTERFACE
                ;;
            esac
        fi
    fi
}

ifplugd_daemon &