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

fix golang post install and post uninstall sriptlets #12026

Open
wants to merge 1 commit into
base: 3.0-dev
Choose a base branch
from

Conversation

tobiasb-ms
Copy link
Contributor

@tobiasb-ms tobiasb-ms commented Jan 22, 2025

Merge Checklist

All boxes should be checked before merging the PR (just tick any boxes which don't apply to this PR)

  • The toolchain has been rebuilt successfully (or no changes were made to it)
  • The toolchain/worker package manifests are up-to-date
  • Any updated packages successfully build (or no packages were changed)
  • Packages depending on static components modified in this PR (Golang, *-static subpackages, etc.) have had their Release tag incremented.
  • Package tests (%check section) have been verified with RUN_CHECK=y for existing SPEC files, or added to new SPEC files
  • All package sources are available
  • cgmanifest files are up-to-date and sorted (./cgmanifest.json, ./toolkit/scripts/toolchain/cgmanifest.json, .github/workflows/cgmanifest.json)
  • LICENSE-MAP files are up-to-date (./LICENSES-AND-NOTICES/SPECS/data/licenses.json, ./LICENSES-AND-NOTICES/SPECS/LICENSES-MAP.md, ./LICENSES-AND-NOTICES/SPECS/LICENSE-EXCEPTIONS.PHOTON)
  • All source files have up-to-date hashes in the *.signatures.json files
  • sudo make go-tidy-all and sudo make go-test-coverage pass
  • Documentation has been updated to match any changes to the build system
  • Ready to merge

Summary

NOTE: This change obviates #11343

golang -- both the primary (1.23) package and the 1.22 package -- has warnings during both package install and package uninstall.

For package install, we things like:

Installing/Updating: golang-1.23.3-2.azl3.x86_64
/sbin/ldconfig: relative path `1' used to build cache
warning: %post(golang-1.23.3-2.azl3.x86_64) scriptlet failed, exit status 1
package golang-1.23.3-2.azl3.x86_64: script warning in %postin

This is caused by #10654, which added the use of alternatives in both the post install and post uninstall scriptlets. The issue is:

%post -p /sbin/ldconfig

alternatives --install %{_bindir}/go go %{goroot}/bin/go %{go_priority}
alternatives --install %{_bindir}/gofmt gofmt %{goroot}/bin/gofmt %{go_priority}

By putting an executable in the %post line, it makes the scriptlet be run with that executable rather than sh. But because there's then a script after the %post line, it means the parameters are totally wrong for ldconfig -- it ends up being a temporary file containing those lines and an extra, special parameter used in the scriptlet. This causes ldconfig to fail, which gives us that warning.

This isn't the end of the world -- linkers will still work and everything, but it's definitely wrong and looks bad.

One may think that we could fix this by moving ldconfig into the script, like this:

%post
/sbin/ldconfig

alternatives --install %{_bindir}/go go %{goroot}/bin/go %{go_priority}
alternatives --install %{_bindir}/gofmt gofmt %{goroot}/bin/gofmt %{go_priority}

However, this exposes a bug in how go_priority is set -- it uses version before it's declared, which results in a completely wrong string. The good news is that we don't realistically need alternatives. And since it isn't actually being called now, we can safely remove it and if we ever think we do need it, we can add it back correctly.

So to fix this, we remove all uses of alternatives and the go_priority variable, which is now unused.

The warning during uninstall seems to have been there "forever":

Removing: golang-1.23.3-2.azl3.x86_64
rm: cannot remove '/etc/profile.d/go-exports.sh': No such file or directory

This happens because %postun calls rm %{_sysconfdir}/profile.d/go-exports.sh. However, that file is in the %files section, so the package manager itself removes it -- there's no reason to have this statement. Fix is to remove it.

Change Log
  • Remove all uses of alternatives, which also makes the %post -p /sbin/ldconfig run as expected.
  • Don't manually remove go-exports.sh
Does this affect the toolchain?

NO

Associated issues
Test Methodology

@tobiasb-ms tobiasb-ms requested a review from a team as a code owner January 22, 2025 19:04
@microsoft-github-policy-service microsoft-github-policy-service bot added Packaging 3.0-dev PRs Destined for AzureLinux 3.0 labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0-dev PRs Destined for AzureLinux 3.0 Packaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant