Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior when --add-slave and --keep-foreign used together for active alternative #102

Closed
frenzymadness opened this issue Apr 6, 2023 · 2 comments · Fixed by #104
Labels

Comments

@frenzymadness
Copy link

We have a problem in python3.11-wheel package which we can probably solve by ourselves but I think the strange behavior of alternatives I discovered is still worth reporting.

When talking about packages, I mean the ones available in RHEL 8 and I'm using 1minutetip for testing. The most important ones are chkconfig-1.19.1-1.el8.x86_64 and python3.11-wheel-0.38.4-3.el8.noarch.

To reproduce the problem on RHEL 8:

  1. dnf install python36 python3.11 (Python 3.6 is needed later.)
  2. alternatives --set python3 /usr/bin/python3.11
  3. dnf install python3.11-wheel

The installation of python3.11-wheel calls this command in its %post scriptlet:
alternatives --keep-foreign --add-slave python3 /usr/bin/python3.11 /usr/bin/wheel-3 wheel-3 /usr/bin/wheel-3.11

The command produces the following error:

Running scriptlet: python3.11-wheel-0.38.4-3.el8.noarch                                 1/1 
failed to link /usr/bin/wheel-3 -> /etc/alternatives/wheel-3: /usr/bin/wheel-3 exists and it is either not a symlink or --keep-foreign was set and link points outside /etc/alternatives

But, if you set the alternative for python3 to python36 which means that the installation of python3.11-wheel will add the slave into an inactive alternative, it works fine and no error is shown. So these steps are fine:

  1. dnf install python36 python3.11
  2. alternatives --set python3 /usr/bin/python3.6
  3. dnf install python3.11-wheel

If I understand it correctly --keep-foreign should prevent the --add-slave from removing/changing a symlink, if it already exists. If that's true, having --add-slave together with --keep-foreign makes perfect sense. The problem is that the error message is not true: /usr/bin/wheel-3 does not exist in this case. Alternatives should create that file if you install python3.11-wheel when python3.11 is the active alternative for python3.

To sum this up:

  • If python3.11 is active alternative for python3, the installation of python3.11-wheel does not create /usr/bin/wheel-3 and shows the error mentioned above.
  • If python36 is active alternative for python3, the installation succeedes without errors. Then, when you switch from python36 to python3.11 alternative, the file /usr/bin/wheel-3 is there and works as expected: /usr/bin/wheel-3 -> /etc/alternatives/wheel-3 -> /usr/bin/wheel-3.11.

Bug report with some more context: https://bugzilla.redhat.com/show_bug.cgi?id=2181479

Does it make sense to use --keep-foreign with --add-slave? If so, could we fix the problem? And if not, could we improve the error message to make it clear that this is not supported?

@lnykryn
Copy link
Member

lnykryn commented Apr 6, 2023

Yep, this is a bug. This combination should work.

If I understand it correctly --keep-foreign should prevent the --add-slave from removing/changing a symlink, if it already exists.

Well, the correct definition is: --keep-foreign prevents changing a symlink if it is not a symlink created by alternatives.

@jamacku jamacku added the bug label Apr 9, 2023
lnykryn added a commit to lnykryn/chkconfig that referenced this issue Apr 9, 2023
Normally alternatives will only refuse to create a link to /etc/alternatives/*
if the file already exists and is not a symlink. But alternatives never
checked if existing symlink goes to /etc/alternatives/.

This is a weird behavior, but we did not want to change the default
behavior so we added --keep-foreign option that is more strict and
checks that the target if the symlink is in /etc/alternatives/.

But we missed the corner-case where there is no file at all and
incorrectly reported on error.

Fixes fedora-sysv#102
lnykryn added a commit to lnykryn/chkconfig that referenced this issue Apr 9, 2023
Normally alternatives will only refuse to create a link to /etc/alternatives/*
if the file already exists and is not a symlink. But alternatives never
checked if existing symlink goes to /etc/alternatives/.

This is a weird behavior, but we did not want to change the default
behavior so we added --keep-foreign option that is more strict and
checks that the target if the symlink is in /etc/alternatives/.

But we missed the corner-case where there is no file at all and
incorrectly reported on error.

Fixes fedora-sysv#102
@jamacku jamacku linked a pull request Apr 10, 2023 that will close this issue
lnykryn added a commit to lnykryn/chkconfig that referenced this issue Apr 13, 2023
Normally alternatives will only refuse to create a link to /etc/alternatives/*
if the file already exists and is not a symlink. But alternatives never
checked if existing symlink goes to /etc/alternatives/.

This is a weird behavior, but we did not want to change the default
behavior so we added --keep-foreign option that is more strict and
checks that the target if the symlink is in /etc/alternatives/.

But we missed the corner-case where there is no file at all and
incorrectly reported on error.

Fixes fedora-sysv#102
jamacku pushed a commit that referenced this issue Apr 13, 2023
Normally alternatives will only refuse to create a link to /etc/alternatives/*
if the file already exists and is not a symlink. But alternatives never
checked if existing symlink goes to /etc/alternatives/.

This is a weird behavior, but we did not want to change the default
behavior so we added --keep-foreign option that is more strict and
checks that the target if the symlink is in /etc/alternatives/.

But we missed the corner-case where there is no file at all and
incorrectly reported on error.

Fixes #102
@frenzymadness
Copy link
Author

Thank you for the fix!

jamacku pushed a commit to jamacku/chkconfig that referenced this issue May 15, 2023
Normally alternatives will only refuse to create a link to /etc/alternatives/*
if the file already exists and is not a symlink. But alternatives never
checked if existing symlink goes to /etc/alternatives/.

This is a weird behavior, but we did not want to change the default
behavior so we added --keep-foreign option that is more strict and
checks that the target if the symlink is in /etc/alternatives/.

But we missed the corner-case where there is no file at all and
incorrectly reported on error.

Fixes fedora-sysv#102

(cherry picked from commit bd9b6cc)
jamacku pushed a commit that referenced this issue May 15, 2023
Normally alternatives will only refuse to create a link to /etc/alternatives/*
if the file already exists and is not a symlink. But alternatives never
checked if existing symlink goes to /etc/alternatives/.

This is a weird behavior, but we did not want to change the default
behavior so we added --keep-foreign option that is more strict and
checks that the target if the symlink is in /etc/alternatives/.

But we missed the corner-case where there is no file at all and
incorrectly reported on error.

Fixes #102

(cherry picked from commit bd9b6cc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants