Debian Codegraph @

testing/guestbin/wait-until-pluto-started

raw
1 #!/bin/sh
2
3 # Wait until both whack can talk to pluto and the addconn process has
4 # has finished adding connections, i.e., until pluto has started.
5
6 # Stop systemctl going all graphical
7 LC_CTYPE=C
8 export LC_CTYPE
9
10 # When pluto starts it does:
11 #
12 # - creates whack socket
13 # -> whack requests will block
14 # - vfork() then exec(addconn)
15 # -> addconn is added to pluto's process list
16 # - starts event loop
17 # -> (blocked) whack requests will be processed
18 #
19 # This code checks things in reverse:
20 #
21 # - queries pluto for a process list
22 # -> so it waits until the event loop is running
23 # and addconn has been started
24 # - checks the process list for addconn
25 # -> so it waits until addconn has finished
26
27 echo ==== cut ====
28
29 count=10
30 while count=$(expr $count - 1) && test $count -gt 0 ; do
31 # both need to attach ...
32 if ps=$(ipsec whack --processstatus) ; then
33 echo "${ps}"
34 # ... and not find addconn
35 if echo "${ps}" | grep addconn ; then
36 echo try again
37 else
38 echo addconn exited
39 break
40 fi
41 fi
42 sleep 1
43 done
44
45 echo ==== tuc ====
46
47 # what took so long?
48 if test $count -eq 0 ; then
49 echo giving up
50 if echo $SUDO_COMMAND | grep "/bin/nsenter " > /dev/null 2>&1 ; then
51 echo "pluto in namespace failed to start - check logs or output"
52 else
53 systemctl --full status ipsec.service
54 fi
55 fi