diag: PMM_DEBUG logging in http_get/curl_capture/install_from_registry to trace Linux mirror lookup

这个提交包含在:
JGZYES
2026-09-01 18:45:46 +08:00
父节点 f74ed27f8f
当前提交 f2178bd652
修改 2 个文件,包含 8 行新增0 行删除
+6
查看文件
@@ -45,6 +45,7 @@ static char *run_capture(const char *cmd, size_t *out_len) {
if (n == 0) break;
}
int rc = PMM_PCLOSE(f);
if (getenv("PMM_DEBUG")) fprintf(stderr, "[http] pclose rc=%d len=%zu\n", rc, len);
if (rc != 0 && len == 0) { free(buf); return NULL; }
if (out_len) *out_len = len;
buf[len] = '\0';
@@ -66,6 +67,7 @@ static char *curl_capture(const char *args, const char *url, size_t *out_len) {
}
*p++ = '"';
*p = '\0';
if (getenv("PMM_DEBUG")) fprintf(stderr, "[http] cmd: %s\n", cmd);
char *res = run_capture(cmd, out_len);
free(cmd);
return res;
@@ -75,7 +77,10 @@ char *http_get(const char *url, int *status) {
/* The status marker has NO backslash/newline, so it's immune to shell
* interpretation differences: body + "__PMM_HTTP_<code>" */
size_t len = 0;
if (getenv("PMM_DEBUG")) fprintf(stderr, "[http] GET %s\n", url);
char *body = curl_capture("-sSL --max-time 60 -w __PMM_HTTP_%{http_code}", url, &len);
if (getenv("PMM_DEBUG")) fprintf(stderr, "[http] captured len=%zu head=%.60s\n",
body ? len : 0, body ? body : "(null)");
if (!body) return NULL;
/* find the LAST marker occurrence, take the digits after it */
const char *mk = "__PMM_HTTP_";
@@ -91,6 +96,7 @@ char *http_get(const char *url, int *status) {
return NULL;
}
if (status) *status = code;
if (getenv("PMM_DEBUG")) fprintf(stderr, "[http] status=%d\n", code);
} else {
/* no marker (some curl/quirk): keep body, status unknown -> later logic
* in install accepts non-404 bodies */
+2
查看文件
@@ -357,6 +357,8 @@ int install_from_registry(const char *name, const char *spec, const char *mirror
snprintf(url, sizeof(url), "%s/%s.json", bases[i], name);
printf("pmm: looking up %s in mirror %s\n", name, bases[i]);
body = http_get(url, &status);
if (getenv("PMM_DEBUG")) fprintf(stderr, "[reg] %s -> body=%s status=%d\n",
bases[i], body ? "set" : "NULL", status);
/* accept any body that isn't an explicit not-found/server error; some
* curl builds don't emit the status marker the way we expect, so a
* non-NULL body with an indeterminate status should still be parsed */