From 541eae531134373d0d421ba7e7fecc12ce189337 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Sat, 18 Oct 2025 11:23:57 +0200 Subject: [PATCH] Update init service for FreeBSD Signed-off-by: AnErrupTion --- build.zig | 11 +++++------ readme.md | 16 ++++++++++++++-- res/ly-freebsd | 23 ----------------------- res/ly-freebsd-wrapper | 7 +++++++ 4 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 res/ly-freebsd create mode 100644 res/ly-freebsd-wrapper diff --git a/build.zig b/build.zig index 1a986f0..74c59cb 100644 --- a/build.zig +++ b/build.zig @@ -320,13 +320,12 @@ fn install_service(allocator: std.mem.Allocator, patch_map: PatchMap) !void { try installText(patched_service, service_dir, service_path, "ly", .{ .mode = 0o755 }); }, .freebsd => { - const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/rc.d" }); - std.fs.cwd().makePath(service_path) catch {}; - var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable; - defer service_dir.close(); + const exe_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/bin" }); + var executable_dir = std.fs.cwd().openDir(exe_path, .{}) catch unreachable; + defer executable_dir.close(); - const patched_service = try patchFile(allocator, "res/ly-freebsd", patch_map); - try installText(patched_service, service_dir, service_path, "ly", .{ .mode = 0o755 }); + const patched_wrapper = try patchFile(allocator, "res/ly-freebsd-wrapper", patch_map); + try installText(patched_wrapper, executable_dir, exe_path, "ly_wrapper", .{ .mode = 0o755 }); }, } } diff --git a/readme.md b/readme.md index a02bcda..c9daae7 100644 --- a/readme.md +++ b/readme.md @@ -180,10 +180,22 @@ To disable TTY 2, go to `/etc/inittab` and comment out the line containing `tty2 ``` # zig build installexe -Dprefix_directory=/usr/local -Dinit_system=freebsd # sysrc lightdm_enable="NO" -# sysrc ly_enable="YES" ``` -To disable TTY 2, go to `/etc/ttys` and comment out the line starting with `ttyv1` (TTYs start at 0 in FreeBSD). +To enable Ly, add the following entry to `/etc/gettytab`: + +``` +Ly:\ + :lo=/usr/local/bin/ly_wrapper:\ + :al=root: +``` + +Then, modify the command field of the `ttyv1` terminal entry in `/etc/ttys` +(TTYs in FreeBSD start at 0): + +``` +ttyv1 "/usr/libexec/getty Ly" xterm on secure +``` ### Updating diff --git a/res/ly-freebsd b/res/ly-freebsd deleted file mode 100644 index 9dfcb9f..0000000 --- a/res/ly-freebsd +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -# -# PROVIDE: ly -# REQUIRE: DAEMON -# KEYWORD: shutdown - -. /etc/rc.subr - -name=ly -rcvar=ly_enable - -command="/usr/local/bin/ly" - -load_rc_config $name - -# -# DO NOT CHANGE THESE DEFAULT VALUES HERE -# SET THEM IN THE /etc/rc.conf FILE -# -ly_enable=${ly_enable-"NO"} -pidfile=${ly_pidfile-"/var/run/ly.pid"} - -run_rc_command "$1" diff --git a/res/ly-freebsd-wrapper b/res/ly-freebsd-wrapper new file mode 100644 index 0000000..23544b7 --- /dev/null +++ b/res/ly-freebsd-wrapper @@ -0,0 +1,7 @@ +#!/bin/sh + +# On FreeBSD, even if we override the default login program, getty will still +# try to append "login -fp root" as arguments to Ly, which is not supported. +# To avoid this, we use a wrapper script that ignores these arguments before +# actually executing Ly. +exec $PREFIX_DIRECTORY/bin/$EXECUTABLE_NAME