Browse Source

install: add -H flag for install

inst* functions and dracut-install now accept the "-H" flag, which
logs all installed files to /lib/dracut/hostonly-files. This is used
to remove those files, if rd.hostonly is given on the kernel command line.
master
Harald Hoyer 11 years ago
parent
commit
26cd262a6a
  1. 30
      dracut-functions.sh
  2. 38
      install/dracut-install.c

30
dracut-functions.sh

@ -763,8 +763,8 @@ inst_dir() {
inst() { inst() {
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
#dinfo "$DRACUT_INSTALL -l $@" #dinfo "$DRACUT_INSTALL -l $@"
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" $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:+-H} "$@" || : (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
} }


inst_simple() { inst_simple() {
@ -777,16 +777,16 @@ inst_simple() {
inst_symlink() { inst_symlink() {
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
[[ -L $1 ]] || return 1 [[ -L $1 ]] || return 1
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" $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:+-H} "$@" || : (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
} }


inst_multiple() { inst_multiple() {
local ret local ret
#dinfo "initdir=$initdir $DRACUT_INSTALL -l $@" #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
ret=$? ret=$?
(($ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || : (($ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
return $ret return $ret
} }


@ -797,18 +797,24 @@ dracut_install() {
inst_library() { inst_library() {
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
[[ -e $1 ]] || return 1 # no source [[ -e $1 ]] || return 1 # no source
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" $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:+-H} "$@" || : (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
} }


inst_binary() { inst_binary() {
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" $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:+-H} "$@" || : (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
} }


inst_script() { inst_script() {
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" $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:+-H} "$@" || : (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
}

mark_hostonly() {
for i in "$@"; do
echo "$i" >> "$initdir/lib/dracut/hostonly-files"
done
} }


# find symlinks linked to given library file # find symlinks linked to given library file

38
install/dracut-install.c

@ -53,6 +53,7 @@ static bool arg_optional = false;
static bool arg_all = false; static bool arg_all = false;
static bool arg_resolvelazy = false; static bool arg_resolvelazy = false;
static bool arg_resolvedeps = false; static bool arg_resolvedeps = false;
static bool arg_hostonly = false;
static char *destrootdir = NULL; static char *destrootdir = NULL;


static Hashmap *items = NULL; static Hashmap *items = NULL;
@ -467,6 +468,29 @@ static int hmac_install(const char *src, const char *dst, const char *hmacpath)
return 0; return 0;
} }


void mark_hostonly(const char *path)
{
_cleanup_free_ char *fulldstpath = NULL;
_cleanup_fclose_ FILE *f = NULL;
int ret;

ret = asprintf(&fulldstpath, "%s/lib/dracut/hostonly-files", destrootdir);
if (ret < 0) {
log_error("Out of memory!");
exit(EXIT_FAILURE);
}

f = fopen(fulldstpath, "a");

if (f == NULL) {
log_error("Could not open '%s' for writing.", fulldstpath);
return;
}

fprintf(f, "%s\n", path);

}

static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst) static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst)
{ {
struct stat sb, db; struct stat sb, db;
@ -628,6 +652,10 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res


log_debug("dracut_install ret = %d", ret); log_debug("dracut_install ret = %d", ret);
log_info("cp '%s' '%s'", src, fulldstpath); log_info("cp '%s' '%s'", src, fulldstpath);

if (arg_hostonly)
mark_hostonly(dst);

ret += cp(src, fulldstpath); ret += cp(src, fulldstpath);


log_debug("dracut_install ret = %d", ret); log_debug("dracut_install ret = %d", ret);
@ -706,13 +734,14 @@ static int parse_argv(int argc, char *argv[])
{"ldd", no_argument, NULL, 'l'}, {"ldd", no_argument, NULL, 'l'},
{"resolvelazy", no_argument, NULL, 'R'}, {"resolvelazy", no_argument, NULL, 'R'},
{"optional", no_argument, NULL, 'o'}, {"optional", no_argument, NULL, 'o'},
{"hostonly", no_argument, NULL, 'H'},
{"all", no_argument, NULL, 'a'}, {"all", no_argument, NULL, 'a'},
{"fips", no_argument, NULL, 'H'}, {"fips", no_argument, NULL, 'f'},
{"destrootdir", required_argument, NULL, 'D'}, {"destrootdir", required_argument, NULL, 'D'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };


while ((c = getopt_long(argc, argv, "adhloD:HR", options, NULL)) != -1) { while ((c = getopt_long(argc, argv, "adfhloD:HR", options, NULL)) != -1) {
switch (c) { switch (c) {
case ARG_VERSION: case ARG_VERSION:
puts(PROGRAM_VERSION_STRING); puts(PROGRAM_VERSION_STRING);
@ -741,9 +770,12 @@ static int parse_argv(int argc, char *argv[])
case 'D': case 'D':
destrootdir = strdup(optarg); destrootdir = strdup(optarg);
break; break;
case 'H': case 'f':
arg_hmac = true; arg_hmac = true;
break; break;
case 'H':
arg_hostonly = true;
break;
case 'h': case 'h':
usage(EXIT_SUCCESS); usage(EXIT_SUCCESS);
break; break;

Loading…
Cancel
Save