Blame SOURCES/0010-cloud-init-per-don-t-use-dashes-in-sem-names.patch

936480
From f8d348243bd32fe3c3f0b55c2a216e95d44c5abd Mon Sep 17 00:00:00 2001
936480
From: Eduardo Otubo <otubo@redhat.com>
936480
Date: Thu, 28 Feb 2019 12:38:36 +0100
936480
Subject: cloud-init-per: don't use dashes in sem names
936480
936480
RH-Author: Eduardo Otubo <otubo@redhat.com>
936480
Message-id: <20190228123836.17979-1-otubo@redhat.com>
936480
Patchwork-id: 84743
936480
O-Subject: [RHEL-7.7 cloud-init PATCH] This is to fix https://bugs.launchpad.net/cloud-init/+bug/1812676
936480
Bugzilla: 1664876
936480
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
936480
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
936480
936480
From: Vitaly Kuznetsov <vkuznets@redhat.com>
936480
936480
    It was found that when there is a dash in cloud-init-per command
936480
    name and cloud-init-per is executed through cloud-init's bootcmd, e.g:
936480
936480
    bootcmd:
936480
     - cloud-init-per instance mycmd-bootcmd /usr/bin/mycmd
936480
936480
    the command is executed on each boot. However, running the same
936480
    cloud-init-per command manually after boot doesn't reveal the issue. Turns
936480
    out the issue comes from 'migrator' cloud-init module which renames all
936480
    files in /var/lib/cloud/instance/sem/ replacing dashes with underscores. As
936480
    migrator runs before bootcmd it renames
936480
936480
    /var/lib/cloud/instance/sem/bootper.mycmd-bootcmd.instance
936480
    to
936480
    /var/lib/cloud/instance/sem/bootper.mycmd_bootcmd.instance
936480
936480
    so cloud-init-per doesn't see it and thinks that the comment was never ran
936480
    before. On next boot the sequence repeats.
936480
936480
    There are multiple ways to resolve the issue. This patch takes the
936480
    following approach: 'canonicalize' sem names by replacing dashes with
936480
    underscores (this is consistent with post-'migrator' contents of
936480
    /var/lib/cloud/instance/sem/). We, however, need to be careful: in case
936480
    someone had a command with dashes before and he had migrator module enables
936480
    we need to see the old sem file (or the command will run again and this can
936480
    be as bad as formatting a partition!) so we add a small 'migrator' part to
936480
    cloud-init-per script itself checking for legacy sem names.
936480
936480
    Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
936480
936480
commit 9cf9d8cdd3a8fd7d4d425f7051122d0ac8af2bbd
936480
Author: Vitaly Kuznetsov <vkuznets@redhat.com>
936480
Date:   Mon Feb 18 22:55:49 2019 +0000
936480
936480
    This is to fix https://bugs.launchpad.net/cloud-init/+bug/1812676
936480
936480
Resolves: rhbz#1664876
936480
X-downstream-only: false
936480
936480
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
936480
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
936480
---
936480
 tools/cloud-init-per | 8 +++++++-
936480
 1 file changed, 7 insertions(+), 1 deletion(-)
936480
936480
diff --git a/tools/cloud-init-per b/tools/cloud-init-per
936480
index 7d6754b..eae3e93 100755
936480
--- a/tools/cloud-init-per
936480
+++ b/tools/cloud-init-per
936480
@@ -38,7 +38,7 @@ fi
936480
 [ "$1" = "-h" -o "$1" = "--help" ] && { Usage ; exit 0; }
936480
 [ $# -ge 3 ] || { Usage 1>&2; exit 1; }
936480
 freq=$1
936480
-name=$2
936480
+name=${2/-/_}
936480
 shift 2;
936480
 
936480
 [ "${name#*/}" = "${name}" ] || fail "name cannot contain a /"
936480
@@ -53,6 +53,12 @@ esac
936480
 [ -d "${sem%/*}" ] || mkdir -p "${sem%/*}" ||
936480
    fail "failed to make directory for ${sem}"
936480
 
936480
+# Rename legacy sem files with dashes in their names. Do not overwrite existing
936480
+# sem files to prevent clobbering those which may have been created from calls
936480
+# outside of cloud-init.
936480
+sem_legacy="${sem/_/-}"
936480
+[ "$sem" != "$sem_legacy" -a -e "$sem_legacy" ] && mv -n "$sem_legacy" "$sem"
936480
+
936480
 [ "$freq" != "always" -a -e "$sem" ] && exit 0
936480
 "$@"
936480
 ret=$?
936480
-- 
936480
1.8.3.1
936480