Skip to content

Commit

Permalink
simpler impl of docker.amInside()
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Apr 17, 2022
1 parent 8a98c0b commit 36d1f7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
20 changes: 3 additions & 17 deletions src/docker.zig
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
const std = @import("std");
const extras = @import("extras");

const strings = @import("./strings.zig");

pub fn amInside(alloc: std.mem.Allocator) !bool {
const max = std.math.maxInt(usize);
const c = try std.fs.cwd().readFileAlloc(alloc, "/proc/1/cgroup", max);
var it = std.mem.split(u8, c, "\n");
while (it.next()) |item| {
const line = try strings.splitAlloc(alloc, item, ":");
if (line.len < 3) {
continue;
}
if (!strings.list.contains(&.{ "/", "/init.scope" }, line[2])) {
return true;
}
}
return false;
pub fn amInside() !bool {
return try extras.doesFileExist(null, "/.dockerenv");
}
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn main() !void {
try w.print(".{s}", .{h[0..9]});
}
}
if (docker.amInside(alloc) catch false) try w.writeAll(".docker");
if (docker.amInside() catch false) try w.writeAll(".docker");
try w.print(".zig{}", .{builtin.zig_version});
version = sbuilder.toOwnedSlice();
}
Expand Down

0 comments on commit 36d1f7d

Please sign in to comment.