From c9614c429822b629408705a9f5af9810a0534c48 Mon Sep 17 00:00:00 2001 From: loretob Date: Tue, 27 Mar 2018 16:09:44 +0200 Subject: [PATCH] Adding support to upstart systems. Currently kpatch rely on systemd to load all kmods on startup. This patch aims to enable kpatch to be used on upstart systems. Limitations: With systemd, it would be possible to unload all modules by issuing: systemctl stop kpatch It was not possible to make a reasonable upstart's equivalent of it, so to unload the modules it will be necessary to call kpatch explicitly: kpatch unload --all I believe this it an non-issue, as it is still possible to unload the modules by calling kpatch explicitly. The file /etc/init/kpatch.conf will be installed unconditionally, and removed on uninstall. On my tests I have verified that all newly added files by this commit are also deleted on uninstall. It was also verified that applied patches are loaded again on startup. rpmlint does not complain about anything new. Signed-off-by: Bruno Loreto --- Makefile.inc | 1 + contrib/Makefile | 4 ++++ contrib/kpatch.conf | 29 +++++++++++++++++++++++++++++ contrib/kpatch.spec | 1 + 4 files changed, 35 insertions(+) create mode 100644 contrib/kpatch.conf diff --git a/Makefile.inc b/Makefile.inc index da27355..7351047 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -15,6 +15,7 @@ LIBEXECDIR = $(DESTDIR)$(PREFIX)/$(LIBEXEC)/kpatch DATADIR = $(DESTDIR)$(PREFIX)/share/kpatch MANDIR = $(DESTDIR)$(PREFIX)/share/man/man1 SYSTEMDDIR = $(DESTDIR)$(PREFIX)/lib/systemd/system +UPSTARTDIR = $(DESTDIR)/etc/init # The core module is only supported on x86_64 ifeq ($(ARCH),x86_64) diff --git a/contrib/Makefile b/contrib/Makefile index 89a67ef..0b0eeeb 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -6,8 +6,12 @@ install: all $(INSTALL) -d $(SYSTEMDDIR) $(INSTALL) -m 0644 kpatch.service $(SYSTEMDDIR) sed -i 's~PREFIX~$(PREFIX)~' $(SYSTEMDDIR)/kpatch.service + $(INSTALL) -d $(UPSTARTDIR) + $(INSTALL) -m 0644 kpatch.conf $(UPSTARTDIR) + sed -i 's~PREFIX~$(PREFIX)~' $(UPSTARTDIR)/kpatch.conf uninstall: $(RM) $(SYSTEMDDIR)/kpatch.service + $(RM) $(UPSTARTDIR)/kpatch.conf clean: diff --git a/contrib/kpatch.conf b/contrib/kpatch.conf new file mode 100644 index 0000000..560ce3d --- /dev/null +++ b/contrib/kpatch.conf @@ -0,0 +1,29 @@ +# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + +# This upstart version lacks the ability of unloading modules with +# the "stop" directive, as upstart does not support a feature like +# systemd's RemainAfterExit option. + + +description "Apply kpatch kernel patches" + +start on runlevel [2345] # Roughly equivalent to multi-user.target + +# We are not a daemon +task + +# Emulating systemd's ConditionKernelCommandLine option. +pre-start script + if [[ -e /proc/cmdline ]] + then + grep -q "kpatch.enable=0" /proc/cmdline && exit 1 + else + dmesg | grep -q "Command line.*kpatch.enable=0" && exit 1 + fi + + exit 0 +end script + +# Main process (start) +exec PREFIX/sbin/kpatch load --all + diff --git a/contrib/kpatch.spec b/contrib/kpatch.spec index a28dfd0..6daf816 100644 --- a/contrib/kpatch.spec +++ b/contrib/kpatch.spec @@ -79,6 +79,7 @@ rm -rf %{buildroot} %{_sbindir}/kpatch %{_mandir}/man1/kpatch.1* %{_usr}/lib/systemd/system/* +%{_sysconfdir}/init/kpatch.conf %files %{KVER} %defattr(-,root,root,-)