From: Simon McVittie <smcv@collabora.com>
Date: Thu, 14 Jun 2018 15:12:22 +0100
Subject: Prevent processes in deb build chroots from trying to start system
 services

Description: Added policy-rc.d that turns invoke-rc.d into a no-op
 The problem is that in older versions of Ubuntu, the unpack packageset
 from the target distribution to be able to run the first-stage
 debootstrap is not very minimal.
 .
 In particular, it includes packages like initscripts, udev and procps,
 which have initscripts that are started by postinst. In older Ubuntu,
 when a postinst runs invoke-rc.d, it communicates with Upstart via a
 mechanism that can escape from the chroot and talk to the host system's
 Upstart (!); and if it can't, invoke-rc.d will fail and the first-stage
 bootstrap will also fail.
 .
 The symptom is that on workers whose host OS did not boot using Upstart
 (for example Debian stretch, but not Ubuntu trusty), the first-stage
 bootstrap fails with:
 .
  [   22s] initctl: Unable to connect to Upstart: Failed to connect to
  socket /com/ubuntu/upstart: Connection refused
 .
 So here is a patch to provide OBS-level solution that adds a policy-rc.d
 that turns invoke-rc.d into a no-op, just like debootstrap does to
 prevent processes in deb build chroots from trying to start system
 services.
Forwarded: https://github.com/openSUSE/obs-build/pull/462
Author: Simon McVittie <smcv@collabora.com>
Last-Update: 2018-08-31
---
 obuild-pkg-deb | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/build-pkg-deb b/build-pkg-deb
index c5959c0..4cf47c9 100644
--- a/build-pkg-deb
+++ b/build-pkg-deb
@@ -44,10 +44,17 @@ deb_setup() {
     mkdir -p $BUILD_ROOT/var/lib/dpkg
     mkdir -p $BUILD_ROOT/var/log
     mkdir -p $BUILD_ROOT/etc/default
+    mkdir -p "$BUILD_ROOT/usr/sbin"
     :>> $BUILD_ROOT/var/lib/dpkg/status
     :>> $BUILD_ROOT/var/lib/dpkg/available
     :>> $BUILD_ROOT/var/log/dpkg.log
     :>> $BUILD_ROOT/etc/ld.so.conf
+    cat > "$BUILD_ROOT/usr/sbin/policy-rc.d" <<'EOF'
+#!/bin/sh
+echo "policy-rc.d from obs-build build-pkg-deb: disallowing rc.d action: $*" >&2
+exit 101
+EOF
+    chmod 755 "$BUILD_ROOT/usr/sbin/policy-rc.d"
 }
 
 pkg_initdb_deb() {
