Skip to content

Commit 2a1e7c0

Browse files
committed
fix: env not work on boot
1 parent a7c06d5 commit 2a1e7c0

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn _main() !void {
5757
\\ z print stdout and stderr of z
5858
\\
5959
\\
60-
\\v20240722 https://github.com/txthinking/z
60+
\\v20240723 https://github.com/txthinking/z
6161
\\
6262
\\
6363
;

src/server.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ pub fn start(self: *Server) !void {
7979
}
8080
}
8181
}
82+
const r2 = try helper.readFile(self.allocator, "/etc/.z/env.json");
83+
if (r2) |r1| {
84+
defer self.allocator.free(r1.b);
85+
const p = try std.json.parseFromSlice([][]u8, self.allocator, r1.b[0..r1.n], .{ .allocate = .alloc_always });
86+
defer p.deinit();
87+
for (p.value) |v| {
88+
var it = std.mem.splitScalar(u8, v, '=');
89+
const k0 = it.next();
90+
const v0 = it.next();
91+
if (k0 != null and v0 != null) {
92+
// put will copy all the memory of parameters
93+
try self.envs.put(k0.?, v0.?);
94+
}
95+
}
96+
}
8297
const r = try helper.readFile(self.allocator, "/etc/.z/command.json");
8398
if (r) |r1| {
8499
defer self.allocator.free(r1.b);
@@ -109,21 +124,6 @@ pub fn start(self: *Server) !void {
109124
thread.detach();
110125
}
111126
}
112-
const r2 = try helper.readFile(self.allocator, "/etc/.z/env.json");
113-
if (r2) |r1| {
114-
defer self.allocator.free(r1.b);
115-
const p = try std.json.parseFromSlice([][]u8, self.allocator, r1.b[0..r1.n], .{ .allocate = .alloc_always });
116-
defer p.deinit();
117-
for (p.value) |v| {
118-
var it = std.mem.splitScalar(u8, v, '=');
119-
const k0 = it.next();
120-
const v0 = it.next();
121-
if (k0 != null and v0 != null) {
122-
// put will copy all the memory of parameters
123-
try self.envs.put(k0.?, v0.?);
124-
}
125-
}
126-
}
127127
const addr = try std.net.Address.parseIp6("::1", 2);
128128
var s = try addr.listen(.{});
129129
defer s.deinit();

0 commit comments

Comments
 (0)