mirror of
https://github.com/fairyglade/ly.git
synced 2026-06-22 07:22:00 +00:00
auth: Create XDG_RUNTIME_DIR if /run/user/UID exists
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
20
src/auth.zig
20
src/auth.zig
@@ -179,7 +179,7 @@ fn startSession(
|
|||||||
// Reset the XDG environment variables
|
// Reset the XDG environment variables
|
||||||
try log_file.info(io, "auth/env", "resetting xdg environment variables", .{});
|
try log_file.info(io, "auth/env", "resetting xdg environment variables", .{});
|
||||||
try setXdgEnv(allocator, tty_str, current_environment);
|
try setXdgEnv(allocator, tty_str, current_environment);
|
||||||
try setXdgRuntimeDir(allocator);
|
try setXdgRuntimeDir(allocator, io);
|
||||||
|
|
||||||
// Set the PAM variables
|
// Set the PAM variables
|
||||||
const pam_env_vars: ?[*:null]?[*:0]u8 = interop.pam.pam_getenvlist(handle);
|
const pam_env_vars: ?[*:null]?[*:0]u8 = interop.pam.pam_getenvlist(handle);
|
||||||
@@ -247,19 +247,21 @@ fn setXdgEnv(allocator: std.mem.Allocator, tty_str: []u8, environment: Environme
|
|||||||
try interop.setEnvironmentVariable(allocator, "XDG_VTNR", tty_str, false);
|
try interop.setEnvironmentVariable(allocator, "XDG_VTNR", tty_str, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setXdgRuntimeDir(allocator: std.mem.Allocator) !void {
|
fn setXdgRuntimeDir(allocator: std.mem.Allocator, io: std.Io) !void {
|
||||||
// The "/run/user/%d" directory is not available on FreeBSD. It is much
|
// The "/run/user/%d" directory is not available on some operating systems,
|
||||||
// better to stick to the defaults and let applications using
|
// like FreeBSD and Alpine
|
||||||
// XDG_RUNTIME_DIR to fall back to directories inside user's home
|
|
||||||
// directory.
|
|
||||||
if (builtin.os.tag != .freebsd) {
|
|
||||||
const uid = std.posix.system.getuid();
|
const uid = std.posix.system.getuid();
|
||||||
var uid_buffer: [32]u8 = undefined; // No UID can be larger than this
|
var uid_buffer: [32]u8 = undefined; // No UID can be larger than this
|
||||||
const uid_str = try std.fmt.bufPrint(&uid_buffer, "/run/user/{d}", .{uid});
|
const uid_str = try std.fmt.bufPrint(&uid_buffer, "/run/user/{d}", .{uid});
|
||||||
|
|
||||||
|
var xdg_dir = std.Io.Dir.openDirAbsolute(io, uid_str, .{}) catch |err| {
|
||||||
|
if (err == error.FileNotFound) return;
|
||||||
|
return err;
|
||||||
|
};
|
||||||
|
xdg_dir.close(io);
|
||||||
|
|
||||||
try interop.setEnvironmentVariable(allocator, "XDG_RUNTIME_DIR", uid_str, false);
|
try interop.setEnvironmentVariable(allocator, "XDG_RUNTIME_DIR", uid_str, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn loginConv(
|
fn loginConv(
|
||||||
num_msg: c_int,
|
num_msg: c_int,
|
||||||
@@ -390,7 +392,7 @@ fn createXauthFile(log_file: *LogFile, io: std.Io, pwd: []const u8, buffer: []u8
|
|||||||
|
|
||||||
const xauthority: []u8 = try std.fmt.bufPrint(buffer, "{s}/{s}", .{ trimmed_xauth_dir, xauth_file });
|
const xauthority: []u8 = try std.fmt.bufPrint(buffer, "{s}/{s}", .{ trimmed_xauth_dir, xauth_file });
|
||||||
|
|
||||||
std.Io.Dir.cwd().createDirPath(io, trimmed_xauth_dir) catch {};
|
try std.Io.Dir.cwd().createDirPath(io, trimmed_xauth_dir);
|
||||||
|
|
||||||
try log_file.info(io, "auth/x11", "creating xauth file: {s}", .{xauthority});
|
try log_file.info(io, "auth/x11", "creating xauth file: {s}", .{xauthority});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user