diff --git a/man/kernel-install.xml b/man/kernel-install.xml index 625658becfa..0223b561f1a 100644 --- a/man/kernel-install.xml +++ b/man/kernel-install.xml @@ -200,13 +200,15 @@ - inspect [[KERNEL-VERSION] KERNEL-IMAGE] [INITRD-FILE ...] + inspect [[[KERNEL-VERSION] KERNEL-IMAGE] [INITRD-FILE ...]] + Takes the same parameters as add. + Shows the various paths and parameters configured or auto-detected. In particular shows the - values of the various $KERNEL_INSTALL_* environment variables listed - below. The option can be used to get the output of this verb as a JSON - object. + values of the various $KERNEL_INSTALL_* environment variables listed below, as + they would be passed to plugins. The option can be used to get the output + of this verb as a JSON object. diff --git a/src/kernel-install/kernel-install.c b/src/kernel-install/kernel-install.c index 1940ae2bb6a..6631054d07d 100644 --- a/src/kernel-install/kernel-install.c +++ b/src/kernel-install/kernel-install.c @@ -1126,6 +1126,28 @@ static int do_add( return context_execute(c); } +static int kernel_from_version(const char *version, char **ret_kernel) { + _cleanup_free_ char *vmlinuz = NULL; + int r; + + assert(version); + + vmlinuz = path_join("/usr/lib/modules/", version, "/vmlinuz"); + if (!vmlinuz) + return log_oom(); + + r = laccess(vmlinuz, F_OK); + if (r < 0) { + if (r == -ENOENT) + return log_error_errno(r, "Kernel image not installed to '%s', requiring manual kernel image path specification.", vmlinuz); + + return log_error_errno(r, "Failed to determin if kernel image is installed to '%s': %m", vmlinuz); + } + + *ret_kernel = TAKE_PTR(vmlinuz); + return 0; +} + static int verb_add(int argc, char *argv[], void *userdata) { Context *c = ASSERT_PTR(userdata); _cleanup_free_ char *vmlinuz = NULL; @@ -1158,17 +1180,9 @@ static int verb_add(int argc, char *argv[], void *userdata) { } if (!kernel) { - vmlinuz = path_join("/usr/lib/modules/", version, "/vmlinuz"); - if (!vmlinuz) - return log_oom(); - - r = laccess(vmlinuz, F_OK); - if (r < 0) { - if (r == -ENOENT) - return log_error_errno(r, "Kernel image not installed to '%s', requiring manual kernel image path specification.", vmlinuz); - - return log_error_errno(r, "Failed to determin if kernel image is installed to '%s': %m", vmlinuz); - } + r = kernel_from_version(version, &vmlinuz); + if (r < 0) + return r; kernel = vmlinuz; } @@ -1301,28 +1315,49 @@ static int verb_remove(int argc, char *argv[], void *userdata) { static int verb_inspect(int argc, char *argv[], void *userdata) { Context *c = ASSERT_PTR(userdata); _cleanup_(table_unrefp) Table *t = NULL; + _cleanup_free_ char *vmlinuz = NULL; + const char *version, *kernel; + char **initrds; + struct utsname un; int r; c->action = ACTION_INSPECT; - if (argc == 2) { - r = context_set_kernel(c, argv[1]); - if (r < 0) - return r; - } else if (argc >= 3) { - r = context_set_version(c, argv[1]); - if (r < 0) - return r; + /* When only a single parameter is specified 'inspect' it's the kernel image path, and not the kernel + * version. i.e. it's the first argument that is optional, not the 2nd. That's a bit unfortunate, but + * we keep the behaviour for compatibility. If users want to specify only the version (and have the + * kernel image path derived automatically), then they may specify an empty string or "dash" as + * kernel image path. */ + version = argc > 2 ? empty_or_dash_to_null(argv[1]) : NULL; + kernel = argc > 2 ? empty_or_dash_to_null(argv[2]) : + (argc > 1 ? empty_or_dash_to_null(argv[1]) : NULL); + initrds = strv_skip(argv, 3); - r = context_set_kernel(c, argv[2]); - if (r < 0) - return r; - - r = context_set_initrds(c, strv_skip(argv, 3)); - if (r < 0) - return r; + if (!version) { + assert_se(uname(&un) >= 0); + version = un.release; } + if (!kernel) { + r = kernel_from_version(version, &vmlinuz); + if (r < 0) + return r; + + kernel = vmlinuz; + } + + r = context_set_version(c, version); + if (r < 0) + return r; + + r = context_set_kernel(c, kernel); + if (r < 0) + return r; + + r = context_set_initrds(c, initrds); + if (r < 0) + return r; + r = context_prepare_execution(c); if (r < 0) return r; @@ -1464,7 +1499,8 @@ static int help(void) { " kernel-install [OPTIONS...] add [[[KERNEL-VERSION] KERNEL-IMAGE] [INITRD ...]]\n" " kernel-install [OPTIONS...] add-all\n" " kernel-install [OPTIONS...] remove KERNEL-VERSION\n" - " kernel-install [OPTIONS...] inspect [KERNEL-VERSION] KERNEL-IMAGE [INITRD ...]\n" + " kernel-install [OPTIONS...] inspect [[[KERNEL-VERSION] KERNEL-IMAGE]\n" + " [INITRD ...]]\n" " kernel-install [OPTIONS...] list\n" "\n%3$sOptions:%4$s\n" " -h --help Show this help\n"