Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ pub fn build(b: *std.Build) !void {
containerd_build.setEnvironmentVariable("GOPATH", b.fmt("{s}/build", .{root}));
containerd_build.setCwd(b.path(containerd_src));
containerd_build.addArgs(&.{
"-tags", shim_tags,
"-ldflags", ldflags,
"-o", "bin/containerd",
"-tags", shim_tags,
"-ldflags", ldflags,
"-o", "bin/containerd",
"./cmd/containerd",
});
containerd_build.step.dependOn(&download_cmd.step);
Expand Down Expand Up @@ -266,7 +266,7 @@ pub fn build(b: *std.Build) !void {
const cni_clone_abs = b.fmt("{s}/.cni-build", .{root});
const cni_workdir_abs = b.fmt("{s}/src/github.com/containernetworking/plugins", .{cni_clone_abs});
const cni_clone = b.addSystemCommand(&.{
bash, "-c",
bash, "-c",
b.fmt("rm -rf {s} && mkdir -p {s} && git clone --single-branch --depth=1 --branch={s} https://github.com/rancher/plugins.git {s}", .{ cni_clone_abs, cni_clone_abs, cni_version, cni_workdir_abs }),
});
const cni_build = b.addSystemCommand(&.{ "go", "build" });
Expand Down Expand Up @@ -406,9 +406,9 @@ fn addSandboxCLIBuild(b: *std.Build, all_step: *std.Build.Step, v: VersionInfo)
const out_path = b.getInstallPath(.bin, out_name);

const go_build = b.addSystemCommand(&[_][]const u8{
"go", "build",
"-ldflags", ldflags,
"-o", out_path,
"go", "build",
"-ldflags", ldflags,
"-o", out_path,
"./cmd/sandboxcli/",
});
go_build.setEnvironmentVariable("GOOS", t.goos);
Expand Down
4 changes: 1 addition & 3 deletions sandboxd/src/events.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const std = @import("std");
///
/// Format per line: {"t":<unix_sec>,"ev":"<event>","sid":"<session>",...}
/// Events: exec_start, exec_end, file_write, file_read, bg_submit, bg_poll.

const EVENT_DIR = "/workspace/.k8e_events";
/// Hard cap for the event file; when exceeded the file is rotated (old -> .1).
pub const max_event_bytes: usize = 4 * 1024 * 1024;
Expand Down Expand Up @@ -45,8 +44,7 @@ pub fn appendAt(dir: []const u8, session_id: []const u8, event: []const u8, extr

const ts = getUnixSeconds();
var line_buf: [MAX_LINE]u8 = undefined;
const line = std.fmt.bufPrint(&line_buf, "{{\"t\":{d},\"ev\":\"{s}\",\"sid\":\"{s}\"{s}}}\n",
.{ ts, event, session_id, extra }) catch return;
const line = std.fmt.bufPrint(&line_buf, "{{\"t\":{d},\"ev\":\"{s}\",\"sid\":\"{s}\"{s}}}\n", .{ ts, event, session_id, extra }) catch return;
_ = std.os.linux.write(@intCast(fd), line.ptr, line.len);
}

Expand Down
6 changes: 1 addition & 5 deletions sandboxd/src/execctl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ pub fn handleSignal(allocator: std.mem.Allocator, client_fd: i32, body: []const
try main.writeResponse(client_fd, "200 OK", "application/json", "{\"ok\":true}");
}


const StdinRequest = struct {
pid: std.os.linux.pid_t,
data: []const u8 = "",
Expand Down Expand Up @@ -375,9 +374,7 @@ pub fn handleProcessList(allocator: std.mem.Allocator, client_fd: i32) !void {

if (wrote_any) try out.append(',');
wrote_any = true;
const entry = try std.fmt.bufPrint(&entry_buf,
"{{\"pid\":{d},\"alive\":{s},\"config\":\"{s}\"}}",
.{ pid, if (alive) "true" else "false", escaped });
const entry = try std.fmt.bufPrint(&entry_buf, "{{\"pid\":{d},\"alive\":{s},\"config\":\"{s}\"}}", .{ pid, if (alive) "true" else "false", escaped });
try out.appendSlice(entry);
}

Expand All @@ -392,7 +389,6 @@ pub fn handleProcessList(allocator: std.mem.Allocator, client_fd: i32) !void {
/// the buffered output, then a done marker. This slice replays the buffer;
/// live tailing a still-running process from a second consumer needs a
/// multi-reader pipe model (documented P1 follow-up).

/// parsePidQuery extracts the integer value of the "pid" query parameter.
fn parsePidQuery(query: []const u8) ?[]const u8 {
const prefix = "pid=";
Expand Down
4 changes: 1 addition & 3 deletions sandboxd/src/files.zig
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ pub fn handleStat(allocator: std.mem.Allocator, client_fd: i32, body: []const u8
const target_escaped = try exec.jsonEscape(allocator, symlink_target);
defer allocator.free(target_escaped);

const resp = try std.fmt.allocPrint(allocator,
"{{\"type\":\"{s}\",\"size\":{d},\"mode\":\"{o}\",\"uid\":{d},\"gid\":{d},\"mtime\":{d},\"name\":\"{s}\",\"symlink_target\":\"{s}\"}}",
.{ ftype, stx.size, mode_u32 & 0o7777, stx.uid, stx.gid, stx.mtime.sec, req.path, target_escaped });
const resp = try std.fmt.allocPrint(allocator, "{{\"type\":\"{s}\",\"size\":{d},\"mode\":\"{o}\",\"uid\":{d},\"gid\":{d},\"mtime\":{d},\"name\":\"{s}\",\"symlink_target\":\"{s}\"}}", .{ ftype, stx.size, mode_u32 & 0o7777, stx.uid, stx.gid, stx.mtime.sec, req.path, target_escaped });
defer allocator.free(resp);
try main.writeResponse(client_fd, "200 OK", "application/json", resp);
}
Expand Down
4 changes: 1 addition & 3 deletions sandboxd/src/processes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const exec = @import("exec.zig");
/// visible in the pod's pid namespace. Reading never triggers collection and
/// an idle daemon does zero extra work (the /proc scan happens only when a
/// consumer requests it).

/// handleProcesses serves GET /processes — JSON array of running processes.
pub fn handleProcesses(allocator: std.mem.Allocator, client_fd: i32, query: []const u8) !void {
_ = query;
Expand Down Expand Up @@ -52,8 +51,7 @@ pub fn handleProcesses(allocator: std.mem.Allocator, client_fd: i32, query: []co
if (wrote_any) try out.append(',');
wrote_any = true;
var entry_buf: [512]u8 = undefined;
const entry = try std.fmt.bufPrint(&entry_buf, "{{\"pid\":{d},\"comm\":\"{s}\",\"state\":\"{c}\"}}",
.{ pid, escaped, state });
const entry = try std.fmt.bufPrint(&entry_buf, "{{\"pid\":{d},\"comm\":\"{s}\",\"state\":\"{c}\"}}", .{ pid, escaped, state });
try out.appendSlice(entry);
}
}
Expand Down
5 changes: 1 addition & 4 deletions sandboxd/src/transcript.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const main = @import("main.zig");
///
/// Format per line: `<unix_seconds> <stream> <text>\n` where stream is one of
/// stdout|stderr|cmd.

const TRANSCRIPT_DIR = "/workspace/.k8e_transcripts";
/// Hard cap for a single window read (bounds per-request memory).
pub const max_window_bytes: usize = 256 * 1024;
Expand Down Expand Up @@ -188,9 +187,7 @@ pub fn handleTranscript(allocator: std.mem.Allocator, client_fd: i32, query: []c

const escaped = try exec_json_escape(allocator, w.output);
defer allocator.free(escaped);
const resp = try std.fmt.allocPrint(allocator,
"{{\"output\":\"{s}\",\"offset\":{d},\"next_offset\":{d},\"truncated_before\":{s},\"eof\":{s}}}",
.{ escaped, w.absolute_offset, w.next_offset, if (w.truncated_before) "true" else "false", if (w.eof) "true" else "false" });
const resp = try std.fmt.allocPrint(allocator, "{{\"output\":\"{s}\",\"offset\":{d},\"next_offset\":{d},\"truncated_before\":{s},\"eof\":{s}}}", .{ escaped, w.absolute_offset, w.next_offset, if (w.truncated_before) "true" else "false", if (w.eof) "true" else "false" });
defer allocator.free(resp);
try main.writeResponse(client_fd, "200 OK", "application/json", resp);
}
Expand Down
1 change: 0 additions & 1 deletion sandboxd/src/transcript_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const transcript = @import("transcript.zig");
// those trigger SIGSYS (same pre-existing limitation as exec_test runCommand
// fork tests). These tests are Linux-only and run in CI.


const TEST_BASE = "/tmp/k8e-transcript-test";

fn setupDir() void {
Expand Down
9 changes: 3 additions & 6 deletions sandboxd/src/watch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const main = @import("main.zig");
/// Watchers are created with a globally-incrementing id. The buffers are
/// plain memory: a daemon restart drops them, matching the process table's
/// honest non-persistence.

const WATCHER_MAX = 32;
const EVENT_BUF_MAX = 64;

Expand Down Expand Up @@ -151,9 +150,8 @@ pub fn handleCreate(allocator: std.mem.Allocator, client_fd: i32, body: []const
try main.writeResponse(client_fd, "400 Bad Request", "application/json", "{\"error\":\"path too long\"}");
return;
};
const wd_raw = std.os.linux.inotify_add_watch(inotify_fd, path_z,
std.os.linux.IN.CREATE | std.os.linux.IN.MODIFY | std.os.linux.IN.DELETE |
std.os.linux.IN.MOVED_FROM | std.os.linux.IN.MOVED_TO | std.os.linux.IN.ATTRIB);
const wd_raw = std.os.linux.inotify_add_watch(inotify_fd, path_z, std.os.linux.IN.CREATE | std.os.linux.IN.MODIFY | std.os.linux.IN.DELETE |
std.os.linux.IN.MOVED_FROM | std.os.linux.IN.MOVED_TO | std.os.linux.IN.ATTRIB);
const wd: isize = @bitCast(wd_raw);
if (wd < 0) {
try main.writeResponse(client_fd, "404 Not Found", "application/json", "{\"error\":\"path not found\"}");
Expand Down Expand Up @@ -217,8 +215,7 @@ pub fn handleEvents(allocator: std.mem.Allocator, client_fd: i32, query: []const
if (wrote_any) try out.append(',');
wrote_any = true;
var entry_buf: [320]u8 = undefined;
const entry = try std.fmt.bufPrint(&entry_buf, "{{\"name\":\"{s}\",\"type\":{d}}}",
.{ name, w.types[slot] });
const entry = try std.fmt.bufPrint(&entry_buf, "{{\"name\":\"{s}\",\"type\":{d}}}", .{ name, w.types[slot] });
try out.appendSlice(entry);
}
w.cursor = w.len;
Expand Down
18 changes: 7 additions & 11 deletions tandem/src/storage/rqlite.zig
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,7 @@ pub const SqlBuilder = struct {
pub fn atomicDeleteRangeSql(allocator: Allocator, key: []const u8, range_end: []const u8) ![]u8 {
const predicate = try keyPredicate(allocator, key, range_end);
defer allocator.free(predicate);
return std.fmt.allocPrint(allocator,
"BEGIN;DROP TABLE IF EXISTS tandem_delete_prev;CREATE TEMP TABLE tandem_delete_prev AS SELECT key,value,create_revision,mod_revision,version,lease FROM kv WHERE {s};" ++
return std.fmt.allocPrint(allocator, "BEGIN;DROP TABLE IF EXISTS tandem_delete_prev;CREATE TEMP TABLE tandem_delete_prev AS SELECT key,value,create_revision,mod_revision,version,lease FROM kv WHERE {s};" ++
"UPDATE revision SET current_revision=current_revision+1 WHERE id=1 AND EXISTS(SELECT 1 FROM tandem_delete_prev);" ++
"INSERT INTO kv_history(key,value,create_revision,mod_revision,version,lease,deleted) SELECT key,value,create_revision,(SELECT current_revision FROM revision WHERE id=1),version,lease,1 FROM tandem_delete_prev;" ++
"DELETE FROM lease_keys WHERE key IN (SELECT key FROM tandem_delete_prev);" ++
Expand Down Expand Up @@ -999,16 +998,14 @@ pub const SqlBuilder = struct {
/// deletions split across revisions, and a client counting revisions to
/// order its own writes saw a gap that was never a real write.
pub fn revokeLeaseWithKeysSql(allocator: Allocator, lease_id: i64) ![]u8 {
return std.fmt.allocPrint(allocator,
"BEGIN;" ++
return std.fmt.allocPrint(allocator, "BEGIN;" ++
"UPDATE revision SET current_revision=current_revision+1 WHERE id=1 AND EXISTS(SELECT 1 FROM kv WHERE lease={d});" ++
"INSERT INTO kv_history(key,value,create_revision,mod_revision,version,lease,deleted) " ++
"SELECT key,value,create_revision,(SELECT current_revision FROM revision WHERE id=1),version,lease,1 FROM kv WHERE lease={d};" ++
"DELETE FROM kv WHERE lease={d};" ++
"DELETE FROM lease_keys WHERE lease_id={d};" ++
"DELETE FROM leases WHERE id={d};" ++
"COMMIT;",
.{ lease_id, lease_id, lease_id, lease_id, lease_id });
"COMMIT;", .{ lease_id, lease_id, lease_id, lease_id, lease_id });
}

/// Expire one leased key: record the tombstone, drop the row and the lease
Expand Down Expand Up @@ -1055,12 +1052,10 @@ pub const SqlBuilder = struct {
defer allocator.free(hex);
const guard = try leaseOwnerGuardSql(allocator, lease_id, owner, now);
defer allocator.free(guard);
return std.fmt.allocPrint(allocator,
"BEGIN;UPDATE revision SET current_revision=current_revision+1 WHERE id=1 AND EXISTS(SELECT 1 FROM kv WHERE key=X'{s}' AND lease={d}) AND {s};" ++
return std.fmt.allocPrint(allocator, "BEGIN;UPDATE revision SET current_revision=current_revision+1 WHERE id=1 AND EXISTS(SELECT 1 FROM kv WHERE key=X'{s}' AND lease={d}) AND {s};" ++
"INSERT INTO kv_history(key,value,create_revision,mod_revision,version,lease,deleted) SELECT key,value,create_revision,(SELECT current_revision FROM revision WHERE id=1),version,lease,1 FROM kv WHERE key=X'{s}' AND lease={d} AND {s};" ++
"DELETE FROM kv WHERE key=X'{s}' AND lease={d} AND {s};" ++
"DELETE FROM lease_keys WHERE key=X'{s}' AND lease_id={d} AND {s};COMMIT;",
.{ hex, lease_id, guard, hex, lease_id, guard, hex, lease_id, guard, hex, lease_id, guard });
"DELETE FROM lease_keys WHERE key=X'{s}' AND lease_id={d} AND {s};COMMIT;", .{ hex, lease_id, guard, hex, lease_id, guard, hex, lease_id, guard, hex, lease_id, guard });
}

pub fn revokeLeaseOwnedSql(allocator: Allocator, lease_id: i64, owner: []const u8, now: i64) ![]u8 {
Expand Down Expand Up @@ -1750,7 +1745,8 @@ test "the rqlite status parser reads nested leader and raft fields" {
test "a status without a leader reports none rather than a fabricated one" {
// A node that has not elected itself still answers /status, and the
// caller reports "no leader" instead of the constant 1 this used to send.
const body = \\{"store":{"ready":false,"node_id":"n1","leader":{},"raft":{"term":0,"applied_index":0}}}
const body =
\\{"store":{"ready":false,"node_id":"n1","leader":{},"raft":{"term":0,"applied_index":0}}}
;
const status = try parseStatusResponse(testing.allocator, body);
defer testing.allocator.free(status.leader_address);
Expand Down
Loading