mirror of https://github.com/fairyglade/ly.git
Fix XDG_RUNTIME_DIR not being set properly (fixes #781)
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
2ae86a695b
commit
41f4378bfe
19
src/auth.zig
19
src/auth.zig
|
|
@ -41,8 +41,7 @@ pub fn authenticate(options: AuthOptions, current_environment: Environment, logi
|
||||||
const pam_tty_str = try std.fmt.bufPrintZ(&pam_tty_buffer, "tty{d}", .{options.tty});
|
const pam_tty_str = try std.fmt.bufPrintZ(&pam_tty_buffer, "tty{d}", .{options.tty});
|
||||||
|
|
||||||
// Set the XDG environment variables
|
// Set the XDG environment variables
|
||||||
setXdgSessionEnv(current_environment.display_server);
|
try setXdgEnv(tty_str, current_environment);
|
||||||
try setXdgEnv(tty_str, current_environment.xdg_session_desktop, current_environment.xdg_desktop_names);
|
|
||||||
|
|
||||||
// Open the PAM session
|
// Open the PAM session
|
||||||
var credentials = [_:null]?[*:0]const u8{ login, password };
|
var credentials = [_:null]?[*:0]const u8{ login, password };
|
||||||
|
|
@ -96,7 +95,7 @@ pub fn authenticate(options: AuthOptions, current_environment: Environment, logi
|
||||||
|
|
||||||
child_pid = try std.posix.fork();
|
child_pid = try std.posix.fork();
|
||||||
if (child_pid == 0) {
|
if (child_pid == 0) {
|
||||||
startSession(options, pwd, handle, current_environment) catch |e| {
|
startSession(options, tty_str, pwd, handle, current_environment) catch |e| {
|
||||||
shared_err.writeError(e);
|
shared_err.writeError(e);
|
||||||
std.process.exit(1);
|
std.process.exit(1);
|
||||||
};
|
};
|
||||||
|
|
@ -132,6 +131,7 @@ pub fn authenticate(options: AuthOptions, current_environment: Environment, logi
|
||||||
|
|
||||||
fn startSession(
|
fn startSession(
|
||||||
options: AuthOptions,
|
options: AuthOptions,
|
||||||
|
tty_str: [:0]u8,
|
||||||
pwd: *interop.pwd.passwd,
|
pwd: *interop.pwd.passwd,
|
||||||
handle: ?*interop.pam.pam_handle,
|
handle: ?*interop.pam.pam_handle,
|
||||||
current_environment: Environment,
|
current_environment: Environment,
|
||||||
|
|
@ -155,6 +155,9 @@ fn startSession(
|
||||||
// Set up the environment
|
// Set up the environment
|
||||||
try initEnv(pwd, options.path);
|
try initEnv(pwd, options.path);
|
||||||
|
|
||||||
|
// Reset the XDG environment variables
|
||||||
|
try setXdgEnv(tty_str, current_environment);
|
||||||
|
|
||||||
// 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);
|
||||||
if (pam_env_vars == null) return error.GetEnvListFailed;
|
if (pam_env_vars == null) return error.GetEnvListFailed;
|
||||||
|
|
@ -193,15 +196,13 @@ fn initEnv(pwd: *interop.pwd.passwd, path_env: ?[:0]const u8) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setXdgSessionEnv(display_server: enums.DisplayServer) void {
|
fn setXdgEnv(tty_str: [:0]u8, environment: Environment) !void {
|
||||||
_ = interop.stdlib.setenv("XDG_SESSION_TYPE", switch (display_server) {
|
_ = interop.stdlib.setenv("XDG_SESSION_TYPE", switch (environment.display_server) {
|
||||||
.wayland => "wayland",
|
.wayland => "wayland",
|
||||||
.shell => "tty",
|
.shell => "tty",
|
||||||
.xinitrc, .x11 => "x11",
|
.xinitrc, .x11 => "x11",
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
|
||||||
|
|
||||||
fn setXdgEnv(tty_str: [:0]u8, maybe_desktop_name: ?[:0]const u8, maybe_xdg_desktop_names: ?[:0]const u8) !void {
|
|
||||||
// The "/run/user/%d" directory is not available on FreeBSD. It is much
|
// The "/run/user/%d" directory is not available on FreeBSD. It is much
|
||||||
// better to stick to the defaults and let applications using
|
// better to stick to the defaults and let applications using
|
||||||
// XDG_RUNTIME_DIR to fall back to directories inside user's home
|
// XDG_RUNTIME_DIR to fall back to directories inside user's home
|
||||||
|
|
@ -214,10 +215,10 @@ fn setXdgEnv(tty_str: [:0]u8, maybe_desktop_name: ?[:0]const u8, maybe_xdg_deskt
|
||||||
_ = interop.stdlib.setenv("XDG_RUNTIME_DIR", uid_str, 0);
|
_ = interop.stdlib.setenv("XDG_RUNTIME_DIR", uid_str, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maybe_xdg_desktop_names) |xdg_desktop_names| _ = interop.stdlib.setenv("XDG_CURRENT_DESKTOP", xdg_desktop_names, 0);
|
if (environment.xdg_desktop_names) |xdg_desktop_names| _ = interop.stdlib.setenv("XDG_CURRENT_DESKTOP", xdg_desktop_names, 0);
|
||||||
_ = interop.stdlib.setenv("XDG_SESSION_CLASS", "user", 0);
|
_ = interop.stdlib.setenv("XDG_SESSION_CLASS", "user", 0);
|
||||||
_ = interop.stdlib.setenv("XDG_SESSION_ID", "1", 0);
|
_ = interop.stdlib.setenv("XDG_SESSION_ID", "1", 0);
|
||||||
if (maybe_desktop_name) |desktop_name| _ = interop.stdlib.setenv("XDG_SESSION_DESKTOP", desktop_name, 0);
|
if (environment.xdg_session_desktop) |desktop_name| _ = interop.stdlib.setenv("XDG_SESSION_DESKTOP", desktop_name, 0);
|
||||||
_ = interop.stdlib.setenv("XDG_SEAT", "seat0", 0);
|
_ = interop.stdlib.setenv("XDG_SEAT", "seat0", 0);
|
||||||
_ = interop.stdlib.setenv("XDG_VTNR", tty_str, 0);
|
_ = interop.stdlib.setenv("XDG_VTNR", tty_str, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue