diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2020-04-08 21:31:07 +0200 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2020-04-08 21:31:07 +0200 |
| commit | 3332e0ab2b39c24acf713d7a19af46addc165519 (patch) | |
| tree | da2e68e1a29da77f4d0fd0d29ea09b8dd14fe619 /src/command.zig | |
| parent | b2fbdf2d87e21c724d82eb59ef7f5dae26b39c7e (diff) | |
| download | river-3332e0ab2b39c24acf713d7a19af46addc165519.tar.gz river-3332e0ab2b39c24acf713d7a19af46addc165519.tar.xz | |
Fix environment of spawned processes
std.ChildProcess isn't handling environment variables set at runtime properly,
so just use libc directly.
Diffstat (limited to 'src/command.zig')
| -rw-r--r-- | src/command.zig | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/command.zig b/src/command.zig index 7aac7f6..6b4ec07 100644 --- a/src/command.zig +++ b/src/command.zig @@ -1,6 +1,7 @@ const std = @import("std"); const c = @import("c.zig"); +const Log = @import("log.zig").Log; const Server = @import("server.zig").Server; const ViewStack = @import("view_stack.zig").ViewStack; @@ -8,6 +9,7 @@ pub const Arg = union { int: i32, uint: u32, float: f64, + cstr: [*:0]const u8, none: void, }; @@ -107,9 +109,13 @@ pub fn toggleFocusedViewTags(server: *Server, arg: Arg) void { /// Spawn a program. /// TODO: make this take a program as a paramter and spawn that pub fn spawn(server: *Server, arg: Arg) void { - const argv = [_][]const u8{ "/bin/sh", "-c", "alacritty" }; - const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable; - std.ChildProcess.spawn(child) catch unreachable; + const cmd = arg.cstr; + if (c.fork() == 0) { + 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. |
