1
Fork 0
mirror of https://github.com/RGBCube/crash synced 2025-05-14 05:04:59 +00:00

feat: bug fixes and build fixes

This commit is contained in:
RGBCube 2025-04-13 02:19:38 +03:00
parent 3405a772ba
commit 119c52f090
No known key found for this signature in database
4 changed files with 28 additions and 16 deletions

View file

@ -1,10 +1,13 @@
.{
.name = "crash",
.name = .crash,
.version = "0.0.1",
.fingerprint = 0xd7e8f0df85300b08,
.minimum_zig_version = "0.12.0",
.minimum_zig_version = "0.14.0",
.paths = .{
"",
"src/main.zig",
"build.zig",
"build.zig.zon",
},
}

6
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1715653339,
"narHash": "sha256-7lR9tpVXviSccl07GXI0+ve/natd24HAkuy1sQp0OlI=",
"lastModified": 1744442362,
"narHash": "sha256-i47t4DRIZgwBZw2Osbrp1OJhhO1k/n+QzRx+TrmfE9Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "abd6d48f8c77bea7dc51beb2adfa6ed3950d2585",
"rev": "2349f9de17183971db12ae9e0123dab132023bd7",
"type": "github"
},
"original": {

View file

@ -34,7 +34,7 @@ in stdenvNoCC.mkDerivation {
homepage = "https://github.com/RGBCube/crash";
license = licenses.mit;
mainProgram = "crash";
platforms = platforms.linux;
platforms = platforms.unix;
maintainers = with maintainers; [ RGBCube ];
};
}

View file

@ -1,8 +1,8 @@
const std = @import("std");
const fallback_shell = @import("build_options").fallback_shell orelse @compileError("fallback shell was not specified");
pub fn fallback(alloc: std.mem.Allocator) noreturn {
const err = std.process.execv(alloc, &[_][]const u8{fallback_shell});
pub fn fallback(alloc: std.mem.Allocator, args: []const []const u8) noreturn {
const err = std.process.execv(alloc, args);
std.process.exit(@intCast(@intFromError(err)));
}
@ -10,28 +10,37 @@ pub fn main() noreturn {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
var args = alloc.alloc([]const u8, std.os.argv.len) catch fallback(alloc);
var args = alloc.alloc([]const u8, std.os.argv.len) catch fallback(alloc, &[_][]const u8{fallback_shell});
defer alloc.free(args);
args.len = 0;
var argi = std.process.args();
while (argi.next()) |arg| {
args.len += 1;
args[args.len - 1] = arg;
defer args.len += 1;
args[args.len] = arg;
}
const shells = std.posix.getenv("SHELLS") orelse fallback(alloc);
const shells = std.posix.getenv("SHELLS") orelse fallback(alloc, args: {
args[0] = fallback_shell;
break :args args;
});
var it = std.mem.split(u8, shells, ":");
var it = std.mem.splitScalar(u8, shells, ':');
while (it.next()) |shell| {
args[0] = shell;
var child = std.process.Child.init(args, alloc);
switch (child.spawnAndWait() catch fallback(alloc)) {
switch (child.spawnAndWait() catch fallback(alloc, args: {
args[0] = fallback_shell;
break :args args;
})) {
std.process.Child.Term.Exited => |exit_code| if (exit_code == 0) std.process.exit(0),
else => continue,
}
}
fallback(alloc);
fallback(alloc, args: {
args[0] = fallback_shell;
break :args args;
});
}