Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 901209 - Add 'update' action to kernel module
Summary: Add 'update' action to kernel module
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: eselect (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo eselect Team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2023-03-14 12:03 UTC by Florian Schmaus
Modified: 2023-03-20 17:27 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
0001-Add-update-action-to-kernel-module.patch (0001-Add-update-action-to-kernel-module.patch,2.47 KB, patch)
2023-03-14 12:03 UTC, Florian Schmaus
Details | Diff
0001-Add-update-action-to-kernel-module.patch (0001-Add-update-action-to-kernel-module.patch,2.46 KB, patch)
2023-03-14 14:18 UTC, Florian Schmaus
Details | Diff
0001-Add-update-action-to-kernel-module.patch (0001-Add-update-action-to-kernel-module.patch,3.29 KB, patch)
2023-03-14 14:39 UTC, Florian Schmaus
Details | Diff
0001-Add-update-action-to-kernel-module.patch (0001-Add-update-action-to-kernel-module.patch,3.45 KB, patch)
2023-03-14 18:40 UTC, Florian Schmaus
Details | Diff
0001-Add-update-action-to-kernel-module.patch (0001-Add-update-action-to-kernel-module.patch,3.44 KB, patch)
2023-03-14 18:59 UTC, Florian Schmaus
Details | Diff
Couldn't update the kernel symlink" (0001-Add-update-action-to-kernel-module.patch,3.73 KB, patch)
2023-03-15 09:10 UTC, Florian Schmaus
Details | Diff
Couldn't update the kernel symlink" (0001-Add-update-action-to-kernel-module.patch,3.73 KB, patch)
2023-03-15 09:11 UTC, Florian Schmaus
Details | Diff
0001-Add-update-action-to-kernel-module.patch (0001-Add-update-action-to-kernel-module.patch,3.73 KB, patch)
2023-03-15 09:12 UTC, Florian Schmaus
Details | Diff
0001-Add-update-action-to-kernel-module.patch (0001-Add-update-action-to-kernel-module.patch,3.73 KB, patch)
2023-03-15 09:59 UTC, Florian Schmaus
Details | Diff
0001-Add-update-action-to-kernel-module.patch (0001-Add-update-action-to-kernel-module.patch,3.68 KB, patch)
2023-03-15 10:02 UTC, Florian Schmaus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Schmaus gentoo-dev 2023-03-14 12:03:22 UTC
Created attachment 857651 [details, diff]
0001-Add-update-action-to-kernel-module.patch

Add an 'update' action to the kernel eselect module which automatically sets the /usr/src/linux symlink to the running kernel.

Branch at https://gitlab.gentoo.org/flow/eselect/-/tree/kernel-update-action
Comment 1 Ulrich Müller gentoo-dev 2023-03-14 13:40:16 UTC
Looks good. One tiny comment: uname --kernel-release is a GNUism. I suggest to use -r instead which is the POSIX option.
Comment 2 Florian Schmaus gentoo-dev 2023-03-14 14:18:06 UTC
Created attachment 857673 [details, diff]
0001-Add-update-action-to-kernel-module.patch

Use -r instead of --kernel-release when invoking uname.
Comment 3 Ulrich Müller gentoo-dev 2023-03-14 14:22:45 UTC
Documentation in man/kernel.eselect.5 has to be updated as well.
Comment 4 Florian Schmaus gentoo-dev 2023-03-14 14:39:40 UTC
Created attachment 857685 [details, diff]
0001-Add-update-action-to-kernel-module.patch
Comment 5 Ulrich Müller gentoo-dev 2023-03-14 17:46:36 UTC
(In reply to Florian Schmaus from comment #4)
> Created attachment 857685 [details, diff] [details, diff]
> 0001-Add-update-action-to-kernel-module.patch

Sorry, I have more comments:

- The exit status of uname should be caught.

- In the for loop, "${targets[@]}" should be quoted (to be whitespace-safe).

- Variable current_kernel_symlink_target is neither declared nor assigned anywhere. Typo for running_kernel_symlink_target?

- At the end of do_update(), collecting and showing target_list is not how other modules do things. Also, the user will typically execute "eselect kernel list" anyway, in order to get the numbers.

So, I'd much prefer something simple like this:

    write_error_msg \
        "No sources for running kernel ${running_kernel_release} found."
    write_error_msg "\"eselect kernel list\" will show available sources."
    die -q "Couldn't update the kernel symlink"

- In the man page, please order actions alphabetically. That is, "update" should go last.
Comment 6 Florian Schmaus gentoo-dev 2023-03-14 18:40:05 UTC
Created attachment 857715 [details, diff]
0001-Add-update-action-to-kernel-module.patch

Sorry, today is not the best day for me to write code. I fixed all, but one of your concerns, plus additional things reported by shellcheck.

I really would like to display the list of available sources if the 'update' action fails to find a suitable one. It is a good service to the user to display some more context when an operation fails and hence provides a better UX. That other actions do to behave similarly is more an argument that those should be changed and not that this action should follow that undesirable pattern.
Comment 7 Florian Schmaus gentoo-dev 2023-03-14 18:59:48 UTC
Created attachment 857717 [details, diff]
0001-Add-update-action-to-kernel-module.patch

Fixed trailing newline when listing available sources.
Comment 8 Ulrich Müller gentoo-dev 2023-03-14 19:37:36 UTC
(In reply to Florian Schmaus from comment #6)
> I really would like to display the list of available sources if the 'update'
> action fails to find a suitable one. It is a good service to the user to
> display some more context when an operation fails and hence provides a
> better UX. That other actions do to behave similarly is more an argument
> that those should be changed and not that this action should follow that
> undesirable pattern.

Sorry, but that's not going to happen. Error messages are concise in all modules that are part of eselect itself and in most external modules.

If you really insist on this, the "eselect way" of doing it would be along the lines of this:

    write_error_msg \
        "No sources for running kernel ${running_kernel_release} found."
    is_output_mode brief || do_list >&2
    die -q "Couldn't update the kernel symlink"

do_list shows the list of targets, with the target numbers and with proper coloring. This should be suppressed though if the --brief option was specified.

(And yes, it will call find_targets() again. That's acceptable in the error case, which should be rare.)
Comment 9 Ulrich Müller gentoo-dev 2023-03-15 08:17:20 UTC
OK, I did some tests. Things seem to work well, except for one minor problem: If the sources of the running kernel have been removed, but the symlink still points to them (i.e. the link is dead), then the action will succeed.

This will fix it:

--- a/modules/kernel.eselect
+++ b/modules/kernel.eselect
@@ -146,9 +146,7 @@ do_update() {
 		die -q "${EROOT}/usr/src/linux exists but is not a symlink"
 	fi
 
-	if [[ $1 == ifunset \
-			  && -L ${EROOT}/usr/src/linux \
-			  && -e ${EROOT}/usr/src/linux ]]; then
+	if [[ $1 == ifunset && -e ${EROOT}/usr/src/linux ]]; then
 		# The /usr/src/linux symlink exists, points to a path that
 		# exists, and 'ifunset' is provided. Nothing to do.
 		return
@@ -159,7 +157,7 @@ do_update() {
 	running_kernel_release=$(uname -r) || die -q "uname failed with $?"
 	local running_kernel_symlink_target="linux-${running_kernel_release}"
 
-	if [[ -L ${EROOT}/usr/src/linux ]]; then
+	if [[ -e ${EROOT}/usr/src/linux ]]; then
 		local current_target
 		current_target=$(basename "$(canonicalise "${EROOT}/usr/src/linux")")
 		if [[ ${current_target} == "${running_kernel_symlink_target}" ]]; then

(The case that -e is true but -L is false cannot happen, because of the sanity check at the begin of the function.)
Comment 10 Florian Schmaus gentoo-dev 2023-03-15 09:10:30 UTC
Created attachment 857807 [details, diff]
Couldn't update the kernel symlink"

No need to be sorry. It is just a technical disagreement. But in the end it appears we could reach consensus using the approach you have shown. And thanks for testing the code.

Attached is the latest patch will your latest suggestions incorporated.
Comment 11 Florian Schmaus gentoo-dev 2023-03-15 09:11:31 UTC
Created attachment 857809 [details, diff]
Couldn't update the kernel symlink"

Fixing the patch description…
Comment 12 Florian Schmaus gentoo-dev 2023-03-15 09:12:00 UTC
Created attachment 857811 [details, diff]
0001-Add-update-action-to-kernel-module.patch
Comment 13 Florian Schmaus gentoo-dev 2023-03-15 09:59:54 UTC
Created attachment 857813 [details, diff]
0001-Add-update-action-to-kernel-module.patch

Moved the the "! -L" and "ifunset" checks under the "-e /usr/src/linux" condition, avoiding an additional "-e" and making the code more readable.
Comment 14 Florian Schmaus gentoo-dev 2023-03-15 10:02:15 UTC
Created attachment 857815 [details, diff]
0001-Add-update-action-to-kernel-module.patch

Remove unused 'target_list' variable (leftover from previous versions).
Comment 15 Ulrich Müller gentoo-dev 2023-03-15 10:48:31 UTC
(In reply to Florian Schmaus from comment #14)
> Created attachment 857815 [details, diff] [details, diff]
> 0001-Add-update-action-to-kernel-module.patch

> +	if [[ -e ${EROOT}/usr/src/linux && ]]; then

Spurious && here. I have fixed it locally.
Comment 16 Larry the Git Cow gentoo-dev 2023-03-15 11:04:41 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/eselect.git/commit/?id=d5bd4e5f8d28c3fc6e7d15d639538ac9b6459e7a

commit d5bd4e5f8d28c3fc6e7d15d639538ac9b6459e7a
Author:     Florian Schmaus <flow@gentoo.org>
AuthorDate: 2023-03-14 10:02:59 +0000
Commit:     Ulrich Müller <ulm@gentoo.org>
CommitDate: 2023-03-15 11:04:22 +0000

    New "update" action in kernel module
    
    * modules/kernel.eselect (do_update, describe_update)
    (describe_update_options): New action, attempts to update the
    /usr/src/linux symlink to point to the sources of the running
    kernel. Bug 901209.
    * man/kernel.eselect.5: Document it.
    
    Thanks to ulm for helpful suggestions when working on this
    functionality.
    
    Bug: https://bugs.gentoo.org/901209
    Signed-off-by: Florian Schmaus <flow@gentoo.org>
    [Tweaked bash syntax. Fixed highlighting in man page.]
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>

 ChangeLog              |  6 +++++
 man/kernel.eselect.5   | 16 ++++++++++--
 modules/kernel.eselect | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 90 insertions(+), 3 deletions(-)
Comment 17 Ulrich Müller gentoo-dev 2023-03-15 11:06:21 UTC
AFAICS everything works, but can you double-check with eselect-9999 before I make a new release?
Comment 18 Florian Schmaus gentoo-dev 2023-03-15 11:57:52 UTC
I also did some testing with -9999 and "eselect kernel update" behaves as expected in the tested cases.
Comment 19 Larry the Git Cow gentoo-dev 2023-03-20 17:27:46 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=015d7e1648ba32072eed926ee3009a3adf9037a1

commit 015d7e1648ba32072eed926ee3009a3adf9037a1
Author:     Ulrich Müller <ulm@gentoo.org>
AuthorDate: 2023-03-20 17:27:09 +0000
Commit:     Ulrich Müller <ulm@gentoo.org>
CommitDate: 2023-03-20 17:27:09 +0000

    app-admin/eselect: add 1.4.22
    
    Closes: https://bugs.gentoo.org/901205
    Closes: https://bugs.gentoo.org/901209
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>

 app-admin/eselect/Manifest              |  1 +
 app-admin/eselect/eselect-1.4.22.ebuild | 58 +++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)