aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2020-06-01 19:43:21 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2020-06-01 19:43:21 +0200
commit072dd575aa47f9fe4bfe569e8a8745c6936f73c1 (patch)
tree1203b8660897dbe1d4df3eb4f06f5d0970a08d3c
parent33539d5b03840aedf5f729a9636ec353483c2422 (diff)
downloadriver-072dd575aa47f9fe4bfe569e8a8745c6936f73c1.tar.gz
river-072dd575aa47f9fe4bfe569e8a8745c6936f73c1.tar.xz
Add support for running a command on startup
-rw-r--r--river/main.zig41
1 files changed, 41 insertions, 0 deletions
diff --git a/river/main.zig b/river/main.zig
index a5f5334..5b64241 100644
--- a/river/main.zig
+++ b/river/main.zig
@@ -22,7 +22,41 @@ const c = @import("c.zig");
const Log = @import("log.zig").Log;
const Server = @import("Server.zig");
+const usage: []const u8 =
+ \\Usage: river [options]
+ \\
+ \\ -h Print this help message and exit.
+ \\ -c <command> Run `sh -c <command>` on startup.
+ \\
+;
+
pub fn main() !void {
+ var startup_command: ?[]const u8 = null;
+ {
+ var it = std.process.args();
+ // Skip our name
+ _ = it.nextPosix();
+ while (it.nextPosix()) |arg| {
+ if (std.mem.eql(u8, arg, "-h")) {
+ const stdout = std.io.getStdOut().outStream();
+ try stdout.print(usage, .{});
+ std.os.exit(0);
+ } else if (std.mem.eql(u8, arg, "-c")) {
+ if (it.nextPosix()) |command| {
+ startup_command = command;
+ } else {
+ const stderr = std.io.getStdErr().outStream();
+ try stderr.print("Error: flag '-c' requires exactly one argument\n", .{});
+ std.os.exit(1);
+ }
+ } else {
+ const stderr = std.io.getStdErr().outStream();
+ try stderr.print(usage, .{});
+ std.os.exit(1);
+ }
+ }
+ }
+
Log.init(Log.Debug);
c.wlr_log_init(.WLR_ERROR, null);
@@ -34,6 +68,13 @@ pub fn main() !void {
try server.start();
+ if (startup_command) |cmd| {
+ const child_args = [_][]const u8{ "/bin/sh", "-c", cmd };
+ const child = try std.ChildProcess.init(&child_args, std.heap.c_allocator);
+ defer child.deinit();
+ try std.ChildProcess.spawn(child);
+ }
+
Log.Info.log("Running server...", .{});
server.run();