Skip to content

Commit

Permalink
Fix failure for lacked hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
g41797 committed Dec 4, 2024
1 parent 6f8805e commit a41d48a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on: [push, pull_request]

env:
HOSTNAME: ANYHOSTNAME


jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "lldb",
"request": "launch",
"name": "Debug Test",
"program": "${workspaceFolder}/zig-out/test-binary",
"program": "${workspaceFolder}/zig-out/bin/test",
"preLaunchTask": "build_test",
"args": [],
"cwd": "${workspaceFolder}",
Expand Down
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
"label": "build_test",
"type": "shell",
"command": "zig",
"args": [
"build",
"install",
"--summary",
"all"
],
"group": "test"
},
{
"label": "build_test_org",
"type": "shell",
"command": "zig",
"args": [
"test",
"${input:testFile}",
Expand Down
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn build(b: *std.Build) void {
lib_unit_tests.root_module.addImport("network", zig_network.module("network"));
lib_unit_tests.root_module.addImport("zig-datetime", zig_datetime.module("zig-datetime"));
lib_unit_tests.root_module.addImport("mailbox", mailbox.module("mailbox"));
b.installArtifact(lib_unit_tests);

const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);

Expand Down
8 changes: 6 additions & 2 deletions src/application.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ pub const Application = struct {

var fbAllocator = std.heap.FixedBufferAllocator.init(&buffer);
const allocator = fbAllocator.allocator();
const hostName = std.process.getEnvVarOwned(allocator, envMame) catch "-";
var hostName = std.process.getEnvVarOwned(allocator, envMame) catch "";

defer allocator.free(hostName);
if (hostName.len == 0) {
hostName = "-";
} else {
defer allocator.free(hostName);
}

_ = try appl.*.host_name.fillFrom(hostName);

Expand Down

0 comments on commit a41d48a

Please sign in to comment.