aboutsummaryrefslogtreecommitdiff
path: root/src/command.zig
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2020-04-09 12:54:38 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2020-04-09 12:54:38 +0200
commitbf17b5404846d54d70fe63eb013cf20bf0a4b448 (patch)
tree180b3dc34c05e4eeebb29e124f870e33778580b7 /src/command.zig
parent6c23f3eefd84c2748f5e83f8a84f0996c6a10578 (diff)
downloadriver-bf17b5404846d54d70fe63eb013cf20bf0a4b448.tar.gz
river-bf17b5404846d54d70fe63eb013cf20bf0a4b448.tar.xz
Go back to using std.ChildProcess
The bug with this was fixed by https://github.com/ziglang/zig/pull/4970.
Diffstat (limited to 'src/command.zig')
-rw-r--r--src/command.zig20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/command.zig b/src/command.zig
index 6b4ec07..ab290c8 100644
--- a/src/command.zig
+++ b/src/command.zig
@@ -9,7 +9,7 @@ pub const Arg = union {
int: i32,
uint: u32,
float: f64,
- cstr: [*:0]const u8,
+ str: []const u8,
none: void,
};
@@ -109,13 +109,17 @@ 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 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});
- }
- }
+ const cmd = arg.str;
+
+ const argv = [_][]const u8{ "/bin/sh", "-c", cmd };
+ const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch |err| {
+ Log.Error.log("Failed to execute {}: {}", .{ cmd, err });
+ return;
+ };
+ std.ChildProcess.spawn(child) catch |err| {
+ Log.Error.log("Failed to execute {}: {}", .{ cmd, err });
+ return;
+ };
}
/// Close the focused view, if any.