Blame SOURCES/clevis-7-retry.patch

9fc9a3
From 2a82ba4040c8dc10dcbe7e2c3ae6646c2778f0b1 Mon Sep 17 00:00:00 2001
9fc9a3
From: Nathaniel McCallum <npmccallum@redhat.com>
9fc9a3
Date: Tue, 16 Jan 2018 13:29:54 -0500
9fc9a3
Subject: [PATCH] Retry until success during systemd boot
9fc9a3
9fc9a3
With dracut, we just try once because we're being called in a loop. But with
9fc9a3
systemd, there might be a race condition for network to come up. So when
9fc9a3
running under systemd, we loop until success. This should not change the dracut
9fc9a3
behavior.
9fc9a3
---
9fc9a3
 src/systemd/clevis-luks-askpass            | 66 ++++++++++++++++++++----------
9fc9a3
 src/systemd/clevis-luks-askpass.service.in |  2 +-
9fc9a3
 2 files changed, 46 insertions(+), 22 deletions(-)
9fc9a3
9fc9a3
diff --git a/src/systemd/clevis-luks-askpass b/src/systemd/clevis-luks-askpass
9fc9a3
index 2fadd5c..6fe5269 100755
9fc9a3
--- a/src/systemd/clevis-luks-askpass
9fc9a3
+++ b/src/systemd/clevis-luks-askpass
9fc9a3
@@ -23,26 +23,50 @@ UUID=cb6e8904-81ff-40da-a84a-07ab9ab5715e
9fc9a3
 
9fc9a3
 shopt -s nullglob
9fc9a3
 
9fc9a3
-for question in /run/systemd/ask-password/ask.*; do
9fc9a3
-    d=
9fc9a3
-    s=
9fc9a3
-
9fc9a3
-    while read line; do
9fc9a3
-        case "$line" in
9fc9a3
-            Id=cryptsetup:*) d="${line##Id=cryptsetup:}";;
9fc9a3
-            Socket=*) s="${line##Socket=}";;
9fc9a3
-        esac
9fc9a3
-    done < "$question"
9fc9a3
-
9fc9a3
-    [ -z "$d" -o -z "$s" ] && continue
9fc9a3
-
9fc9a3
-    luksmeta show -d "$d" | while read -r slot state uuid; do
9fc9a3
-        [ "$state" != "active" ] && continue
9fc9a3
-        [ "$uuid" != "$UUID" ] && continue
9fc9a3
-
9fc9a3
-        if pt="`luksmeta load -d $d -s $slot -u $UUID | clevis decrypt`"; then
9fc9a3
-            echo -n "+$pt" | nc -U -u --send-only "$s"
9fc9a3
-            break
9fc9a3
-        fi
9fc9a3
+while getopts ":l" o; do
9fc9a3
+    case "$o" in
9fc9a3
+    l) loop=true;;
9fc9a3
+    esac
9fc9a3
+done
9fc9a3
+
9fc9a3
+while true; do
9fc9a3
+    todo=0
9fc9a3
+
9fc9a3
+    for question in /run/systemd/ask-password/ask.*; do
9fc9a3
+        metadata=false
9fc9a3
+        unlocked=false
9fc9a3
+        d=
9fc9a3
+        s=
9fc9a3
+
9fc9a3
+        while read line; do
9fc9a3
+            case "$line" in
9fc9a3
+                Id=cryptsetup:*) d="${line##Id=cryptsetup:}";;
9fc9a3
+                Socket=*) s="${line##Socket=}";;
9fc9a3
+            esac
9fc9a3
+        done < "$question"
9fc9a3
+
9fc9a3
+        [ -z "$d" -o -z "$s" ] && continue
9fc9a3
+
9fc9a3
+        while read -r slot state uuid; do
9fc9a3
+            [ "$state" != "active" ] && continue
9fc9a3
+            [ "$uuid" != "$UUID" ] && continue
9fc9a3
+            metadata=true
9fc9a3
+
9fc9a3
+            if pt="`luksmeta load -d $d -s $slot -u $UUID | clevis decrypt`"; then
9fc9a3
+                echo -n "+$pt" | nc -U -u --send-only "$s"
9fc9a3
+                unlocked=true
9fc9a3
+                break
9fc9a3
+            fi
9fc9a3
+        done < <(luksmeta show -d "$d")
9fc9a3
+
9fc9a3
+        [ $metadata == true ] || continue
9fc9a3
+        [ $unlocked == true ] && continue
9fc9a3
+        todo=$((todo + 1))
9fc9a3
     done
9fc9a3
+
9fc9a3
+    if [ $todo -eq 0 ] || [ "$loop" != "true" ]; then
9fc9a3
+        break;
9fc9a3
+    fi
9fc9a3
+
9fc9a3
+    sleep 0.5
9fc9a3
 done
9fc9a3
diff --git a/src/systemd/clevis-luks-askpass.service.in b/src/systemd/clevis-luks-askpass.service.in
9fc9a3
index aa38a5b..2c6bbed 100644
9fc9a3
--- a/src/systemd/clevis-luks-askpass.service.in
9fc9a3
+++ b/src/systemd/clevis-luks-askpass.service.in
9fc9a3
@@ -5,4 +5,4 @@ After=network-online.target
9fc9a3
 
9fc9a3
 [Service]
9fc9a3
 Type=oneshot
9fc9a3
-ExecStart=@libexecdir@/clevis-luks-askpass
9fc9a3
+ExecStart=@libexecdir@/clevis-luks-askpass -l
9fc9a3
-- 
9fc9a3
2.14.3
9fc9a3