fixes
This commit is contained in:
parent
aa9d8216d9
commit
dab10464fe
1 changed files with 25 additions and 14 deletions
39
src/main.zig
39
src/main.zig
|
@ -67,9 +67,11 @@ fn readConfig(allocator: std.mem.Allocator, path: []const u8) !ConfigWrapper(Con
|
|||
.arena = try allocator.create(std.heap.ArenaAllocator),
|
||||
.value = undefined,
|
||||
};
|
||||
config.arena.child_allocator = allocator;
|
||||
const data = try std.fs.cwd().readFileAlloc(config.arena.child_allocator, path, 1024);
|
||||
config.value = try std.json.parseFromSliceLeaky(Config, config.arena.child_allocator, data, .{});
|
||||
errdefer allocator.destroy(config.arena);
|
||||
config.arena.* = std.heap.ArenaAllocator.init(allocator);
|
||||
errdefer config.arena.deinit();
|
||||
const data = try std.fs.cwd().readFileAlloc(config.arena.allocator(), path, 1024);
|
||||
config.value = try std.json.parseFromSliceLeaky(Config, config.arena.allocator(), data, .{});
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -102,7 +104,10 @@ pub fn main() !void {
|
|||
var password_buffer: [128]u8 = undefined;
|
||||
var password: []const u8 = undefined;
|
||||
if (config.value.loki.password_file) |password_file_path| {
|
||||
password = try std.fs.cwd().readFile(password_file_path, &password_buffer);
|
||||
password = std.fs.cwd().readFile(password_file_path, &password_buffer) catch |err| {
|
||||
iperf3_log.err("error trying to read password file {s}: {}", .{ password_file_path, err });
|
||||
return;
|
||||
};
|
||||
password = std.mem.trimRight(u8, password, "\r\n");
|
||||
} else if (config.value.loki.password) |password_data| {
|
||||
@memcpy(&password_buffer, password_data);
|
||||
|
@ -133,9 +138,6 @@ pub fn main() !void {
|
|||
|
||||
const uri = try std.Uri.parse(url);
|
||||
|
||||
var client = std.http.Client{ .allocator = allocator };
|
||||
defer client.deinit();
|
||||
|
||||
var port_buf: [16]u8 = undefined;
|
||||
var port: []u8 = undefined;
|
||||
if (config.value.iperf3.port) |p| {
|
||||
|
@ -169,15 +171,15 @@ pub fn main() !void {
|
|||
"--json",
|
||||
"--one-off",
|
||||
},
|
||||
arena.child_allocator,
|
||||
arena.allocator(),
|
||||
);
|
||||
c.stdin_behavior = .Ignore;
|
||||
c.stdout_behavior = .Pipe;
|
||||
c.stderr_behavior = .Pipe;
|
||||
try c.spawn();
|
||||
|
||||
var stdout = std.ArrayList(u8).init(arena.child_allocator);
|
||||
var stderr = std.ArrayList(u8).init(arena.child_allocator);
|
||||
var stdout = std.ArrayList(u8).init(arena.allocator());
|
||||
var stderr = std.ArrayList(u8).init(arena.allocator());
|
||||
|
||||
iperf3_log.info("waiting for data", .{});
|
||||
|
||||
|
@ -197,7 +199,7 @@ pub fn main() !void {
|
|||
|
||||
var obj_or_err = std.json.parseFromSliceLeaky(
|
||||
iperf3.IPerfReturn,
|
||||
arena.child_allocator,
|
||||
arena.allocator(),
|
||||
stdout.items,
|
||||
.{},
|
||||
);
|
||||
|
@ -243,7 +245,7 @@ pub fn main() !void {
|
|||
},
|
||||
};
|
||||
|
||||
var data = std.ArrayList(u8).init(allocator);
|
||||
var data = std.ArrayList(u8).init(arena.allocator());
|
||||
try std.json.stringify(
|
||||
streams,
|
||||
.{
|
||||
|
@ -260,13 +262,22 @@ pub fn main() !void {
|
|||
.{data.items.len},
|
||||
);
|
||||
|
||||
var headers = std.http.Headers{ .allocator = allocator };
|
||||
var client = std.http.Client{ .allocator = arena.allocator() };
|
||||
defer client.deinit();
|
||||
|
||||
var headers = std.http.Headers{ .allocator = arena.allocator() };
|
||||
try headers.append("Authorization", auth_header);
|
||||
try headers.append("Accept", "application/json");
|
||||
try headers.append("Content-Type", "application/json");
|
||||
try headers.append("Content-Length", content_length);
|
||||
defer headers.deinit();
|
||||
|
||||
var req = try client.request(.POST, uri, headers, .{});
|
||||
var req = try client.request(
|
||||
.POST,
|
||||
uri,
|
||||
headers,
|
||||
.{},
|
||||
);
|
||||
defer req.deinit();
|
||||
|
||||
iperf3_log.info("sending stream to loki", .{});
|
||||
|
|
Loading…
Reference in a new issue