Compare commits
7
Commits
939f21a946
..
v0.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01217ef040
|
||
|
|
d921e38baa
|
||
|
|
ff10e8bbd2
|
||
|
|
b5951fac0b
|
||
|
|
f3449f9cca
|
||
|
|
c172346052
|
||
|
|
9dac8ee088
|
No files matched your search
@@ -0,0 +1,109 @@
|
||||
name: package
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
# Only a version change produces a release; other commits stay off this path.
|
||||
paths: [version]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
# Releases are ordered: a second run waits instead of racing for the same tag.
|
||||
concurrency:
|
||||
group: package
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
package:
|
||||
# Arch containers cannot be stored on the NTFS runner disk: pacman's local
|
||||
# database uses ':' in epoch directory names, which NTFS rejects. The package
|
||||
# is therefore built by makepkg on the Arch host itself.
|
||||
runs-on: arch-host
|
||||
env:
|
||||
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Read the version file
|
||||
id: version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version="$(tr -d '[:space:]' < version)"
|
||||
if [ -z "$version" ]; then
|
||||
echo "::error file=version::the version file is empty"
|
||||
exit 1
|
||||
fi
|
||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build the Arch package
|
||||
id: package
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version='${{ steps.version.outputs.version }}'
|
||||
work="$RUNNER_TEMP/build"
|
||||
rm -rf "$work"
|
||||
mkdir -p "$work"
|
||||
cp PKGBUILD version "$work/"
|
||||
git archive --format=tar.gz --prefix="fws-deskmanager-$version/" \
|
||||
-o "$work/fws-deskmanager-$version.tar.gz" HEAD
|
||||
# makepkg needs the PKGBUILD, the version file it reads and the source
|
||||
# tarball in one directory; the runner's checkout stays untouched.
|
||||
cd "$work"
|
||||
makepkg --noconfirm --nodeps --force --cleanbuild
|
||||
asset="$(ls -1 ./*.pkg.tar.zst | grep -v -- '-debug-' | head -1)"
|
||||
echo "file=$work/${asset##*/}" >> "$GITHUB_OUTPUT"
|
||||
echo "name=${asset##*/}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Create the release and attach the package
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY"
|
||||
version='${{ steps.version.outputs.version }}'
|
||||
tag="v$version"
|
||||
name="${{ steps.package.outputs.name }}"
|
||||
file="${{ steps.package.outputs.file }}"
|
||||
auth="Authorization: token $GITEA_TOKEN"
|
||||
|
||||
release_id="$(curl -sS -H "$auth" "$api/releases/tags/$tag" | jq -r 'if type == "object" then (.id // empty) else empty end')"
|
||||
if [ -z "$release_id" ]; then
|
||||
body="FWS-DeskManager $version
|
||||
|
||||
Arch package: \`$name\`"
|
||||
release_id="$(curl -sS --fail-with-body -X POST -H "$auth" -H 'Content-Type: application/json' \
|
||||
-d "$(jq -n --arg tag "$tag" --arg name "FWS-DeskManager $version" \
|
||||
--arg body "$body" '{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')" \
|
||||
"$api/releases" | jq -r '.id')"
|
||||
fi
|
||||
|
||||
# A re-run must not fail on its own previous asset.
|
||||
previous="$(curl -sS -H "$auth" "$api/releases/$release_id/assets" \
|
||||
| jq -r --arg n "$name" '.[] | select(.name == $n) | .id')"
|
||||
if [ -n "$previous" ]; then
|
||||
curl -sS -X DELETE -H "$auth" "$api/releases/assets/$previous" -o /dev/null
|
||||
fi
|
||||
|
||||
curl -sS --fail-with-body -X POST -H "$auth" \
|
||||
-F "attachment=@$file" \
|
||||
"$api/releases/$release_id/assets?name=$name" -o /dev/null
|
||||
echo "attached $name to release $tag"
|
||||
|
||||
- name: Publish to repo.laxacube.ch
|
||||
if: env.REPO_TOKEN != ''
|
||||
run: |
|
||||
set -euo pipefail
|
||||
file="${{ steps.package.outputs.file }}"
|
||||
name="${{ steps.package.outputs.name }}"
|
||||
curl -sS --fail-with-body -X POST https://repo.laxacube.ch/api/packages \
|
||||
-H "Authorization: Bearer $REPO_TOKEN" \
|
||||
-H "X-Filename: $name" \
|
||||
-H 'Content-Type: application/octet-stream' \
|
||||
--data-binary "@$file"
|
||||
echo
|
||||
|
||||
- name: Warn when the upload token is missing
|
||||
if: env.REPO_TOKEN == ''
|
||||
run: echo "::warning::REPO_TOKEN is not set, the package was released but not published to repo.laxacube.ch"
|
||||
@@ -0,0 +1,23 @@
|
||||
name: version
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
print-version:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Read version file
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version="$(tr -d '[:space:]' < version)"
|
||||
if [ -z "$version" ]; then
|
||||
echo "::error file=version::the version file is empty"
|
||||
exit 1
|
||||
fi
|
||||
echo "FWS-DeskManager version: $version"
|
||||
@@ -36,3 +36,7 @@
|
||||
# Build directories
|
||||
build/
|
||||
build-*/
|
||||
|
||||
# ---> makepkg
|
||||
pkg/
|
||||
*.pkg.tar.*
|
||||
@@ -0,0 +1,27 @@
|
||||
# Maintainer: FWS
|
||||
# The version file is the single source of truth for releases, so the package
|
||||
# version follows it instead of being duplicated here.
|
||||
pkgname=fws-deskmanager
|
||||
pkgver=$(tr -d '[:space:]' < version)
|
||||
pkgrel=1
|
||||
pkgdesc="Switch desktop environments on Arch Linux without rebooting"
|
||||
arch=('x86_64')
|
||||
url="https://gitea.nocode-var.tech/FWS/FWS-DeskManger"
|
||||
license=('unknown')
|
||||
depends=('gtk4' 'systemd' 'polkit')
|
||||
makedepends=('cmake' 'pkgconf')
|
||||
# Release packages only: the debug split package has no use for end users.
|
||||
options=('!debug')
|
||||
source=("$pkgname-$pkgver.tar.gz")
|
||||
sha256sums=('SKIP')
|
||||
|
||||
build() {
|
||||
cmake -S "$pkgname-$pkgver" -B build \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=/usr
|
||||
cmake --build build -j"$(nproc)"
|
||||
}
|
||||
|
||||
package() {
|
||||
DESTDIR="$pkgdir" cmake --install build
|
||||
}
|
||||
@@ -109,9 +109,9 @@ l'installation (sortie pacman) sont disponibles dans un panneau dépliable.
|
||||
## Utilisation
|
||||
|
||||
Tout se fait dans la fenêtre : installer, lancer, basculer, revenir à l'écran de
|
||||
connexion. Le binaire n'expose pas de sous-commandes ; `--privileged-launch` est un
|
||||
mode interne que l'application s'appelle elle-même à travers `pkexec` pendant un
|
||||
démarrage sans greeter.
|
||||
connexion. Le binaire n'expose pas de sous-commandes ; `--privileged-launch` et
|
||||
`--privileged-cleanup` sont des modes internes que l'application s'appelle elle-même à
|
||||
travers `pkexec` pendant un démarrage sans greeter.
|
||||
|
||||
## Obtenir deux sessions
|
||||
|
||||
@@ -139,6 +139,12 @@ un clic, sans fermer la moindre application.
|
||||
sessions remplacées sont fermées par une unité systemd transitoire, pour que le
|
||||
nettoyage survive à la session qu'il ferme. En cas d'échec, le fichier est retiré et
|
||||
la session précédente réactivée.
|
||||
Le fichier porte une ligne de marque, et son effacement ne dépend pas du mode
|
||||
privilégié : une unité systemd transitoire est créée avant l'écriture et son
|
||||
`ExecStopPost` supprime le fichier quand elle est arrêtée, quand son `RuntimeMaxSec`
|
||||
expire (mode privilégié tué) et pendant l'extinction de la machine. Le mode privilégié
|
||||
intercepte aussi `SIGTERM`/`SIGINT`/`SIGHUP` pour faire le nettoyage lui-même, et
|
||||
chaque lancement balaie un résidu laissé par une exécution précédente.
|
||||
4. `greeter` demande l'écran de connexion, sans rien tuer : interface
|
||||
`org.freedesktop.DisplayManager` (`SwitchToGreeter`) implémentée par GDM, SDDM et
|
||||
LightDM, puis `dm-tool switch-to-greeter`, puis activation d'une session `Class=greeter`
|
||||
@@ -172,8 +178,11 @@ identifiants de session sont validés comme numériques.
|
||||
perdues, comme une déconnexion. Les sessions des autres environnements déjà ouvertes
|
||||
sont également fermées.
|
||||
- **`launch` modifie la configuration du gestionnaire d'affichage** : un fichier
|
||||
d'autologin est ajouté le temps du démarrage puis supprimé. Si le processus est tué
|
||||
entre-temps, le supprimer à la main (`/etc/sddm.conf.d/zz-fws-autologin.conf`).
|
||||
d'autologin marqué est ajouté le temps du démarrage, puis supprimé par le mode
|
||||
privilégié et par l'unité de nettoyage — y compris s'il est tué (au plus tard après
|
||||
trois minutes) ou lors de l'extinction. Un lancement ne laisse donc pas de connexion
|
||||
automatique au démarrage suivant ; la fenêtre signale un résidu éventuel, et le
|
||||
lancement suivant le retire.
|
||||
- **Wayland** : impossible de lancer un compositeur Wayland depuis une session Wayland
|
||||
sans passer par logind/DRM master ; le démarrage direct n'est pas implémenté (#6).
|
||||
- **`greeter` ne ferme plus la session courante** : au login suivant, SDDM/GDM peuvent
|
||||
|
||||
+13
@@ -444,6 +444,14 @@ private:
|
||||
|
||||
buildRows();
|
||||
refreshRows();
|
||||
|
||||
// A launch killed before its cleanup leaves the autologin armed: the next
|
||||
// launch clears it, but the window has to say so before the reboot.
|
||||
const std::string stale = fws::staleAutologinFile();
|
||||
if (!stale.empty()) {
|
||||
setStatus("Autologin residuel (« " + stale +
|
||||
" ») : le prochain lancement le supprime.");
|
||||
}
|
||||
}
|
||||
|
||||
void buildRows() {
|
||||
@@ -826,5 +834,10 @@ int main(int argc, char** argv) {
|
||||
if (argc == 4 && std::string(argv[1]) == "--privileged-launch") {
|
||||
return fws::runLaunchHelper(argv[2], argv[3]);
|
||||
}
|
||||
// Same re-entry for removing a drop-in, which the watchdog unit runs as root
|
||||
// when it notices a launch that never cleaned up.
|
||||
if (argc == 2 && std::string(argv[1]) == "--privileged-cleanup") {
|
||||
return fws::runAutologinCleanup();
|
||||
}
|
||||
return ManagerWindow::run(argc, argv);
|
||||
}
|
||||
+225
-11
@@ -11,6 +11,7 @@
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -29,6 +30,41 @@ constexpr int kLoginTimeoutMs = 90000;
|
||||
constexpr const char* kHelperName = "fws-deskmanager";
|
||||
// Hidden switch that turns the single binary into the privileged helper.
|
||||
constexpr const char* kHelperMode = "--privileged-launch";
|
||||
// Hidden switch for the privileged removal of a drop-in. The watchdog unit calls
|
||||
// it on its own, so it has to work with no other argument.
|
||||
constexpr const char* kCleanupMode = "--privileged-cleanup";
|
||||
|
||||
// One-shot autologin drop-ins this tool owns. Display managers read a directory
|
||||
// rather than a single file, so a launch adds a file of its own instead of
|
||||
// editing the configuration the administrator maintains.
|
||||
constexpr const char* kSddmDropIn = "/etc/sddm.conf.d/zz-fws-autologin.conf";
|
||||
constexpr const char* kLightdmDropIn = "/etc/lightdm/lightdm.conf.d/99-fws-autologin.conf";
|
||||
|
||||
// First line of every drop-in. A launch killed before its cleanup leaves the
|
||||
// file behind, and this marker is what lets the tool delete it later without
|
||||
// ever touching a configuration it did not write.
|
||||
constexpr const char* kDropInMarker =
|
||||
"# FWS-DeskManager one-shot autologin - removed automatically";
|
||||
|
||||
// A killed launch must not keep the autologin armed: the transient unit started
|
||||
// alongside the drop-in deletes it when stopped, on timeout, and while the
|
||||
// machine shuts down.
|
||||
constexpr int kWatchdogSeconds = 180;
|
||||
|
||||
// The helper waits up to ninety seconds for the seat: a terminated launch still
|
||||
// has to reach its cleanup instead of dying inside the sleep.
|
||||
volatile std::sig_atomic_t g_interrupted = 0;
|
||||
|
||||
void onTerminationSignal(int) { g_interrupted = 1; }
|
||||
|
||||
void catchTerminationSignals() {
|
||||
struct sigaction action {};
|
||||
action.sa_handler = onTerminationSignal;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGTERM, &action, nullptr);
|
||||
sigaction(SIGINT, &action, nullptr);
|
||||
sigaction(SIGHUP, &action, nullptr);
|
||||
}
|
||||
|
||||
std::string lower(std::string value) {
|
||||
std::transform(value.begin(), value.end(), value.begin(),
|
||||
@@ -61,14 +97,15 @@ bool autologinFile(const std::string& unit, const std::string& user,
|
||||
const std::string& sessionFile, std::filesystem::path& path,
|
||||
std::string& content) {
|
||||
if (unit == "sddm.service") {
|
||||
path = "/etc/sddm.conf.d/zz-fws-autologin.conf";
|
||||
content = "[Autologin]\nUser=" + user + "\nSession=" + sessionFile + "\nRelogin=false\n";
|
||||
path = kSddmDropIn;
|
||||
content = std::string(kDropInMarker) + "\n[Autologin]\nUser=" + user +
|
||||
"\nSession=" + sessionFile + "\nRelogin=false\n";
|
||||
return true;
|
||||
}
|
||||
if (unit == "lightdm.service") {
|
||||
path = "/etc/lightdm/lightdm.conf.d/99-fws-autologin.conf";
|
||||
content = "[Seat:*]\nautologin-user=" + user + "\nautologin-session=" + sessionFile +
|
||||
"\nautologin-user-timeout=0\n";
|
||||
path = kLightdmDropIn;
|
||||
content = std::string(kDropInMarker) + "\n[Seat:*]\nautologin-user=" + user +
|
||||
"\nautologin-session=" + sessionFile + "\nautologin-user-timeout=0\n";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -104,6 +141,73 @@ bool writeTextFile(const std::filesystem::path& path, const std::string& content
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::string> dropInPaths() { return {kSddmDropIn, kLightdmDropIn}; }
|
||||
|
||||
bool carriesMarker(const std::string& content) {
|
||||
return content.find(kDropInMarker) != std::string::npos;
|
||||
}
|
||||
|
||||
// Drop-ins written by builds that had no marker are still ours when they hold
|
||||
// nothing but the keys this tool writes: one launch or `cleanup` clears them.
|
||||
bool onlyOwnedKeys(const std::string& content) {
|
||||
static const std::vector<std::string> kOwnedKeys = {
|
||||
"[autologin]", "[seat:*]", "user=",
|
||||
"session=", "relogin=", "autologin-user=",
|
||||
"autologin-session=", "autologin-user-timeout="};
|
||||
for (const std::string& line : splitLines(content)) {
|
||||
if (line[0] == '#' || line[0] == ';') {
|
||||
continue;
|
||||
}
|
||||
std::string key = lower(line);
|
||||
const std::size_t equals = key.find('=');
|
||||
if (equals != std::string::npos) {
|
||||
key = key.substr(0, equals + 1);
|
||||
}
|
||||
if (std::find(kOwnedKeys.begin(), kOwnedKeys.end(), key) == kOwnedKeys.end()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ownsDropIn(const std::filesystem::path& path) {
|
||||
std::error_code code;
|
||||
if (!std::filesystem::is_regular_file(path, code)) {
|
||||
return false;
|
||||
}
|
||||
const std::string content = readTextFile(path);
|
||||
if (content.empty()) {
|
||||
return false;
|
||||
}
|
||||
return carriesMarker(content) || onlyOwnedKeys(content);
|
||||
}
|
||||
|
||||
std::string firstOwnedDropIn() {
|
||||
for (const std::string& path : dropInPaths()) {
|
||||
if (ownsDropIn(path)) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool removeOwnedDropIns(std::vector<std::string>& removed, std::string& error) {
|
||||
bool ok = true;
|
||||
for (const std::string& path : dropInPaths()) {
|
||||
if (!ownsDropIn(path)) {
|
||||
continue;
|
||||
}
|
||||
std::error_code code;
|
||||
if (std::filesystem::remove(path, code)) {
|
||||
removed.push_back(path);
|
||||
} else {
|
||||
ok = false;
|
||||
error = "Impossible de supprimer " + path + " : " + code.message();
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
std::string currentUserName() {
|
||||
const passwd* account = getpwuid(getuid());
|
||||
return account != nullptr ? std::string(account->pw_name) : std::string();
|
||||
@@ -124,6 +228,45 @@ std::string launchHelperPath() {
|
||||
return findExecutable(kHelperName);
|
||||
}
|
||||
|
||||
// The drop-in is only safe if something outside the helper can delete it. The
|
||||
// unit below lives for the whole launch and its ExecStopPost fires when the unit
|
||||
// is stopped by us, when RuntimeMaxSec expires after a killed helper, and when
|
||||
// systemd shuts the machine down.
|
||||
std::string startCleanupWatchdog(const std::string& helper, std::string& error) {
|
||||
if (helper.empty()) {
|
||||
error = "Le nettoyage de l'autologin n'a pas de binaire a appeler";
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string stopCommand = helper;
|
||||
if (stopCommand.find(' ') != std::string::npos) {
|
||||
stopCommand = "\"" + stopCommand + "\"";
|
||||
}
|
||||
stopCommand += std::string(" ") + kCleanupMode;
|
||||
|
||||
const std::string unit = "fws-deskmanager-autologin-" + std::to_string(getpid());
|
||||
const CommandResult result = runCommand(
|
||||
{"systemd-run", "--quiet", "--collect", "--unit=" + unit,
|
||||
"--property=RuntimeMaxSec=" + std::to_string(kWatchdogSeconds),
|
||||
"--property=ExecStopPost=" + stopCommand, "/bin/sleep",
|
||||
std::to_string(kWatchdogSeconds)});
|
||||
if (!result.started || result.exitCode != 0) {
|
||||
const std::string detail = trim(result.output);
|
||||
error = "Nettoyage automatique de l'autologin impossible (systemd-run)";
|
||||
if (!detail.empty()) {
|
||||
error += " : " + detail;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
return unit;
|
||||
}
|
||||
|
||||
void stopCleanupWatchdog(const std::string& unit) {
|
||||
if (!unit.empty()) {
|
||||
runCommand({"systemctl", "stop", unit});
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> desktopNamesFor(const std::string& sessionFile) {
|
||||
std::vector<std::string> names;
|
||||
for (const DesktopEntry& entry : listInstalledDesktops()) {
|
||||
@@ -237,6 +380,26 @@ bool canStartWithoutGreeter(std::string& reason) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string staleAutologinFile() { return firstOwnedDropIn(); }
|
||||
|
||||
int runAutologinCleanup() {
|
||||
if (geteuid() != 0) {
|
||||
std::cerr << "Cette commande doit etre lancee en root (pkexec).\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<std::string> removed;
|
||||
std::string error;
|
||||
if (!removeOwnedDropIns(removed, error)) {
|
||||
std::cerr << error << "\n";
|
||||
return 1;
|
||||
}
|
||||
for (const std::string& path : removed) {
|
||||
std::cout << "Autologin residuel supprime : " << path << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LaunchOutcome launchDesktop(const DesktopProfile& profile) {
|
||||
LaunchOutcome outcome;
|
||||
|
||||
@@ -298,6 +461,11 @@ LaunchOutcome launchDesktop(const DesktopProfile& profile) {
|
||||
const std::string message = trim(result.output);
|
||||
outcome.error = message.empty() ? "Le demarrage de " + profile.name + " a echoue."
|
||||
: message;
|
||||
if (!firstOwnedDropIn().empty()) {
|
||||
outcome.error +=
|
||||
" Un autologin residuel subsiste ; l'unite de nettoyage le retirera, au plus "
|
||||
"tard a l'extinction.";
|
||||
}
|
||||
return outcome;
|
||||
}
|
||||
|
||||
@@ -322,6 +490,18 @@ int runLaunchHelper(const std::string& user, const std::string& sessionFile) {
|
||||
}
|
||||
const std::string uid = std::to_string(account->pw_uid);
|
||||
|
||||
// A previous launch may have been killed before its cleanup: start from a
|
||||
// clean state, so the drop-in written below is the only one in place.
|
||||
std::vector<std::string> staleFiles;
|
||||
std::string staleError;
|
||||
if (!removeOwnedDropIns(staleFiles, staleError)) {
|
||||
std::cerr << staleError << "\n";
|
||||
return 3;
|
||||
}
|
||||
for (const std::string& stale : staleFiles) {
|
||||
std::cout << "Autologin residuel supprime : " << stale << "\n";
|
||||
}
|
||||
|
||||
std::filesystem::path configPath;
|
||||
std::string content;
|
||||
if (!autologinFile(displayManagerUnit(), user, sessionFile, configPath, content)) {
|
||||
@@ -344,9 +524,24 @@ int runLaunchHelper(const std::string& user, const std::string& sessionFile) {
|
||||
std::error_code code;
|
||||
const bool existed = std::filesystem::exists(configPath, code);
|
||||
const std::string backup = existed ? readTextFile(configPath) : std::string();
|
||||
// What an earlier launch left at this path is removed, never restored.
|
||||
const bool staleBackup = existed && ownsDropIn(configPath);
|
||||
|
||||
// Never arm an autologin that nothing would disarm: without the cleanup unit
|
||||
// the launch is refused instead of leaving a password-free boot behind.
|
||||
std::string watchdogError;
|
||||
const std::string watchdog = startCleanupWatchdog(launchHelperPath(), watchdogError);
|
||||
if (watchdog.empty()) {
|
||||
std::cerr << watchdogError << ". Lancement annule pour ne pas laisser "
|
||||
<< configPath.string() << " en place.\n";
|
||||
return 3;
|
||||
}
|
||||
|
||||
catchTerminationSignals();
|
||||
|
||||
std::string error;
|
||||
if (!writeTextFile(configPath, content, error)) {
|
||||
stopCleanupWatchdog(watchdog);
|
||||
std::cerr << error << "\n";
|
||||
return 3;
|
||||
}
|
||||
@@ -363,7 +558,7 @@ int runLaunchHelper(const std::string& user, const std::string& sessionFile) {
|
||||
std::string unexpected;
|
||||
const auto deadline =
|
||||
std::chrono::steady_clock::now() + std::chrono::milliseconds(kLoginTimeoutMs);
|
||||
while (std::chrono::steady_clock::now() < deadline) {
|
||||
while (std::chrono::steady_clock::now() < deadline && g_interrupted == 0) {
|
||||
for (const SessionInfo& session : listGraphicalSessionsForUid(uid)) {
|
||||
if (!session.active ||
|
||||
std::find(previous.begin(), previous.end(), session.id) != previous.end()) {
|
||||
@@ -383,11 +578,30 @@ int runLaunchHelper(const std::string& user, const std::string& sessionFile) {
|
||||
}
|
||||
|
||||
// The autologin only exists for this launch: a later boot must show the
|
||||
// greeter instead of logging the user in on its own.
|
||||
if (existed) {
|
||||
writeTextFile(configPath, backup, error);
|
||||
} else {
|
||||
std::filesystem::remove(configPath, code);
|
||||
// greeter instead of logging the user in on its own. Stopping the cleanup
|
||||
// unit already deletes the drop-in; removing it here as well keeps the
|
||||
// helper independent from systemd having kept the unit alive.
|
||||
stopCleanupWatchdog(watchdog);
|
||||
std::filesystem::remove(configPath, code);
|
||||
if (existed && !staleBackup) {
|
||||
std::string restoreError;
|
||||
if (!writeTextFile(configPath, backup, restoreError)) {
|
||||
std::cerr << restoreError << "\n";
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (ownsDropIn(configPath)) {
|
||||
std::cerr << "L'autologin " << configPath.string()
|
||||
<< " n'a pas pu etre retire ; supprimez-le avant le prochain demarrage.\n";
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (g_interrupted != 0) {
|
||||
std::cerr << "Lancement interrompu ; l'autologin a ete retire.\n";
|
||||
if (!previousActive.empty()) {
|
||||
runCommand({"loginctl", "activate", previousActive});
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (sessionId.empty()) {
|
||||
|
||||
@@ -23,6 +23,14 @@ bool canStartWithoutGreeter(std::string& reason);
|
||||
// helper (polkit) and closes the sessions it replaces.
|
||||
LaunchOutcome launchDesktop(const DesktopProfile& profile);
|
||||
|
||||
// Drop-in left behind by a launch killed before its cleanup, empty when the
|
||||
// system is clean. Readable without privileges so the window can warn about it.
|
||||
std::string staleAutologinFile();
|
||||
|
||||
// Privileged side, run by the same binary with --privileged-cleanup as root:
|
||||
// deletes every drop-in this tool owns. Returns 0 when nothing is left behind.
|
||||
int runAutologinCleanup();
|
||||
|
||||
// Privileged side, run by the same binary with --privileged-launch as root.
|
||||
// Returns 0 when the requested session took the seat and the replaced sessions
|
||||
// are closing.
|
||||
|
||||
Reference in new issue
Block a user