Fix environment of spawned processes

std.ChildProcess isn't handling environment variables set at runtime properly,
so just use libc directly.
This commit is contained in:
Isaac Freund 2020-04-08 21:31:07 +02:00
parent b2fbdf2d87
commit 3332e0ab2b
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
5 changed files with 15 additions and 8 deletions

View file

@ -2,6 +2,7 @@ pub usingnamespace @cImport({
@cDefine("WLR_USE_UNSTABLE", {}); @cDefine("WLR_USE_UNSTABLE", {});
@cInclude("time.h"); @cInclude("time.h");
@cInclude("stdlib.h"); @cInclude("stdlib.h");
@cInclude("unistd.h");
@cInclude("wayland-server-core.h"); @cInclude("wayland-server-core.h");
//@cInclude("wlr/backend.h"); //@cInclude("wlr/backend.h");
//@cInclude("wlr/render/wlr_renderer.h"); //@cInclude("wlr/render/wlr_renderer.h");

View file

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const c = @import("c.zig"); const c = @import("c.zig");
const Log = @import("log.zig").Log;
const Server = @import("server.zig").Server; const Server = @import("server.zig").Server;
const ViewStack = @import("view_stack.zig").ViewStack; const ViewStack = @import("view_stack.zig").ViewStack;
@ -8,6 +9,7 @@ pub const Arg = union {
int: i32, int: i32,
uint: u32, uint: u32,
float: f64, float: f64,
cstr: [*:0]const u8,
none: void, none: void,
}; };
@ -107,9 +109,13 @@ pub fn toggleFocusedViewTags(server: *Server, arg: Arg) void {
/// Spawn a program. /// Spawn a program.
/// TODO: make this take a program as a paramter and spawn that /// TODO: make this take a program as a paramter and spawn that
pub fn spawn(server: *Server, arg: Arg) void { pub fn spawn(server: *Server, arg: Arg) void {
const argv = [_][]const u8{ "/bin/sh", "-c", "alacritty" }; const cmd = arg.cstr;
const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable; if (c.fork() == 0) {
std.ChildProcess.spawn(child) catch unreachable; const terminator: ?*u8 = null;
if (c.execl("/bin/sh", "/bin/sh", "-c", cmd, terminator) == -1) {
Log.Error.log("Failed to execute command {}", .{cmd});
}
}
} }
/// Close the focused view, if any. /// Close the focused view, if any.

View file

@ -50,7 +50,7 @@ pub const Config = struct {
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_h, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.modifyMasterCount, .arg = .{ .int = 1 } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_h, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.modifyMasterCount, .arg = .{ .int = 1 } });
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_l, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.modifyMasterCount, .arg = .{ .int = -1 } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_l, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.modifyMasterCount, .arg = .{ .int = -1 } });
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_Return, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.spawn, .arg = .{ .none = {} } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_Return, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.spawn, .arg = .{ .cstr = "alacritty" } });
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_1, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 1 << 0 } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_1, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 1 << 0 } });
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_2, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 1 << 1 } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_2, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 1 << 1 } });

View file

@ -17,7 +17,7 @@ pub const Keyboard = struct {
pub fn init(self: *Self, seat: *Seat, device: *c.wlr_input_device) !void { pub fn init(self: *Self, seat: *Seat, device: *c.wlr_input_device) !void {
self.seat = seat; self.seat = seat;
self.device = device; self.device = device;
self.wlr_keyboard = device.unnamed_133.keyboard; self.wlr_keyboard = device.unnamed_136.keyboard;
// We need to prepare an XKB keymap and assign it to the keyboard. This // We need to prepare an XKB keymap and assign it to the keyboard. This
// assumes the defaults (e.g. layout = "us"). // assumes the defaults (e.g. layout = "us").
@ -78,7 +78,7 @@ pub const Keyboard = struct {
@alignCast(@alignOf(*c.wlr_event_keyboard_key), data), @alignCast(@alignOf(*c.wlr_event_keyboard_key), data),
); );
const wlr_keyboard: *c.wlr_keyboard = keyboard.device.unnamed_133.keyboard; const wlr_keyboard: *c.wlr_keyboard = keyboard.device.unnamed_136.keyboard;
// Translate libinput keycode -> xkbcommon // Translate libinput keycode -> xkbcommon
const keycode = event.keycode + 8; const keycode = event.keycode + 8;

View file

@ -4,6 +4,7 @@ const command = @import("command.zig");
const Config = @import("config.zig").Config; const Config = @import("config.zig").Config;
const DecorationManager = @import("decoration_manager.zig").DecorationManager; const DecorationManager = @import("decoration_manager.zig").DecorationManager;
const Log = @import("log.zig").Log;
const Output = @import("output.zig").Output; const Output = @import("output.zig").Output;
const Root = @import("root.zig").Root; const Root = @import("root.zig").Root;
const Seat = @import("seat.zig").Seat; const Seat = @import("seat.zig").Seat;
@ -105,8 +106,7 @@ pub const Server = struct {
return error.CantStartBackend; return error.CantStartBackend;
} }
// Set the WAYLAND_DISPLAY environment variable to our socket and run the // Set the WAYLAND_DISPLAY environment variable to our socket
// startup command if requested. */
if (c.setenv("WAYLAND_DISPLAY", socket, 1) == -1) { if (c.setenv("WAYLAND_DISPLAY", socket, 1) == -1) {
return error.CantSetEnv; return error.CantSetEnv;
} }