cmd/snap, packaging: multi entry binary [WIP]#17145
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #17145 +/- ##
==========================================
+ Coverage 79.12% 79.17% +0.05%
==========================================
Files 1388 1385 -3
Lines 193484 193455 -29
Branches 2466 2466
==========================================
+ Hits 153093 153177 +84
+ Misses 31205 31094 -111
+ Partials 9186 9184 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Mon Jun 15 14:46:38 UTC 2026 Failures:Preparing:
Executing:
Restoring:
Skipped tests from snapd-testing-skipIf you wish to have any of the below tests run in your PR, in your PR description, add 'unskip:' followed by a copy-and-pasted list (without variants) of the below tests you wish to run (unskip plus test list must be valid yaml)
|
b9fbfb6 to
abbeecf
Compare
|
Love this @bboozzoo |
|
@kubiko I'm looking into merging snapctl (~8MB) and snap-exec (~5MB) - should save ~1-2MB on the snap size and we benefit from sharing page cache of binaries that are always (snap-exec) or very often (snapctl) called during startup. |
|
@bboozzoo yeah I was thinking about those as well, as they are called often, smaller gain, but prime candidates indeed. |
00032f8 to
18f1690
Compare
There was a problem hiding this comment.
Pull request overview
This draft PR restructures snapd’s delivered binaries so the snap client can also serve as the snapd daemon entrypoint (via argv0/symlink dispatch), with corresponding updates across packaging and test suites to reflect the new layout.
Changes:
- Merge daemon entrypoint into
cmd/snap(run daemon mode when invoked assnapd) and refactorsnapdmain into an importable package. - Update distro packaging and snapcraft build logic to stop shipping a standalone
snapdbinary and instead provide/usr/lib/snapd/snapd -> /usr/bin/snap. - Adjust spread/tests/docs and a few runtime paths to align with the new
snapdexecutable location (.../usr/bin/snap), including FIPS variant handling.
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/smoke/hacking-md/task.yaml | Drops building a separate snapd binary from HACKING.md snippet smoke checks. |
| tests/main/static/task.yaml | Updates static build test to build cmd/snap instead of cmd/snapd. |
| tests/main/snapd-reexec/task.yaml | Updates re-exec test bind-mount paths from usr/lib/snapd/snapd to usr/bin/snap. |
| tests/main/snap-cli-no-managers/task.yaml | Adjusts import expectations now that snap includes snapd; keeps snap-bootstrap constraint. |
| tests/lib/snapd-standalone/entry.go | Adds a small standalone entry program calling daemon/snapd.Main(). |
| spread.yaml | Updates re-exec memory map assertion to match .../usr/bin/snap. |
| snap/quota/resources.go | Lazily checks memory cgroup support via sync.Once when memory quotas are requested. |
| packaging/ubuntu-26.04/snapd.links | Adds /usr/lib/snapd/snapd link pointing to /usr/bin/snap. |
| packaging/ubuntu-26.04/snapd.install.in | Stops installing a standalone usr/bin/snapd into /usr/lib/snapd/. |
| packaging/ubuntu-26.04/rules | Removes dedicated cmd/snap build step and updates comments for new tag usage. |
| packaging/ubuntu-16.04/snapd.links | Adds /usr/lib/snapd/snapd link pointing to /usr/bin/snap. |
| packaging/ubuntu-16.04/snapd.install.in | Stops installing a standalone usr/bin/snapd into /usr/lib/snapd/. |
| packaging/ubuntu-16.04/rules | Removes dedicated cmd/snap build step and updates comments for new tag usage. |
| packaging/snapd.mk | Removes standalone snapd build/install; adds symlink install rules for snapctl and snapd -> snap. |
| packaging/debian-sid/snapd.links | Adds /usr/lib/snapd/snapd link pointing to /usr/bin/snap. |
| packaging/debian-sid/snapd.install | Stops installing a standalone usr/bin/snapd into /usr/lib/snapd/. |
| packaging/debian-sid/rules | Removes cmd/snapd from the dh-golang build package list. |
| overlord/snapstate/export_test.go | Updates exports for catalog refresh delay testing and adds a getter for per-instance delta. |
| overlord/snapstate/catalogrefresh.go | Moves refresh delta to be stored per catalogRefresh instance instead of global var. |
| overlord/snapstate/catalogrefresh_test.go | Updates tests to assert against the per-instance delay delta. |
| overlord/servicestate/quota_control.go | Makes systemd version check lazy via sync.Once instead of eager init-time call. |
| overlord/managers_test.go | Adds cgroup v2 controller-file setup for quota-related test coverage under mocked root. |
| overlord/hookstate/hookmgr.go | Adjusts snap command path detection for merged snap/snapd and snap-fips layouts. |
| HACKING.md | Updates documentation to reflect building snap (now including daemon functionality) and removes standalone snapd build instructions. |
| daemon/snapd/main.go | Refactors daemon entrypoint from package main to package snapd with exported Main(), and sets plug/slot sanitizer. |
| daemon/snapd/main_test.go | Updates test package/imports to match daemon/snapd refactor. |
| daemon/snapd/export_test.go | Updates package name to match daemon/snapd refactor. |
| daemon/export_test.go | Adds a test helper to reset cached virtualization detection state. |
| daemon/export_api_general_test.go | Updates virtualization mocking to hook into the new sync.Once-based detection. |
| daemon/api_notices_test.go | Adds coverage for snap-fips path behavior when detecting snap cmd under re-exec. |
| daemon/api_general.go | Caches systemd-detect-virt output via sync.Once and exposes a mockable setter for tests. |
| daemon/api_base_test.go | Resets virtualization detection between daemon API tests for determinism. |
| daemon/access.go | Updates snap cmd identity check to allow both snap and snap-fips under snapd re-exec. |
| cmd/snap/main.go | Adds argv0-based dispatch into daemon mode when invoked as snapd. |
| cmd/snap/main_snapd.go | Linux-only daemon-mode bridge calling daemon/snapd.Main(). |
| cmd/snap/main_snapd_stub.go | Non-Linux stub for daemon mode with an error message. |
| build-aux/snap/snapcraft.yaml | Stops building/shipping lib/snapd/snapd as a separate binary; wires symlinks and updates tag selection for merged binary and FIPS layout. |
| // 1. maybe symlink from snapd -> snap | ||
| if argv0 == "snapd" { | ||
| snapdMain() | ||
| panic("not reached") | ||
| } |
|
|
||
| details: | | ||
| This test checks that snap binary does not import snapstate when built | ||
| This test checks that snapstate is not imported when binaries are built built |
| base := filepath.Base(exe) | ||
| // Depending on the build variant of the snapd snap, the command could | ||
| // either be $SNAPD_MOUNT/usr/bin/snap or $SNAP_MOUNT/usr/bin/snap-fips | ||
| if base == "snap" || base == "snap-fips" { | ||
| return true, nil |
| func ResetVirtualizationDetection() { | ||
| systemdVirtOnce = sync.Once{} | ||
| } |
18f1690 to
2c09050
Compare
| if snapdenv.Preseeding() { | ||
| logger.Noticef("running for preseeding") | ||
| } else { | ||
| snapdtool.ExecInSnapdOrCoreSnap() |
There was a problem hiding this comment.
this could be dropped
0ebc1fc to
39ea40b
Compare
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
…e rather than a global one Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
…pers in tests Signed-off-by: Maciej Borzecki <[email protected]>
39ea40b to
f13b636
Compare
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
… snap Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Note, the caller still has to be allowed to transition to snapp_t context, which is currently only allowed for init_t. Signed-off-by: Maciej Borzecki <[email protected]>
…nning on SELinux enabled systems Set a desired SELinuxContext for the snapd service. The policy must alreayd allow transition from init_t -> snappy_t. Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
…erve and pokit are undesired Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
f13b636 to
1e958c1
Compare
This is a draft WIP branch of multi entry snapd binary.
Initial comparison shows that merging the standalone snapd binary into /usr/bin/snap allows us to save ~13% on the size of the snap, 50.5MB -> 44.1MB. The run time savings are likely noticeable as instead of a 31MB (snapd) + 23MB (snap) binaries, we now have a single 33MB (snap) binary, which should help reducing the IO and make better use of the cache.
Related: SNAPDENG-36950