From 6d3808553ef0b6a1f66c715d0c6e2c420f62912a Mon Sep 17 00:00:00 2001 From: Muki Kiboigo Date: Wed, 19 Jun 2024 16:17:42 -0700 Subject: [PATCH 1/2] templated systemd file --- build.zig | 2 +- readme.md | 7 +++++-- res/{ly.service => ly@.service} | 11 ++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) rename res/{ly.service => ly@.service} (53%) diff --git a/build.zig b/build.zig index 13c5140..c6580a1 100644 --- a/build.zig +++ b/build.zig @@ -111,7 +111,7 @@ fn installsystemd(self: *std.Build.Step, progress: *std.Progress.Node) !void { var service_dir = std.fs.openDirAbsolute("/usr/lib/systemd/system", .{}) catch unreachable; defer service_dir.close(); - try std.fs.cwd().copyFile("res/ly.service", service_dir, "ly.service", .{ .override_mode = 644 }); + try std.fs.cwd().copyFile("res/ly@.service", service_dir, "ly@.service", .{ .override_mode = 644 }); } fn installopenrc(self: *std.Build.Step, progress: *std.Progress.Node) !void { diff --git a/readme.md b/readme.md index 1402122..06cd9ab 100644 --- a/readme.md +++ b/readme.md @@ -92,9 +92,10 @@ Install Ly and the provided systemd service file # zig build installsystemd ``` -Enable the service +Enable the service (this will spawn on tty2 and tty9) ``` -# systemctl enable ly.service +# systemctl enable ly@tty2.service +# systemctl enable ly@tty9.service ``` If you need to switch between ttys after Ly's start you also have to @@ -103,6 +104,8 @@ disable getty on Ly's tty to prevent "login" from spawning on top of it # systemctl disable getty@tty2.service ``` +If you have multiple ttys setup with systemd, the tty option will be used as your default tty. + ### OpenRC **NOTE**: On Gentoo, Ly will disable the `display-manager-init` service in order to run. diff --git a/res/ly.service b/res/ly@.service similarity index 53% rename from res/ly.service rename to res/ly@.service index 09c1559..aad446b 100644 --- a/res/ly.service +++ b/res/ly@.service @@ -1,17 +1,18 @@ [Unit] -Description=TUI display manager +Description=TUI display manager (on %I) After=systemd-user-sessions.service plymouth-quit-wait.service -After=getty@tty2.service -Conflicts=getty@tty2.service +After=getty@%I.service +Conflicts=getty@%I.service [Service] Type=idle ExecStart=/usr/bin/ly StandardError=journal StandardInput=tty -TTYPath=/dev/tty2 +TTYPath=/dev/%I TTYReset=yes TTYVHangup=yes [Install] -Alias=display-manager.service +WantedBy=multi-user.target +# Alias=display-manager.service From ab462e91c24eab4c613bfe508f2ab349b85dfff2 Mon Sep 17 00:00:00 2001 From: Muki Kiboigo Date: Wed, 19 Jun 2024 16:19:35 -0700 Subject: [PATCH 2/2] authenticate and run on current virtual terminal --- src/interop.zig | 5 +++++ src/main.zig | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/interop.zig b/src/interop.zig index a053747..5c017bb 100644 --- a/src/interop.zig +++ b/src/interop.zig @@ -6,6 +6,10 @@ pub const termbox = @cImport({ @cInclude("termbox.h"); }); +pub const vt = @cImport({ + @cInclude("linux/vt.h"); +}); + pub const pam = @cImport({ @cInclude("security/pam_appl.h"); }); @@ -44,6 +48,7 @@ pub const passwd = extern struct { pw_shell: [*:0]u8, }; +pub const VT_GETSTATE: c_int = 0x5603; pub const VT_ACTIVATE: c_int = 0x5606; pub const VT_WAITACTIVE: c_int = 0x5607; diff --git a/src/main.zig b/src/main.zig index bff277b..2d16db5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -526,6 +526,11 @@ pub fn main() !void { defer shared_err.deinit(); { + // This will set the current active VT as our TTY. + var vtstat: interop.vt.vt_stat = undefined; + _ = std.c.ioctl(std.c.STDIN_FILENO, interop.VT_GETSTATE, &vtstat); + config.tty = @intCast(vtstat.v_active); + const login_text = try allocator.dupeZ(u8, login.text.items); defer allocator.free(login_text); const password_text = try allocator.dupeZ(u8, password.text.items);