Repository navigation
fix(systemd): bind autostart to the graphical session #11
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
Open
hualet
wants to merge
1
commit into
main
Choose a base branch
from
fix/graphical-session-autostart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/sh | ||
| # SPDX-FileCopyrightText: 2026 Hualet Wang | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
| set -e | ||
|
|
||
| # Migrate the old default.target links before debhelper records the new ones. | ||
| # Preserve services disabled by the administrator. | ||
| if [ "$1" = configure ] && [ -z "${DPKG_ROOT:-}" ]; then | ||
| for unit in echoflow.service echoflow-ui.service; do | ||
| if deb-systemd-helper --quiet --user debian-installed "$unit" && | ||
| deb-systemd-helper --quiet --user was-enabled "$unit"; then | ||
| deb-systemd-helper --user reenable "$unit" >/dev/null || true | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| #DEBHELPER# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: 2026 Hualet Wang | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
| set -euo pipefail | ||
|
|
||
| ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" | ||
| TEST_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/echoflow-systemd-spec.XXXXXX")" | ||
| trap 'rm -rf "$TEST_ROOT"' EXIT | ||
| HELPER="$(command -v deb-systemd-helper || true)" | ||
| if [[ -z "$HELPER" ]]; then | ||
| echo 'SKIP - deb-systemd-helper is not installed' | ||
| exit 0 | ||
| fi | ||
|
|
||
| fail() { echo "FAIL - $*" >&2; exit 1; } | ||
|
|
||
| # Exercise the real Debian helper without touching the host service state. | ||
| mkdir -p "$TEST_ROOT/bin" | ||
| export HELPER | ||
| export DPKG_MAINTSCRIPT_PACKAGE=echoflow | ||
| cat > "$TEST_ROOT/bin/deb-systemd-helper" <<'EOF' | ||
| #!/bin/sh | ||
| DPKG_ROOT="$TEST_PACKAGE_ROOT" exec "$HELPER" "$@" | ||
| EOF | ||
| chmod +x "$TEST_ROOT/bin/deb-systemd-helper" | ||
|
|
||
| for scenario in enabled disabled fresh preset-disabled; do | ||
| export TEST_PACKAGE_ROOT="$TEST_ROOT/$scenario" | ||
| units="$TEST_PACKAGE_ROOT/usr/lib/systemd/user" | ||
| mkdir -p "$units" "$TEST_PACKAGE_ROOT/usr/bin" "$TEST_PACKAGE_ROOT/etc/systemd/user-preset" | ||
| printf '[Unit]\nDescription=Test user manager\n' > "$units/default.target" | ||
| printf '[Unit]\nDescription=Test graphical session\n' > "$units/graphical-session.target" | ||
| ln -s "$(command -v systemctl)" "$TEST_PACKAGE_ROOT/usr/bin/systemctl" | ||
| if [[ "$scenario" == preset-disabled ]]; then | ||
| printf 'disable echoflow*\n' > "$TEST_PACKAGE_ROOT/etc/systemd/user-preset/00-test.preset" | ||
| fi | ||
| for unit in echoflow.service echoflow-ui.service; do | ||
| sed -e 's|@CMAKE_INSTALL_FULL_BINDIR@|/usr/bin|g' \ | ||
| -e 's/WantedBy=graphical-session.target/WantedBy=default.target/' \ | ||
| "$ROOT/systemd/user/$unit.in" > "$units/$unit" | ||
| if [[ "$scenario" == enabled || "$scenario" == disabled ]]; then | ||
| DPKG_ROOT="$TEST_PACKAGE_ROOT" "$HELPER" --user enable "$unit" | ||
| if [[ "$scenario" == disabled ]]; then | ||
| DPKG_ROOT="$TEST_PACKAGE_ROOT" "$HELPER" --user disable "$unit" | ||
| fi | ||
| fi | ||
| sed 's|@CMAKE_INSTALL_FULL_BINDIR@|/usr/bin|g' \ | ||
| "$ROOT/systemd/user/$unit.in" > "$units/$unit" | ||
| done | ||
|
|
||
| # The maintscript must run before debhelper updates its recorded link state. | ||
| env -u DPKG_ROOT PATH="$TEST_ROOT/bin:$PATH" sh "$ROOT/debian/postinst" configure | ||
| for unit in echoflow.service echoflow-ui.service; do | ||
| if [[ "$scenario" == fresh || "$scenario" == preset-disabled ]]; then | ||
| if DPKG_ROOT="$TEST_PACKAGE_ROOT" "$HELPER" --quiet --user debian-installed "$unit"; then | ||
| fail "migration bypassed first-install preset handling: $unit" | ||
| fi | ||
| fi | ||
| # Complete the normal debhelper enable/update-state sequence. | ||
| if DPKG_ROOT="$TEST_PACKAGE_ROOT" "$HELPER" --quiet --user was-enabled "$unit"; then | ||
| DPKG_ROOT="$TEST_PACKAGE_ROOT" "$HELPER" --user enable "$unit" | ||
| else | ||
| DPKG_ROOT="$TEST_PACKAGE_ROOT" "$HELPER" --user update-state "$unit" | ||
| fi | ||
| old="$TEST_PACKAGE_ROOT/etc/systemd/user/default.target.wants/$unit" | ||
| new="$TEST_PACKAGE_ROOT/etc/systemd/user/graphical-session.target.wants/$unit" | ||
| [[ ! -L "$old" ]] || fail "$scenario retained boot-only link: $unit" | ||
| if [[ "$scenario" == disabled || "$scenario" == preset-disabled ]]; then | ||
| [[ ! -L "$new" ]] || fail "upgrade enabled a disabled service: $unit" | ||
| else | ||
| [[ -L "$new" ]] || fail "$scenario missing session autostart: $unit" | ||
| fi | ||
| done | ||
| done | ||
| echo 'ok - Debian session autostart migration preserves disabled services and presets' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · User link migration goes unverified
When the fake
systemctlis used for the user-install migration check,test_onboarding_install.shaccepts the loggedreenablecommand at line 98 as migration success; its fakesystemctlat lines 41–48 only logs arguments and always exits zero, so the test passes with the olddefault.targetlink unchanged.Assert the resulting link state using an isolated systemd-compatible helper, or make the fake model
reenableand verify that it replaces the old link.Prompt for AI agents