Skip to content

Commit 8643a67

Browse files
committed
Add bootstrap logs for lock/resolve
1 parent 21baacf commit 8643a67

2 files changed

Lines changed: 170 additions & 0 deletions

File tree

src/lock.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,44 @@
11
#include <fs.h>
22
#include <path.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
35
#include <string.h>
46
#include <uv.h>
57

68
#include "../include/appling.h"
79

10+
static void
11+
appling__bootstrap_log(const char *tag, const char *detail) {
12+
const char *log_path = getenv("PEAR_BOOTSTRAP_LOG");
13+
if (!log_path || !log_path[0]) return;
14+
15+
FILE *fp = fopen(log_path, "a");
16+
if (!fp) return;
17+
18+
fprintf(fp, "[%llu] %s: %s\n",
19+
(unsigned long long) uv_hrtime(),
20+
tag ? tag : "(null)",
21+
detail ? detail : ""
22+
);
23+
24+
fclose(fp);
25+
}
26+
827
static void
928
appling_lock__on_close(fs_close_t *fs_req, int status) {
1029
appling_lock_t *req = (appling_lock_t *) fs_req->data;
1130

31+
if (!req) {
32+
appling__bootstrap_log("lock-close", "req-null");
33+
return;
34+
}
35+
36+
{
37+
char buf[128];
38+
snprintf(buf, sizeof(buf), "status=%d", status);
39+
appling__bootstrap_log("lock-close", buf);
40+
}
41+
1242
if (req->status < 0) status = req->status;
1343

1444
if (status >= 0) {
@@ -22,6 +52,17 @@ static void
2252
appling_lock__on_lock(fs_lock_t *fs_req, int status) {
2353
appling_lock_t *req = (appling_lock_t *) fs_req->data;
2454

55+
if (!req) {
56+
appling__bootstrap_log("lock-lock", "req-null");
57+
return;
58+
}
59+
60+
{
61+
char buf[128];
62+
snprintf(buf, sizeof(buf), "status=%d", status);
63+
appling__bootstrap_log("lock-lock", buf);
64+
}
65+
2566
if (status >= 0) {
2667
if (req->on_lock) req->on_lock(req, 0);
2768
} else {
@@ -35,6 +76,17 @@ static void
3576
appling_lock__on_open(fs_open_t *fs_req, int status, uv_file file) {
3677
appling_lock_t *req = (appling_lock_t *) fs_req->data;
3778

79+
if (!req) {
80+
appling__bootstrap_log("lock-open", "req-null");
81+
return;
82+
}
83+
84+
{
85+
char buf[128];
86+
snprintf(buf, sizeof(buf), "status=%d", status);
87+
appling__bootstrap_log("lock-open", buf);
88+
}
89+
3890
if (status >= 0) {
3991
req->file = file;
4092

@@ -48,6 +100,17 @@ static void
48100
appling_lock__on_mkdir(fs_mkdir_t *fs_req, int status) {
49101
appling_lock_t *req = (appling_lock_t *) fs_req->data;
50102

103+
if (!req) {
104+
appling__bootstrap_log("lock-mkdir", "req-null");
105+
return;
106+
}
107+
108+
{
109+
char buf[256];
110+
snprintf(buf, sizeof(buf), "status=%d dir=%s", status, req->dir);
111+
appling__bootstrap_log("lock-mkdir", buf);
112+
}
113+
51114
appling_path_t path;
52115
size_t path_len = sizeof(appling_path_t);
53116

@@ -110,5 +173,17 @@ appling_lock(uv_loop_t *loop, appling_lock_t *req, const char *dir, appling_lock
110173
);
111174
}
112175

176+
appling__bootstrap_log("lock-dir", req->dir);
177+
{
178+
uv_fs_t stat_req;
179+
int stat_rc = uv_fs_stat(loop, &stat_req, req->dir, NULL);
180+
if (stat_rc < 0) {
181+
char buf[256];
182+
snprintf(buf, sizeof(buf), "missing(%d) %s", stat_rc, req->dir);
183+
appling__bootstrap_log("lock-dir-missing", buf);
184+
}
185+
uv_fs_req_cleanup(&stat_req);
186+
}
187+
113188
return fs_mkdir(req->loop, &req->mkdir, req->dir, 0777, true, appling_lock__on_mkdir);
114189
}

src/resolve.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,41 @@
1010

1111
#include "../include/appling.h"
1212

13+
static void
14+
appling__bootstrap_log(const char *tag, const char *detail) {
15+
const char *log_path = getenv("PEAR_BOOTSTRAP_LOG");
16+
if (!log_path || !log_path[0]) return;
17+
18+
FILE *fp = fopen(log_path, "a");
19+
if (!fp) return;
20+
21+
fprintf(fp, "[%llu] %s: %s\n",
22+
(unsigned long long) uv_hrtime(),
23+
tag ? tag : "(null)",
24+
detail ? detail : ""
25+
);
26+
27+
fclose(fp);
28+
}
29+
1330
static void
1431
appling_resolve__realpath(appling_resolve_t *req);
1532

1633
static void
1734
appling_resolve__on_close(fs_close_t *fs_req, int status) {
1835
appling_resolve_t *req = (appling_resolve_t *) fs_req->data;
1936

37+
if (!req) {
38+
appling__bootstrap_log("resolve-close", "req-null");
39+
return;
40+
}
41+
42+
{
43+
char buf[128];
44+
snprintf(buf, sizeof(buf), "status=%d", status);
45+
appling__bootstrap_log("resolve-close", buf);
46+
}
47+
2048
if (req->status < 0) status = req->status;
2149

2250
if (status >= 0) {
@@ -35,6 +63,11 @@ appling_resolve__on_read(fs_read_t *fs_req, int status, size_t read) {
3563

3664
appling_resolve_t *req = (appling_resolve_t *) fs_req->data;
3765

66+
if (!req) {
67+
appling__bootstrap_log("resolve-read", "req-null");
68+
return;
69+
}
70+
3871
if (status >= 0) {
3972
compact_state_t state = {
4073
0,
@@ -106,6 +139,11 @@ appling_resolve__on_read(fs_read_t *fs_req, int status, size_t read) {
106139

107140
req->status = 0; // Reset
108141
} else {
142+
{
143+
char buf[128];
144+
snprintf(buf, sizeof(buf), "status=%d", status);
145+
appling__bootstrap_log("resolve-read", buf);
146+
}
109147
req->status = status; // Propagate
110148
}
111149

@@ -119,13 +157,23 @@ static void
119157
appling_resolve__on_stat(fs_stat_t *fs_req, int status, const uv_stat_t *stat) {
120158
appling_resolve_t *req = (appling_resolve_t *) fs_req->data;
121159

160+
if (!req) {
161+
appling__bootstrap_log("resolve-stat", "req-null");
162+
return;
163+
}
164+
122165
if (status >= 0) {
123166
size_t len = stat->st_size;
124167

125168
req->buf = uv_buf_init(malloc(len), len);
126169

127170
fs_read(req->loop, &req->read, req->file, &req->buf, 1, 0, appling_resolve__on_read);
128171
} else {
172+
{
173+
char buf[128];
174+
snprintf(buf, sizeof(buf), "status=%d", status);
175+
appling__bootstrap_log("resolve-stat", buf);
176+
}
129177
req->status = status; // Propagate
130178

131179
fs_close(req->loop, &req->close, req->file, appling_resolve__on_close);
@@ -136,11 +184,29 @@ static void
136184
appling_resolve__on_open(fs_open_t *fs_req, int status, uv_file file) {
137185
appling_resolve_t *req = (appling_resolve_t *) fs_req->data;
138186

187+
if (!req) {
188+
appling__bootstrap_log("resolve-open", "req-null");
189+
return;
190+
}
191+
139192
if (status >= 0) {
140193
req->file = file;
141194

142195
fs_stat(req->loop, &req->stat, req->file, appling_resolve__on_stat);
143196
} else {
197+
appling_path_t path;
198+
size_t path_len = sizeof(appling_path_t);
199+
path_join(
200+
(const char *[]) {req->platform->path, "..", "..", "checkout", NULL},
201+
path,
202+
&path_len,
203+
path_behavior_system
204+
);
205+
{
206+
char buf[256];
207+
snprintf(buf, sizeof(buf), "status=%d path=%s", status, path);
208+
appling__bootstrap_log("resolve-open", buf);
209+
}
144210
if (req->cb) req->cb(req, status);
145211
}
146212
}
@@ -166,11 +232,32 @@ static void
166232
appling_resolve__on_realpath(fs_realpath_t *fs_req, int status, const char *path) {
167233
appling_resolve_t *req = (appling_resolve_t *) fs_req->data;
168234

235+
if (!req) {
236+
appling__bootstrap_log("resolve-realpath", "req-null");
237+
return;
238+
}
239+
169240
if (status >= 0) {
170241
strcpy(req->platform->path, path);
171242

172243
appling_resolve__open(req);
173244
} else {
245+
{
246+
appling_path_t candidate_path;
247+
size_t candidate_len = sizeof(appling_path_t);
248+
size_t i = req->candidate;
249+
if (appling_platform_candidates[i]) {
250+
path_join(
251+
(const char *[]) {req->path, appling_platform_candidates[i], NULL},
252+
candidate_path,
253+
&candidate_len,
254+
path_behavior_system
255+
);
256+
char buf[256];
257+
snprintf(buf, sizeof(buf), "status=%d path=%s", status, candidate_path);
258+
appling__bootstrap_log("resolve-realpath", buf);
259+
}
260+
}
174261
size_t i = ++req->candidate;
175262

176263
if (appling_platform_candidates[i]) appling_resolve__realpath(req);
@@ -192,6 +279,12 @@ appling_resolve__realpath(appling_resolve_t *req) {
192279
path_behavior_system
193280
);
194281

282+
{
283+
char buf[256];
284+
snprintf(buf, sizeof(buf), "candidate=%zu path=%s", i, path);
285+
appling__bootstrap_log("resolve-candidate", buf);
286+
}
287+
195288
log_debug("appling_resolve() accessing platform at %s", path);
196289

197290
fs_realpath(req->loop, &req->realpath, path, appling_resolve__on_realpath);
@@ -245,6 +338,8 @@ appling_resolve(uv_loop_t *loop, appling_resolve_t *req, const char *dir, applin
245338
);
246339
}
247340

341+
appling__bootstrap_log("resolve-root", req->path);
342+
248343
appling_resolve__realpath(req);
249344

250345
return 0;

0 commit comments

Comments
 (0)