diff --git a/Makefile b/Makefile index 8f0ef59..69e8eaa 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ include Makefile.inc -SUBDIRS = kpatch-build kpatch kmod man +SUBDIRS = kpatch-build kpatch kmod man contrib BUILD_DIRS = $(SUBDIRS:%=build-%) INSTALL_DIRS = $(SUBDIRS:%=install-%) UNINSTALL_DIRS = $(SUBDIRS:%=uninstall-%) diff --git a/contrib/Makefile b/contrib/Makefile new file mode 100644 index 0000000..f007fb0 --- /dev/null +++ b/contrib/Makefile @@ -0,0 +1,14 @@ +include ../Makefile.inc + +DRACUTDIR=/usr/lib/dracut/modules.d/99kpatch + +all: + +install: all + $(INSTALL) -d $(DRACUTDIR) + $(INSTALL) module-setup.sh kpatch-apply-all.sh $(DRACUTDIR) + +uninstall: + $(RM) $(DRACUTDIR) + +clean: diff --git a/contrib/kpatch-apply-all.sh b/contrib/kpatch-apply-all.sh new file mode 100755 index 0000000..5d6566d --- /dev/null +++ b/contrib/kpatch-apply-all.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +# +# Licensed under the GPLv2 +# +# Copyright 2014 Red Hat, Inc. +# Josh Poimboeuf + +insmod /usr/lib/modules/$(uname -r)/kpatch/kpatch.ko +kpatch apply --all diff --git a/contrib/module-setup.sh b/contrib/module-setup.sh new file mode 100755 index 0000000..5dd91ac --- /dev/null +++ b/contrib/module-setup.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +# +# Licensed under the GPLv2 +# +# Copyright 2014 Red Hat, Inc. +# Josh Poimboeuf + +# called by dracut +check() { + if [[ -e /var/lib/kpatch/$kernel ]] || [[ -e /usr/lib/kpatch/$kernel ]]; then + return 0 + else + return 1 + fi +} + +# called by dracut +install() { + # install kpatch script + inst_any -d /usr/sbin/kpatch /usr/local/sbin/kpatch /usr/sbin/kpatch + + # install insmod (needed by kpatch script) + inst_symlink /usr/sbin/insmod + + # install core module + inst_any -d /usr/lib/modules/$kernel/kpatch/kpatch.ko /usr/local/lib/modules/$kernel/kpatch/kpatch.ko /usr/lib/modules/$kernel/kpatch/kpatch.ko + + # install patch modules + if [[ -e /var/lib/kpatch/$kernel ]]; then + inst_dir /var/lib/kpatch/$kernel + for i in /var/lib/kpatch/$kernel/*; do + [[ -e $i ]] || continue + inst "$i" + done + fi + if [[ -e /usr/lib/kpatch/$kernel ]]; then + inst_dir /usr/lib/kpatch/$kernel + for i in /usr/lib/kpatch/$kernel/*; do + [[ -e $i ]] || continue + inst "$i" + done + fi + + # install hook script + inst_hook pre-udev 00 "$moddir/kpatch-apply-all.sh" +} diff --git a/kpatch/kpatch b/kpatch/kpatch index 63cb425..449aad2 100755 --- a/kpatch/kpatch +++ b/kpatch/kpatch @@ -120,6 +120,7 @@ case "$1" in [[ ${PATCH: -3} == ".ko" ]] || die "$PATCH isn't a .ko file" mkdir -p "$USERDIR" || die "failed to create install directory" cp -f "$PATCH" "$USERDIR" || die "failed to install patch $PATCH" + dracut -f || die "dracut failed" ;; "uninstall") @@ -127,6 +128,7 @@ case "$1" in PATCH="$2" find_module "$PATCH" || die "$PATCH is not installed" rm -f "$USERDIR/$(basename $MODULE)" || die "failed to uninstall patch $PATCH" + dracut -f || die "dracut failed" ;; "list")