最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

linux - How to use update-alternatives Yocto class correctly? - Stack Overflow

matteradmin6PV0评论

I would appreciate any help with update-alternatives Yocto class: simply I cannot understand how it can be used and what are the correct options there.

The problem is simple: I need to install nginx-debug (my own build with --with-debug config) and non-debug nginx into one target image, so -debug version could take precedence (via ALTERNATIVE_PRIORITY) and I would have an option to remove it with dnf (so leaving image with non-debug version only). In other words, I need to have one main symlink called, say, /usr/sbin/nginx and it could point to two different targets: debug (nginx built with debugging support) and non-debug (plain build) in different times, without any further modifications, say, systemd units.

I looked into abovementioned class and wrote the following code (just portions of two recipes):

nginx.bb - non-debug version; it should appear as a default one with name of /usr/sbin/nginx

# I rename built binary of nginx to nginx.1 in do_install() task
...
inherit update-alternatives
# Lower the priority so we could override it with nginx-debug
ALTERNATIVE_PRIORITY = "10" 
ALTERNATIVE:${PN} = "nginx"

# Am I correct here? Should I specify [nginx] in all statements here?
ALTERNATIVE_TARGET[nginx] = "${sbindir_native}/nginx.1"
ALTERNATIVE_LINK_NAME[nginx] = "${sbindir_native}/nginx"

FILES:${PN} += "/"
CONFFILES:${PN} = "${sysconfdir}/${BPN}"
INSANE_SKIP:${PN} = "libdir"

nginx-debug.bb - debug version; it can be separately installed with dnf (not enabled by default), so I anticipate that /usr/sbin/nginx would point to its binary upon installation.

# Again, I setup built process and rename binary artifact to nginx-debug in do_install()
inherit update-alternatives

# This recipe should be a default one, substituting original binary
ALTERNATIVE_PRIORITY = "100"
ALTERNATIVE:${PN} = "nginx"
ALTERNATIVE_TARGET[nginx] = "${sbindir_native}/nginx-debug"
ALTERNATIVE_LINK_NAME[nginx] = "${sbindir_native}/nginx"

# Make package maximum lightweight
PACKAGES = "${PN}"
FILES:${PN} += "${sbindir_native}"
INHIBIT_PACKAGE_STRIP = "1"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"

And I should say it somehow works, but I am unable to perform dnf remove nginx-debug command as it gives me:

+ set -e
+ update-alternatives --remove nginx /usr/sbin/nginx-debug
mv: '/usr/sbin/nginx-debug' and '/usr/sbin/nginx-debug' are the same file

Also, if I install nginx (non-debug) version into clean system, it does not install any ALTERNATIVES but writes its binary. And I can't understand why it happens this way. Could you please help me understand the following:

  1. Am I right with TARGET and LINK_NAME given I need to perform the task of providing two binaries with one link?
  2. What can cause the problem with package removal? Am I correct with options for ALTERNATIVE_TARGET and ALTERNATIVE_LINK_NAME?

Thanks!

Post a comment

comment list (0)

  1. No comments so far