mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-20 19:24:53 +00:00
Add fallback UID range options at compile-time
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -55,6 +55,7 @@ err_battery: []const u8 = "failed to load battery status",
|
||||
err_switch_tty: []const u8 = "failed to switch tty",
|
||||
err_tty_ctrl: []const u8 = "tty control transfer failed",
|
||||
err_no_users: []const u8 = "no users found",
|
||||
err_uid_range: []const u8 = "failed to dynamically get uid range",
|
||||
err_user_gid: []const u8 = "failed to set user GID",
|
||||
err_user_init: []const u8 = "failed to initialize user",
|
||||
err_user_uid: []const u8 = "failed to set user UID",
|
||||
|
||||
19
src/main.zig
19
src/main.zig
@@ -26,6 +26,7 @@ const SavedUsers = @import("config/SavedUsers.zig");
|
||||
const migrator = @import("config/migrator.zig");
|
||||
const SharedError = @import("SharedError.zig");
|
||||
const LogFile = @import("LogFile.zig");
|
||||
const UidRange = @import("UidRange.zig");
|
||||
|
||||
const StringList = std.ArrayListUnmanaged([]const u8);
|
||||
const Ini = ini.Ini;
|
||||
@@ -219,7 +220,8 @@ pub fn main() !void {
|
||||
migrator.lateConfigFieldHandler(&config);
|
||||
}
|
||||
|
||||
var usernames = try getAllUsernames(allocator, config.login_defs_path);
|
||||
var maybe_uid_range_error: ?anyerror = null;
|
||||
var usernames = try getAllUsernames(allocator, config.login_defs_path, &maybe_uid_range_error);
|
||||
defer {
|
||||
for (usernames.items) |username| allocator.free(username);
|
||||
usernames.deinit(allocator);
|
||||
@@ -344,6 +346,11 @@ pub fn main() !void {
|
||||
try log_writer.print("unable to parse argument '{s}{s}': {s}\n", .{ longest.kind.prefix(), longest.name, @errorName(arg_parse_error) });
|
||||
}
|
||||
|
||||
if (maybe_uid_range_error) |err| {
|
||||
try info_line.addMessage(lang.err_uid_range, config.error_bg, config.error_fg);
|
||||
try log_writer.print("failed to get uid range: {s}; falling back to default\n", .{@errorName(err)});
|
||||
}
|
||||
|
||||
if (maybe_config_load_error) |err| {
|
||||
// We can't localize this since the config failed to load so we'd fallback to the default language anyway
|
||||
try info_line.addMessage("unable to parse config file", config.error_bg, config.error_fg);
|
||||
@@ -1277,8 +1284,14 @@ fn findSessionByName(session: *Session, name: []const u8) ?usize {
|
||||
return null;
|
||||
}
|
||||
|
||||
fn getAllUsernames(allocator: std.mem.Allocator, login_defs_path: []const u8) !StringList {
|
||||
const uid_range = try interop.getUserIdRange(allocator, login_defs_path);
|
||||
fn getAllUsernames(allocator: std.mem.Allocator, login_defs_path: []const u8, uid_range_error: *?anyerror) !StringList {
|
||||
const uid_range = interop.getUserIdRange(allocator, login_defs_path) catch |err| no_uid_range: {
|
||||
uid_range_error.* = err;
|
||||
break :no_uid_range UidRange{
|
||||
.uid_min = build_options.fallback_uid_min,
|
||||
.uid_max = build_options.fallback_uid_max,
|
||||
};
|
||||
};
|
||||
|
||||
var usernames: StringList = .empty;
|
||||
var maybe_entry = interop.getNextUsernameEntry();
|
||||
|
||||
Reference in New Issue
Block a user