mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-05-20 07:53:56 +02:00
mzteriver: make river log to file
This commit is contained in:
parent
0f06c8e5a5
commit
1e8286b8fc
|
@ -1,6 +1,8 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const opts = @import("opts");
|
const opts = @import("opts");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.mzteriver);
|
||||||
|
|
||||||
const Connection = @import("Connection.zig");
|
const Connection = @import("Connection.zig");
|
||||||
|
|
||||||
pub fn init(alloc: std.mem.Allocator) !void {
|
pub fn init(alloc: std.mem.Allocator) !void {
|
||||||
|
@ -162,18 +164,18 @@ pub fn init(alloc: std.mem.Allocator) !void {
|
||||||
var init_child = std.process.Child.init(&.{init_path}, alloc);
|
var init_child = std.process.Child.init(&.{init_path}, alloc);
|
||||||
const term = init_child.spawnAndWait() catch |e| switch (e) {
|
const term = init_child.spawnAndWait() catch |e| switch (e) {
|
||||||
error.FileNotFound => b: {
|
error.FileNotFound => b: {
|
||||||
std.log.info("no river_init", .{});
|
log.info("no river_init", .{});
|
||||||
break :b std.process.Child.Term{ .Exited = 0 };
|
break :b std.process.Child.Term{ .Exited = 0 };
|
||||||
},
|
},
|
||||||
else => return e,
|
else => return e,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!std.meta.eql(term, .{ .Exited = 0 })) {
|
if (!std.meta.eql(term, .{ .Exited = 0 })) {
|
||||||
std.log.err("river_init borked: {}", .{term});
|
log.err("river_init borked: {}", .{term});
|
||||||
return error.InitBorked;
|
return error.InitBorked;
|
||||||
}
|
}
|
||||||
|
|
||||||
std.log.info("configuration finished, spawning processes", .{});
|
log.info("configuration finished, spawning processes", .{});
|
||||||
|
|
||||||
var child_arena = std.heap.ArenaAllocator.init(alloc);
|
var child_arena = std.heap.ArenaAllocator.init(alloc);
|
||||||
defer child_arena.deinit();
|
defer child_arena.deinit();
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const opts = @import("opts");
|
const opts = @import("opts");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.mzteriver);
|
||||||
|
|
||||||
pub const std_options = std.Options{
|
pub const std_options = std.Options{
|
||||||
.log_level = switch (@import("builtin").mode) {
|
.log_level = switch (@import("builtin").mode) {
|
||||||
.Debug => .debug,
|
.Debug => .debug,
|
||||||
|
@ -9,22 +11,53 @@ pub const std_options = std.Options{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var dbg_gpa = if (@import("builtin").mode == .Debug) std.heap.GeneralPurposeAllocator(.{}){} else {};
|
||||||
defer _ = gpa.deinit();
|
defer if (@TypeOf(dbg_gpa) != void) {
|
||||||
const alloc = gpa.allocator();
|
_ = dbg_gpa.deinit();
|
||||||
|
};
|
||||||
|
const alloc = if (@TypeOf(dbg_gpa) == void) std.heap.c_allocator else dbg_gpa.allocator();
|
||||||
|
|
||||||
if (std.mem.endsWith(u8, std.mem.span(std.os.argv[0]), "init") or
|
if (std.mem.endsWith(u8, std.mem.span(std.os.argv[0]), "init") or
|
||||||
(std.os.argv.len >= 2 and std.mem.orderZ(u8, std.os.argv[1], "init") == .eq))
|
(std.os.argv.len >= 2 and std.mem.orderZ(u8, std.os.argv[1], "init") == .eq))
|
||||||
{
|
{
|
||||||
std.log.info("running in init mode", .{});
|
log.info("running in init mode", .{});
|
||||||
try @import("init.zig").init(alloc);
|
try @import("init.zig").init(alloc);
|
||||||
} else {
|
} else {
|
||||||
std.log.info("running in launch mode", .{});
|
log.info("running in launch mode", .{});
|
||||||
|
|
||||||
const envp = env: {
|
const logfd = logf: {
|
||||||
var env = try std.ArrayList(?[*:0]const u8)
|
const logf_path = try std.fmt.allocPrintZ(
|
||||||
.initCapacity(alloc, std.os.environ.len + 16);
|
alloc,
|
||||||
errdefer env.deinit();
|
"/tmp/mzteriver-{}-{}.log",
|
||||||
|
.{ std.os.linux.getuid(), std.os.linux.getpid() },
|
||||||
|
);
|
||||||
|
defer alloc.free(logf_path);
|
||||||
|
|
||||||
|
log.info("river log file: {s}", .{logf_path});
|
||||||
|
|
||||||
|
break :logf try std.os.openatZ(
|
||||||
|
std.os.AT.FDCWD,
|
||||||
|
logf_path.ptr,
|
||||||
|
// no CLOEXEC
|
||||||
|
.{
|
||||||
|
.ACCMODE = .WRONLY,
|
||||||
|
.CREAT = true,
|
||||||
|
.TRUNC = true,
|
||||||
|
},
|
||||||
|
0o644,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
{
|
||||||
|
errdefer std.os.close(logfd);
|
||||||
|
|
||||||
|
// redirect river's STDERR and STDOUT to log file
|
||||||
|
try std.os.dup2(logfd, std.os.STDOUT_FILENO);
|
||||||
|
try std.os.dup2(logfd, std.os.STDERR_FILENO);
|
||||||
|
}
|
||||||
|
std.os.close(logfd);
|
||||||
|
|
||||||
|
var env = std.BoundedArray(?[*:0]const u8, 0xff).init(0) catch unreachable;
|
||||||
|
const envp: [*:null]?[*:0]const u8 = env: {
|
||||||
try env.appendSlice(std.os.environ);
|
try env.appendSlice(std.os.environ);
|
||||||
|
|
||||||
try env.append("XKB_DEFAULT_LAYOUT=de");
|
try env.append("XKB_DEFAULT_LAYOUT=de");
|
||||||
|
@ -35,12 +68,11 @@ pub fn main() !void {
|
||||||
try env.append("WLR_NO_HARDWARE_CURSORS=1");
|
try env.append("WLR_NO_HARDWARE_CURSORS=1");
|
||||||
}
|
}
|
||||||
|
|
||||||
break :env try env.toOwnedSliceSentinel(null);
|
// manually add sentinel
|
||||||
|
try env.append(null);
|
||||||
|
break :env @ptrCast(env.slice().ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
// techncially unreachable
|
|
||||||
defer alloc.free(envp);
|
|
||||||
|
|
||||||
return std.os.execvpeZ("river", &[_:null]?[*:0]const u8{"river"}, envp);
|
return std.os.execvpeZ("river", &[_:null]?[*:0]const u8{"river"}, envp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue