gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3698438636984386Preserve state transitions when their notes are editedmre36984386/plugins/http/http_common.zig

22.1 KB

  1. // Shared HTTP utilities — compiled into each HTTP plugin at build time
  2. // Not a standalone plugin .so, but a Zig module imported by hl:http1, hl:http2, hl:http3
  3. const std = @import("std");
  4. const api = @import("plugin_api");
  5. pub const HlString = api.HlString;
  6. pub fn hlStr(s: []const u8) HlString {
  7. return .{ .ptr = s.ptr, .len = s.len };
  8. }
  9. pub fn statusReason(code: u16) []const u8 {
  10. return switch (code) {
  11. 200 => "OK",
  12. 201 => "Created",
  13. 204 => "No Content",
  14. 301 => "Moved Permanently",
  15. 302 => "Found",
  16. 304 => "Not Modified",
  17. 400 => "Bad Request",
  18. 401 => "Unauthorized",
  19. 403 => "Forbidden",
  20. 404 => "Not Found",
  21. 405 => "Method Not Allowed",
  22. 409 => "Conflict",
  23. 413 => "Payload Too Large",
  24. 415 => "Unsupported Media Type",
  25. 422 => "Unprocessable Entity",
  26. 429 => "Too Many Requests",
  27. 500 => "Internal Server Error",
  28. 502 => "Bad Gateway",
  29. 503 => "Service Unavailable",
  30. 504 => "Gateway Timeout",
  31. else => "OK",
  32. };
  33. }
  34. /// Decode percent-encoded URL components (%20 → space, etc.)
  35. pub fn urlDecode(allocator: anytype, input: []const u8) ![]u8 {
  36. var result = try allocator.alloc(u8, input.len);
  37. var out: usize = 0;
  38. var i: usize = 0;
  39. while (i < input.len) {
  40. if (input[i] == '%' and i + 2 < input.len) {
  41. const hi = hexVal(input[i + 1]) orelse {
  42. result[out] = input[i];
  43. out += 1;
  44. i += 1;
  45. continue;
  46. };
  47. const lo = hexVal(input[i + 2]) orelse {
  48. result[out] = input[i];
  49. out += 1;
  50. i += 1;
  51. continue;
  52. };
  53. result[out] = (@as(u8, hi) << 4) | @as(u8, lo);
  54. out += 1;
  55. i += 3;
  56. } else if (input[i] == '+') {
  57. result[out] = ' ';
  58. out += 1;
  59. i += 1;
  60. } else {
  61. result[out] = input[i];
  62. out += 1;
  63. i += 1;
  64. }
  65. }
  66. return result[0..out];
  67. }
  68. fn hexVal(c: u8) ?u4 {
  69. if (c >= '0' and c <= '9') return @intCast(c - '0');
  70. if (c >= 'a' and c <= 'f') return @intCast(c - 'a' + 10);
  71. if (c >= 'A' and c <= 'F') return @intCast(c - 'A' + 10);
  72. return null;
  73. }
  74. /// Split a query string into key-value pairs.
  75. /// Returns allocated slices that must be freed by the caller.
  76. pub fn parseQueryString(alloc: anytype, query: []const u8) ![]QueryParam {
  77. var params: @import("std").ArrayListUnmanaged(QueryParam) = .empty;
  78. var iter = @import("std").mem.splitScalar(u8, query, '&');
  79. while (iter.next()) |pair| {
  80. if (pair.len == 0) continue;
  81. if (@import("std").mem.indexOfScalar(u8, pair, '=')) |eq| {
  82. const key = try urlDecode(alloc, pair[0..eq]);
  83. const val = try urlDecode(alloc, pair[eq + 1 ..]);
  84. try params.append(alloc, .{ .key = key, .value = val });
  85. } else {
  86. const key = try urlDecode(alloc, pair);
  87. try params.append(alloc, .{ .key = key, .value = &[_]u8{} });
  88. }
  89. }
  90. return params.toOwnedSlice(alloc);
  91. }
  92. pub const QueryParam = struct {
  93. key: []u8,
  94. value: []u8,
  95. };
  96. /// Lowercase a header key in-place (HTTP/1.1 headers are case-insensitive)
  97. pub fn toLowercase(buf: []u8) void {
  98. for (buf) |*ch| {
  99. if (ch.* >= 'A' and ch.* <= 'Z') {
  100. ch.* = ch.* + 32;
  101. }
  102. }
  103. }
  104. // ---------------------------------------------------------------------------
  105. // RESPONSE HEADERS WITH MORE THAN ONE VALUE (ticket #222) — ONE implementation
  106. // for hl:http1, hl:http2 and hl:http3, so the three cannot drift.
  107. //
  108. // A header value in a Response may be a String (one header line) or an Array of
  109. // Strings (one header line, or one HTTP/2 / HTTP/3 field, per entry). An array
  110. // crosses the plugin boundary as an object keyed "0".."n-1", so any object value
  111. // is read as a list; entries that are not strings are skipped, an empty list
  112. // writes nothing. Names are compared WITHOUT regard to case: keys that differ
  113. // only in case ("Set-Cookie" and "set-cookie") are merged into one list in the
  114. // order they were written, and sit where the first of them stood, under the
  115. // spelling of that first one. Values are never joined into one comma line:
  116. // that is wrong for Set-Cookie.
  117. // ---------------------------------------------------------------------------
  118. /// Call `sink.add(name, value)` once per header line the headers object `obj`
  119. /// stands for. `sink` is any pointer with an `add([]const u8, []const u8) void`.
  120. pub fn eachHeaderLine(obj: *const api.HlObject, sink: anytype) void {
  121. const fields = obj.fields[0..obj.field_count];
  122. for (fields, 0..) |field, i| {
  123. if (field.value.type != .hl_string and field.value.type != .hl_object) continue;
  124. const name = field.key.ptr[0..field.key.len];
  125. // an earlier key of the same name (in any case) already wrote this one's values
  126. var seen = false;
  127. for (fields[0..i]) |prev| {
  128. if (prev.value.type != .hl_string and prev.value.type != .hl_object) continue;
  129. if (std.ascii.eqlIgnoreCase(prev.key.ptr[0..prev.key.len], name)) {
  130. seen = true;
  131. break;
  132. }
  133. }
  134. if (seen) continue;
  135. for (fields[i..]) |same| {
  136. if (!std.ascii.eqlIgnoreCase(same.key.ptr[0..same.key.len], name)) continue;
  137. switch (same.value.type) {
  138. .hl_string => sink.add(name, same.value.data.string.ptr[0..same.value.data.string.len]),
  139. .hl_object => {
  140. const list = same.value.data.object;
  141. for (list.fields[0..list.field_count]) |item| {
  142. if (item.value.type == .hl_string) sink.add(name, item.value.data.string.ptr[0..item.value.data.string.len]);
  143. }
  144. },
  145. else => {},
  146. }
  147. }
  148. }
  149. }
  150. const TestSink = struct {
  151. out: std.ArrayListUnmanaged(u8) = .empty,
  152. pub fn add(self: *TestSink, name: []const u8, value: []const u8) void {
  153. self.out.appendSlice(std.testing.allocator, name) catch {};
  154. self.out.appendSlice(std.testing.allocator, "=") catch {};
  155. self.out.appendSlice(std.testing.allocator, value) catch {};
  156. self.out.appendSlice(std.testing.allocator, ";") catch {};
  157. }
  158. };
  159. test "eachHeaderLine: lists, case-merge, order" {
  160. var cookies = [_]api.HlField{
  161. .{ .key = hlStr("0"), .value = api.makeString("a=1") },
  162. .{ .key = hlStr("1"), .value = api.makeString("b=2") },
  163. };
  164. var list = api.HlObject{ .fields = &cookies, .field_count = 2, .deinit_fn = null };
  165. var fields = [_]api.HlField{
  166. .{ .key = hlStr("Set-Cookie"), .value = api.makeObject(&list) },
  167. .{ .key = hlStr("X-One"), .value = api.makeString("1") },
  168. .{ .key = hlStr("set-cookie"), .value = api.makeString("c=3") },
  169. };
  170. var obj = api.HlObject{ .fields = &fields, .field_count = 3, .deinit_fn = null };
  171. var sink = TestSink{};
  172. defer sink.out.deinit(std.testing.allocator);
  173. eachHeaderLine(&obj, &sink);
  174. try std.testing.expectEqualStrings("Set-Cookie=a=1;Set-Cookie=b=2;Set-Cookie=c=3;X-One=1;", sink.out.items);
  175. }
  176. // ---------------------------------------------------------------------------
  177. // RESPONSE BODY COMPRESSION (creator, 2026-08-15) — a TRANSPORT concern, like
  178. // TLS: nobody writes compression in app code; a server honors Accept-Encoding.
  179. // ONE implementation here (decision D8's pattern), each plugin adds only its
  180. // own framing. gzip via Zig std flate — no external library.
  181. // ---------------------------------------------------------------------------
  182. /// Below this a gzip header+footer is overhead, not savings (canonical ~860
  183. /// from Akamai's measurements; MTU-fitting responses gain nothing).
  184. pub const compress_min_len = 860;
  185. /// The texty content types worth compressing, decided from the Content-Type
  186. /// VALUE. Already-compressed formats (images, fonts, archives) get bigger, not
  187. /// smaller. hl:http2 and hl:http3 carry headers as key/value pairs rather than
  188. /// h1's raw blob, so this is the half they can ask.
  189. pub fn compressibleTypeValue(value: []const u8) bool {
  190. const v = std.mem.trim(u8, value, " ");
  191. return std.mem.startsWith(u8, v, "text/") or
  192. std.mem.startsWith(u8, v, "application/javascript") or
  193. std.mem.startsWith(u8, v, "application/json") or
  194. std.mem.startsWith(u8, v, "image/svg");
  195. }
  196. /// The same question asked of h1's assembled custom-header text.
  197. pub fn compressibleContentType(headers_blob: []const u8) bool {
  198. var it = std.mem.splitSequence(u8, headers_blob, "\r\n");
  199. while (it.next()) |line| {
  200. if (line.len > 13 and std.ascii.eqlIgnoreCase(line[0..13], "content-type:")) {
  201. return compressibleTypeValue(line[13..]);
  202. }
  203. if (line.len > 17 and std.ascii.eqlIgnoreCase(line[0..17], "content-encoding:")) return false;
  204. }
  205. // no Content-Type in custom headers → the plugin's default is text/html
  206. return true;
  207. }
  208. /// gzip `body`; null when compression does not pay (or fails — the caller then
  209. /// sends the identity bytes, which is always correct).
  210. pub fn gzipBody(allocator: std.mem.Allocator, body: []const u8) ?[]u8 {
  211. if (body.len < compress_min_len) return null;
  212. // Compress.init asserts `output.buffer.len > 8`, and a plain
  213. // Allocating.init starts EMPTY — the assert then panics on a worker thread
  214. // and kills the server after the first compressed response (found the hard
  215. // way 2026-08-15). initCapacity gives the writer its buffer up front.
  216. var out: std.Io.Writer.Allocating = std.Io.Writer.Allocating.initCapacity(allocator, 4096) catch return null;
  217. defer out.deinit();
  218. const window = allocator.alloc(u8, std.compress.flate.max_window_len) catch return null;
  219. defer allocator.free(window);
  220. // .level_6 — the documented setting; Options carries no defaults.
  221. var c = std.compress.flate.Compress.init(&out.writer, window, .gzip, .level_6) catch return null;
  222. c.writer.writeAll(body) catch return null;
  223. c.finish() catch return null;
  224. if (out.writer.buffered().len >= body.len) return null; // grew: send identity
  225. return allocator.dupe(u8, out.writer.buffered()) catch null;
  226. }
  227. // ── The mission-125 BELL: one eventfd per loop source ────────────────────────
  228. //
  229. // RESTORED 2026-08-29 (mission 257). `hl:fetch` and `hl:smtp` both call these by
  230. // name, and both had been UNBUILDABLE since the 2026-08-20 recovery replay
  231. // dropped them from this file — nothing noticed, because `native/build.zig` did
  232. // not build either plugin. See `native/src/loop_wait.zig` for the contract they
  233. // implement: the loop owns one epoll set over every source's `wake_fd`, adds it
  234. // LEVEL-triggered, and drains the counter itself right after `epoll_wait`. A
  235. // producer therefore only ever has to create the fd and write to it.
  236. //
  237. // Raw syscalls rather than libc, so a plugin that does not link libc (hl:http1)
  238. // can still ring a bell.
  239. /// A source's wake fd: a non-blocking eventfd counter. `-1` on failure, which is
  240. /// the ABI's "no signal, keep polling" value — a plugin that cannot get an fd
  241. /// degrades to the polled path instead of failing to load.
  242. pub fn makeWakeFd() i32 {
  243. const rc = std.os.linux.eventfd(0, std.os.linux.EFD.NONBLOCK | std.os.linux.EFD.CLOEXEC);
  244. if (@as(isize, @bitCast(rc)) < 0) return -1;
  245. return @intCast(rc);
  246. }
  247. /// RING IT. Coalesced, duplicated or early wakes are harmless by design (a bell,
  248. /// not a routing key); only a wake that is never sent can be a bug — so producers
  249. /// ring generously and never reason about whether the loop "needs" it.
  250. pub fn ringWake(fd: i32) void {
  251. if (fd < 0) return;
  252. const one: u64 = 1;
  253. _ = std.os.linux.write(fd, @ptrCast(&one), @sizeOf(u64));
  254. }
  255. // ================================================================================
  256. // WHY A BIND FAILED — IN WORDS, AND WITH THE HOLDER'S NAME (mission 286)
  257. // ================================================================================
  258. // All three transports used to print the same six words — `bind() failed on port
  259. // N` — and drop the errno on the floor. Six words cannot be acted on: a port that
  260. // is taken, a port below 1024 without CAP_NET_BIND_SERVICE, and an address that is
  261. // not one of this machine's are three different mistakes with three different
  262. // fixes, and the kernel had already said which one it was.
  263. //
  264. // So the errno is named, and when it is EADDRINUSE the holder is looked up the way
  265. // an operator would look it up: `/proc/net/{tcp,tcp6,udp,udp6}` for the socket on
  266. // that port, then `/proc/<pid>/fd` for whoever owns its inode. It says "a process
  267. // this one cannot see" rather than guessing when the holder belongs to another
  268. // user — `/proc/<pid>/fd` is unreadable then, and a wrong name is worse than none.
  269. //
  270. // This costs nothing on the happy path: it runs once, on a boot that is about to
  271. // be refused.
  272. fn errnoWord(e: u32) []const u8 {
  273. return switch (e) {
  274. 13 => "EACCES",
  275. 22 => "EINVAL",
  276. 24 => "EMFILE",
  277. 97 => "EAFNOSUPPORT",
  278. 98 => "EADDRINUSE",
  279. 99 => "EADDRNOTAVAIL",
  280. else => "errno",
  281. };
  282. }
  283. fn errnoWhy(e: u32) []const u8 {
  284. return switch (e) {
  285. 13 => "permission denied — a port below 1024 needs CAP_NET_BIND_SERVICE or root",
  286. 22 => "invalid argument — this socket is already bound",
  287. 24 => "too many open files — the process fd limit is reached",
  288. 97 => "address family not supported",
  289. 98 => "the port is already in use",
  290. 99 => "that address is not one of this machine's",
  291. else => "the kernel refused the bind",
  292. };
  293. }
  294. fn hexNibble(c: u8) ?u8 {
  295. return switch (c) {
  296. '0'...'9' => c - '0',
  297. 'a'...'f' => c - 'a' + 10,
  298. 'A'...'F' => c - 'A' + 10,
  299. else => null,
  300. };
  301. }
  302. fn hexValue(s: []const u8) ?u64 {
  303. if (s.len == 0 or s.len > 16) return null;
  304. var v: u64 = 0;
  305. for (s) |c| v = (v << 4) | (hexNibble(c) orelse return null);
  306. return v;
  307. }
  308. /// `/proc/net/*`'s local_address column ("0100007F:1F90") as text the operator
  309. /// recognises. IPv4 is four little-endian bytes; anything longer is printed as the
  310. /// raw hex word rather than mis-rendered as a v6 address it may not be.
  311. fn writeProcAddr(out: []u8, hex: []const u8, port: u16) []const u8 {
  312. if (hex.len == 8) {
  313. const v = hexValue(hex) orelse return "";
  314. const b: [4]u8 = .{
  315. @truncate(v & 0xff),
  316. @truncate((v >> 8) & 0xff),
  317. @truncate((v >> 16) & 0xff),
  318. @truncate((v >> 24) & 0xff),
  319. };
  320. return std.fmt.bufPrint(out, "{d}.{d}.{d}.{d}:{d}", .{ b[0], b[1], b[2], b[3], port }) catch "";
  321. }
  322. return std.fmt.bufPrint(out, "[{s}]:{d}", .{ hex, port }) catch "";
  323. }
  324. // RAW SYSCALLS, for the same reason the wake bell above uses them: this file is
  325. // compiled INTO three plugins, `std.fs` in Zig 0.16 wants an `Io` interface these
  326. // plugins do not carry, and `/proc` is read once, at a boot that is failing.
  327. const lin = std.os.linux;
  328. fn sysOpen(path: [*:0]const u8, dir: bool) ?i32 {
  329. const rc = lin.open(path, .{ .ACCMODE = .RDONLY, .CLOEXEC = true, .DIRECTORY = dir }, 0);
  330. const fd: i64 = @bitCast(@as(u64, rc));
  331. if (fd < 0) return null;
  332. return @intCast(fd);
  333. }
  334. fn sysClose(fd: i32) void {
  335. _ = lin.close(fd);
  336. }
  337. const SocketOnPort = struct { inode: u64, addr_hex: [40]u8, addr_len: usize };
  338. /// The socket sitting on `port`, out of the four `/proc/net` tables. For TCP only a
  339. /// LISTEN socket (`st == 0A`) can block a bind — mission 285 measured that, squat by
  340. /// squat: TIME_WAIT and ESTABLISHED are tolerated because both sides set
  341. /// SO_REUSEADDR. UDP has no states worth filtering.
  342. fn socketOnPort(port: u16, udp: bool) ?SocketOnPort {
  343. const tables: [2][*:0]const u8 = if (udp)
  344. .{ "/proc/net/udp", "/proc/net/udp6" }
  345. else
  346. .{ "/proc/net/tcp", "/proc/net/tcp6" };
  347. for (tables) |path| {
  348. const fd = sysOpen(path, false) orelse continue;
  349. defer sysClose(fd);
  350. var chunk: [8192]u8 = undefined;
  351. var line: [512]u8 = undefined;
  352. var line_len: usize = 0;
  353. while (true) {
  354. const rc = lin.read(fd, &chunk, chunk.len);
  355. const got: i64 = @bitCast(@as(u64, rc));
  356. if (got <= 0) break;
  357. const n: usize = @intCast(got);
  358. for (chunk[0..n]) |ch| {
  359. if (ch != '\n') {
  360. if (line_len < line.len) {
  361. line[line_len] = ch;
  362. line_len += 1;
  363. }
  364. continue;
  365. }
  366. if (parseProcNetLine(line[0..line_len], port, udp)) |hit| return hit;
  367. line_len = 0;
  368. }
  369. }
  370. if (line_len > 0) {
  371. if (parseProcNetLine(line[0..line_len], port, udp)) |hit| return hit;
  372. }
  373. }
  374. return null;
  375. }
  376. /// One `/proc/net/*` row: `sl local rem st tx:rx tr:when retrnsmt uid timeout inode`.
  377. fn parseProcNetLine(line: []const u8, port: u16, udp: bool) ?SocketOnPort {
  378. var it = std.mem.tokenizeAny(u8, line, " \t");
  379. _ = it.next() orelse return null; // sl
  380. const local = it.next() orelse return null;
  381. _ = it.next() orelse return null; // rem_address
  382. const st = it.next() orelse return null;
  383. if (!udp and !std.mem.eql(u8, st, "0A")) return null;
  384. const colon = std.mem.lastIndexOfScalar(u8, local, ':') orelse return null;
  385. const lport = hexValue(local[colon + 1 ..]) orelse return null;
  386. if (lport != port) return null;
  387. var skipped: usize = 0;
  388. while (skipped < 5) : (skipped += 1) _ = it.next() orelse return null;
  389. const inode = std.fmt.parseInt(u64, it.next() orelse return null, 10) catch return null;
  390. const hex = local[0..colon];
  391. var hit = SocketOnPort{ .inode = inode, .addr_hex = undefined, .addr_len = 0 };
  392. if (hex.len > hit.addr_hex.len) return null;
  393. @memcpy(hit.addr_hex[0..hex.len], hex);
  394. hit.addr_len = hex.len;
  395. return hit;
  396. }
  397. /// Whoever has that socket inode open. An unreadable `/proc/<pid>/fd` is SKIPPED,
  398. /// not reported as absent: a holder owned by another user is invisible from here,
  399. /// and the caller says exactly that instead of naming the wrong process.
  400. fn pidHolding(inode: u64, name_out: []u8, name_len: *usize) ?u32 {
  401. const proc_fd = sysOpen("/proc", true) orelse return null;
  402. defer sysClose(proc_fd);
  403. var want: [48]u8 = undefined;
  404. const want_link = std.fmt.bufPrint(&want, "socket:[{d}]", .{inode}) catch return null;
  405. var ents: [8192]u8 align(8) = undefined;
  406. while (true) {
  407. const rc = lin.getdents64(proc_fd, &ents, ents.len);
  408. const got: i64 = @bitCast(@as(u64, rc));
  409. if (got <= 0) return null;
  410. var off: usize = 0;
  411. while (off < @as(usize, @intCast(got))) {
  412. const ent: *align(1) const lin.dirent64 = @ptrCast(&ents[off]);
  413. off += ent.reclen;
  414. const name_ptr: [*:0]const u8 = @ptrCast(&ent.name);
  415. const pid = std.fmt.parseInt(u32, std.mem.span(name_ptr), 10) catch continue;
  416. if (fdsHold(pid, want_link)) {
  417. name_len.* = readComm(pid, name_out);
  418. return pid;
  419. }
  420. }
  421. }
  422. }
  423. /// Does this pid have that socket open? An unreadable `/proc/<pid>/fd` answers
  424. /// false — the process belongs to another user and is simply not visible.
  425. fn fdsHold(pid: u32, want_link: []const u8) bool {
  426. var path: [64:0]u8 = undefined;
  427. const dir_path = std.fmt.bufPrintZ(&path, "/proc/{d}/fd", .{pid}) catch return false;
  428. const dir_fd = sysOpen(dir_path, true) orelse return false;
  429. defer sysClose(dir_fd);
  430. var ents: [4096]u8 align(8) = undefined;
  431. while (true) {
  432. const rc = lin.getdents64(dir_fd, &ents, ents.len);
  433. const got: i64 = @bitCast(@as(u64, rc));
  434. if (got <= 0) return false;
  435. var off: usize = 0;
  436. while (off < @as(usize, @intCast(got))) {
  437. const ent: *align(1) const lin.dirent64 = @ptrCast(&ents[off]);
  438. off += ent.reclen;
  439. const name_ptr: [*:0]const u8 = @ptrCast(&ent.name);
  440. var lbuf: [64]u8 = undefined;
  441. const lrc = lin.readlinkat(dir_fd, name_ptr, &lbuf, lbuf.len);
  442. const llen: i64 = @bitCast(@as(u64, lrc));
  443. if (llen <= 0) continue;
  444. if (std.mem.eql(u8, lbuf[0..@intCast(llen)], want_link)) return true;
  445. }
  446. }
  447. }
  448. fn readComm(pid: u32, out: []u8) usize {
  449. var path: [64:0]u8 = undefined;
  450. const p = std.fmt.bufPrintZ(&path, "/proc/{d}/comm", .{pid}) catch return 0;
  451. const fd = sysOpen(p, false) orelse return 0;
  452. defer sysClose(fd);
  453. const rc = lin.read(fd, out.ptr, out.len);
  454. const got: i64 = @bitCast(@as(u64, rc));
  455. if (got <= 0) return 0;
  456. var len: usize = @intCast(got);
  457. while (len > 0 and (out[len - 1] == '\n' or out[len - 1] == '\r')) len -= 1;
  458. return len;
  459. }
  460. /// The sentence a transport appends to `bind() failed on port N`. It never fails: a
  461. /// buffer too small or a `/proc` that will not answer degrades to the part that IS
  462. /// known, and the errno alone already says more than the old message did.
  463. pub fn bindFailureDetail(out: []u8, rc: usize, port: u16, udp: bool) []const u8 {
  464. const signed: i64 = @bitCast(@as(u64, rc));
  465. const errno: u32 = if (signed < 0 and signed > -4096) @intCast(-signed) else 0;
  466. var w: usize = 0;
  467. const head = std.fmt.bufPrint(out[w..], "{s} — {s}", .{ errnoWord(errno), errnoWhy(errno) }) catch return out[0..w];
  468. w += head.len;
  469. if (errno != 98) return out[0..w];
  470. const sock = socketOnPort(port, udp) orelse {
  471. const gone = std.fmt.bufPrint(out[w..], "; nothing holds it now — the listener came and went", .{}) catch return out[0..w];
  472. return out[0 .. w + gone.len];
  473. };
  474. var abuf: [80]u8 = undefined;
  475. const addr = writeProcAddr(&abuf, sock.addr_hex[0..sock.addr_len], port);
  476. var comm: [32]u8 = undefined;
  477. var comm_len: usize = 0;
  478. if (pidHolding(sock.inode, &comm, &comm_len)) |pid| {
  479. const tail = std.fmt.bufPrint(out[w..], "; held by pid {d} ({s}) on {s}", .{ pid, comm[0..comm_len], addr }) catch return out[0..w];
  480. return out[0 .. w + tail.len];
  481. }
  482. const tail = std.fmt.bufPrint(out[w..], "; held on {s} by a process this one cannot see (another user)", .{addr}) catch return out[0..w];
  483. return out[0 .. w + tail.len];
  484. }

Branches

Latest commits

  • 36984386Preserve state transitions when their notes are editedmre
  • d75cb946Log E30 startmre
  • 0bf3fefaMission 030: edited state note labelmre
  • 691565c6Log neutral-ticket rule checkmre
  • bc3bdecerecords: day38b live, #94 purgedmre
  • f6c5aa0dMerge main (records)mre
  • e23d42acconnect gate: wait for hydration before clicking Disconnectmre
  • a5d45d00records: D38 cause, GOmre
  • 19eeb938records: D38 gates, two day38b failuresmre
  • f8e42a85Re-vendor tickets to Hybriel set day38b (1e554d7)mre
  • 51645016Merge purge-94 (#94, identity rule)mre
  • 94d6ca2arecords: D38 startedmre
  • 9df09aacmission 029: day38b re-vendor + deploymre
  • d2834f65records: #94 backup planmre
  • 4467d8cbrecords: #94 purge readymre
  • aa2d124eREADME: the #94 purge gatemre
  • e843ff7cOne-time purge of miserit-anthar#94 (#94, identity rule): idempotent step in lib/migrate.hl, fixture gate tests/purge94.mjsmre
  • 506a4efdmission 028: #94, identity rulemre
  • 78c7f48eRefine mpackdb holdmre
  • 3d7d89c8Record mpackdb hold until day38mre