]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
add "--loginstall <DIR>" and loginstall="<DIR>" options
authorHarald Hoyer <harald@redhat.com>
Thu, 11 Sep 2014 14:42:36 +0000 (16:42 +0200)
committerHarald Hoyer <harald@redhat.com>
Thu, 11 Sep 2014 14:42:36 +0000 (16:42 +0200)
loginstall specifies a directory, in which dracut-install records all
files, which were installed from the host system to the initramfs.

Use case is e.g. to create a list of packages to watch for updates, to
maybe trigger a recreation of the initramfs.

dracut-bash-completion.sh
dracut-functions.sh
dracut.8.asc
dracut.conf.5.asc
dracut.sh
install/dracut-install.c

index d04e6c2acfe80867c2c175e306adaa633cb264dc..35ddc4d0724fc6be76412e56ea3765bf499fb731 100644 (file)
@@ -31,13 +31,16 @@ _dracut() {
                               --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
                               --xz --no-compress --gzip --list-modules --show-modules --keep
                               --printsize --regenerate-all --noimageifnotneeded --early-microcode
-                              --no-early-microcode --print-cmdline --prelink --noprelink'
+                              --no-early-microcode --print-cmdline --prelink --noprelink --reproducible
+                              '
 
                        [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
                               --omit-drivers --modules --omit --drivers --filesystems --install
                               --fwdir --libdirs --fscks --add-fstab --mount --device --nofscks
                               --kmoddir --conf --confdir --tmpdir --stdlog --compress --prefix
-                              --kernel-cmdline --sshkey --persistent-policy --install-optional'
+                              --kernel-cmdline --sshkey --persistent-policy --install-optional
+                              --loginstall
+                              '
         )
 
         if __contains_word "$prev" ${OPTS[ARG]}; then
index a2a352fadcbe67b3360ca14b4801cf302bd2a9fa..346ab97e5ba9a1aa06376a99a67d362017339528 100755 (executable)
@@ -764,8 +764,8 @@ inst() {
         shift
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
-    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_simple() {
@@ -776,8 +776,8 @@ inst_simple() {
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
     [[ -e $1 ]] || return 1  # no source
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${_hostonly_install:+-H} "$@"
-    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${_hostonly_install:+-H} "$@" || :
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_symlink() {
@@ -788,15 +788,15 @@ inst_symlink() {
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
     [[ -L $1 ]] || return 1
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
-    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_multiple() {
     local _ret
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
     _ret=$?
-    (($_ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    (($_ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
     return $_ret
 }
 
@@ -812,18 +812,18 @@ inst_library() {
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
     [[ -e $1 ]] || return 1  # no source
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
-    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_binary() {
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
-    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
 }
 
 inst_script() {
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
-    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
 }
 
 mark_hostonly() {
@@ -1520,7 +1520,7 @@ dracut_kernel_post() {
 
         (
             if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
-                xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
+                xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
             else
                 while read _modpath; do
                     local _destpath=$_modpath
@@ -1539,7 +1539,7 @@ dracut_kernel_post() {
                 for _fwdir in $fw_dir; do
                     echo $_fwdir/$line;
                 done;
-            done | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
+            done | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} -a -o
         else
             for _fw in $(xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
                 for _fwdir in $fw_dir; do
index 986e73bcd7b9efd7d8bcf0ae8e92267e32775817..7d11f431f0ffbe07d44a94270f9591242422d9df 100644 (file)
@@ -462,6 +462,9 @@ will not be able to boot.
     Regenerate all initramfs images at the default location with the kernel
     versions found on the system. Additional parameters are passed through.
 
+**--loginstall _<DIR>_::
+    Log all files installed from the host to _<DIR>_.
+
 FILES
 -----
 _/var/log/dracut.log_::
index 71d5c7114019c7655f0c0b9f07191ffeaba52156..0531a495d5910565069f8a01718abb53b54dd343 100644 (file)
@@ -186,6 +186,9 @@ provide a valid _/etc/fstab_.
 *reproducible=*"__{yes|no}__"::
     Create reproducible images.
 
+*loginstall=*"__<DIR>__"::
+    Log all files installed from the host to _<DIR>_.
+
 Files
 -----
 _/etc/dracut.conf_::
index afbc075781bbb3961d1741b679af66973745fc59..eef405fbddecdbb4b020f6f4ddfee71161846abe 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -174,10 +174,10 @@ Creates initial ramdisk images for preloading modules
   --xz                  Compress the generated initramfs using xz.
                          Make sure that your kernel has xz support compiled
                          in, otherwise you will not be able to boot.
-  --lzo                  Compress the generated initramfs using lzop.
+  --lzo                 Compress the generated initramfs using lzop.
                          Make sure that your kernel has lzo support compiled
                          in, otherwise you will not be able to boot.
-  --lz4                  Compress the generated initramfs using lz4.
+  --lz4                 Compress the generated initramfs using lz4.
                          Make sure that your kernel has lz4 support compiled
                          in, otherwise you will not be able to boot.
   --compress [COMPRESSION] Compress the generated initramfs with the
@@ -194,6 +194,7 @@ Creates initial ramdisk images for preloading modules
   --sshkey [SSHKEY]     Add ssh key to initramfs (use with ssh-client module)
   --logfile [FILE]      Logfile to use (overrides configuration setting)
   --reproducible        Create reproducible images
+  --loginstall [DIR]    Log all files installed from the host to [DIR]
 
 If [LIST] has multiple arguments, then you have to put these in quotes.
 
@@ -377,6 +378,7 @@ rearrange_params()
         --long early-microcode \
         --long no-early-microcode \
         --long reproducible \
+        --long loginstall: \
         -- "$@")
 
     if (( $? != 0 )); then
@@ -498,6 +500,7 @@ while :; do
         -L|--stdlog)   stdloglvl_l="$2";               PARMS_TO_STORE+=" '$2'"; shift;;
         --compress)    compress_l="$2";                PARMS_TO_STORE+=" '$2'"; shift;;
         --prefix)      prefix_l="$2";                  PARMS_TO_STORE+=" '$2'"; shift;;
+        --loginstall)  loginstall_l="$2";              PARMS_TO_STORE+=" '$2'"; shift;;
         --rebuild)     if [ $rebuild_file == $outfile ]; then
                            force=yes
                        fi
@@ -808,6 +811,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
 [[ $early_microcode ]] || early_microcode=no
 [[ $logfile_l ]] && logfile="$logfile_l"
 [[ $reproducible_l ]] && reproducible="$reproducible_l"
+[[ $loginstall_l ]] && loginstall="$loginstall_l"
 
 # eliminate IFS hackery when messing with fw_dir
 fw_dir=${fw_dir//:/ }
@@ -993,6 +997,14 @@ if [[ ! $print_cmdline ]]; then
         dfatal "No permission to write $outfile."
         exit 1
     fi
+
+    if [[ $loginstall ]]; then
+        if ! mkdir -p "$loginstall"; then
+            dfatal "Could not create directory to log installed files to '$loginstall'."
+            exit 1
+        fi
+        loginstall=$(readlink -f "$loginstall")
+    fi
 fi
 
 if [[ $acpi_override = yes ]] && ! check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE; then
@@ -1216,7 +1228,7 @@ export initdir dracutbasedir dracutmodules \
     debug host_fs_types host_devs sshkey add_fstab \
     DRACUT_VERSION udevdir prefix filesystems drivers \
     systemdutildir systemdsystemunitdir systemdsystemconfdir \
-    host_modalias host_modules hostonly_cmdline
+    host_modalias host_modules hostonly_cmdline loginstall
 
 mods_to_load=""
 # check all our modules to see if they should be sourced.
index c39392ac836dd7eb0404bfe0338767d773b4bbeb..201f1815e5447dd3ca32e60626d766e06ed0fd84 100644 (file)
@@ -53,7 +53,9 @@ static bool arg_resolvelazy = false;
 static bool arg_resolvedeps = false;
 static bool arg_hostonly = false;
 static char *destrootdir = NULL;
-
+static char *logdir = NULL;
+static char *logfile = NULL;
+FILE *logfile_f = NULL;
 static Hashmap *items = NULL;
 static Hashmap *items_failed = NULL;
 
@@ -498,6 +500,14 @@ void mark_hostonly(const char *path)
         fprintf(f, "%s\n", path);
 }
 
+void dracut_log_cp(const char *path)
+{
+        int ret;
+        ret = fprintf(logfile_f, "%s\n", path);
+        if (ret < 0)
+                log_error("Could not append '%s' to logfile '%s': %m", path, logfile);
+}
+
 static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst)
 {
         struct stat sb, db;
@@ -664,6 +674,8 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
                 mark_hostonly(dst);
 
         ret += cp(src, fulldstpath);
+        if (ret == 0 && logfile_f)
+                dracut_log_cp(src);
 
         log_debug("dracut_install ret = %d", ret);
 
@@ -689,6 +701,7 @@ static void usage(int status)
                "  -o --optional       If SOURCE does not exist, do not fail\n"
                "  -d --dir            SOURCE is a directory\n"
                "  -l --ldd            Also install shebang executables and libraries\n"
+               "  -L --logdir <DIR>   Log files, which were installed from the host to <DIR>\n"
                "  -R --resolvelazy    Only install shebang executables and libraries\n"
                "                      for all SOURCE files\n"
                "  -H --fips           Also install all '.SOURCE.hmac' files\n"
@@ -745,10 +758,11 @@ static int parse_argv(int argc, char *argv[])
                 {"all", no_argument, NULL, 'a'},
                 {"fips", no_argument, NULL, 'f'},
                 {"destrootdir", required_argument, NULL, 'D'},
+                {"logdir", required_argument, NULL, 'L'},
                 {NULL, 0, NULL, 0}
         };
 
-        while ((c = getopt_long(argc, argv, "adfhloD:HR", options, NULL)) != -1) {
+        while ((c = getopt_long(argc, argv, "adfhlL:oD:HR", options, NULL)) != -1) {
                 switch (c) {
                 case ARG_VERSION:
                         puts(PROGRAM_VERSION_STRING);
@@ -777,6 +791,9 @@ static int parse_argv(int argc, char *argv[])
                 case 'D':
                         destrootdir = strdup(optarg);
                         break;
+                case 'L':
+                        logdir = strdup(optarg);
+                        break;
                 case 'f':
                         arg_hmac = true;
                         break;
@@ -1001,6 +1018,23 @@ int main(int argc, char **argv)
                 goto finish;
         }
 
+        if (logdir) {
+                int ret;
+
+                ret = asprintf(&logfile, "%s/%d.log", logdir, getpid());
+                if (ret < 0) {
+                        log_error("Out of memory!");
+                        exit(EXIT_FAILURE);
+                }
+
+                logfile_f = fopen(logfile, "a");
+                if (logfile_f == NULL) {
+                        log_error("Could not open %s for logging: %m", logfile);
+                        r = EXIT_FAILURE;
+                        goto finish;
+                }
+        }
+
         r = EXIT_SUCCESS;
 
         if (((optind + 1) < argc) && (strcmp(argv[optind + 1], destrootdir) == 0)) {
@@ -1029,6 +1063,8 @@ int main(int argc, char **argv)
                 r = EXIT_SUCCESS;
 
  finish:
+        if (logfile_f)
+                fclose(logfile_f);
 
         while ((i = hashmap_steal_first(items)))
                 item_free(i);