Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
327 changes: 327 additions & 0 deletions .agents/sow/done/SOW-0073-20261123-c-lookup-retry-request-buffer.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# SOW-0074 - test_uds EINTR wrapper on 64-bit glibc 2.41

## Status

Status: open

Sub-state: found during SOW-0073 validation; not started.

## Requirements

### Purpose

`test_uds` must build on every glibc the project supports.

### User Request

Tracked from SOW-0073 (found while validating on Debian 13, glibc 2.41, x86_64).

### Assistant Understanding

Facts:

- `tests/fixtures/c/uds_eintr_wrap.c` defines `__wrap___sendmsg64` and calls `__real___sendmsg64` under
`#if defined(__GLIBC__) && defined(__USE_TIME_BITS64)`; `CMakeLists.txt` links `test_uds` with
`--wrap=__sendmsg64` on every non-Apple platform.
- glibc 2.41 (`bits/features-time64.h`) defines `__USE_TIME_BITS64` whenever `__TIMESIZE == 64`, i.e. on every
64-bit target. `sys/socket.h` redirects `sendmsg` to `__sendmsg64` only under `__USE_TIME64_REDIRECTS` (32-bit
`time_t` targets built with `_TIME_BITS=64`).
- So on x86_64 glibc 2.41 the wrapper references `__sendmsg64`, which libc does not export:
`undefined reference to '__sendmsg64'`, and `test_uds` does not link (reproduced on 1ff116f1dc).

Inferences:

- The guard should follow the header's own condition (`__USE_TIME64_REDIRECTS`, falling back to `__TIMESIZE == 32`
with `__USE_TIME_BITS64` for glibc versions that predate that macro).

Unknowns:

- Which glibc version started defining `__USE_TIME_BITS64` on 64-bit targets (CI's Ubuntu glibc still links).

### Acceptance Criteria

- `test_uds` links and passes on x86_64 glibc 2.41 and on the 32-bit time64 targets of `tests/run-linux-target.sh`.

## Analysis

Sources checked:

- `tests/fixtures/c/uds_eintr_wrap.c`, `CMakeLists.txt` (`test_uds` link options), glibc 2.41 headers on Debian 13.

Current state:

- Test-only build failure; library code unaffected.

Risks:

- None for production; the EINTR injection tests do not run on affected hosts until fixed.

## Pre-Implementation Gate

Status: blocked

Not started: fill the gate before implementation.

## Implications And Decisions

None yet.

## Plan

1. Fix the guard; validate on glibc 2.41 x86_64 and a 32-bit time64 target.

## Execution Log

None yet.

## Validation

Pending.

## Outcome

Pending.

## Lessons Extracted

Pending.

## Followup

None yet.

## Regression Log

None yet.
6 changes: 6 additions & 0 deletions src/libnetdata/netipc/include/netipc/netipc_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ typedef struct {
/* Internal reusable Level 2 scratch, allocated lazily from session sizes. */
uint8_t *response_buf;
size_t response_buf_size;
/* SHM frame (header + request copy); a reconnect may resize it. */
uint8_t *send_buf;
size_t send_buf_size;
/* Encoded lookup request; an in-call retry resends it unchanged. */
uint8_t *request_buf;
size_t request_buf_size;
} nipc_client_ctx_t;

/* ------------------------------------------------------------------ */
Expand Down Expand Up @@ -505,6 +509,7 @@ typedef enum {
NIPC_WIN_SERVICE_TEST_FAULT_CACHE_ITEMS_CALLOC,
NIPC_WIN_SERVICE_TEST_FAULT_CACHE_ITEM_NAME_MALLOC,
NIPC_WIN_SERVICE_TEST_FAULT_CACHE_ITEM_PATH_MALLOC,
NIPC_WIN_SERVICE_TEST_FAULT_CLIENT_REQUEST_BUF_REALLOC,
} nipc_win_service_test_fault_site_t;

void nipc_win_service_test_fault_set(int site, uint32_t skip_matches);
Expand All @@ -524,6 +529,7 @@ typedef enum {
NIPC_POSIX_SERVICE_TEST_FAULT_CACHE_ITEMS_CALLOC,
NIPC_POSIX_SERVICE_TEST_FAULT_CACHE_ITEM_NAME_MALLOC,
NIPC_POSIX_SERVICE_TEST_FAULT_CACHE_ITEM_PATH_MALLOC,
NIPC_POSIX_SERVICE_TEST_FAULT_CLIENT_REQUEST_BUF_REALLOC,
} nipc_posix_service_test_fault_site_t;

void nipc_posix_service_test_fault_set(int site, uint32_t skip_matches);
Expand Down
8 changes: 4 additions & 4 deletions src/libnetdata/netipc/src/service/netipc_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ bool nipc_service_posix_ensure_buffer(uint8_t **buf, size_t *buf_size,
return true;
}

bool nipc_service_platform_ensure_client_send_buffer(nipc_client_ctx_t *ctx,
size_t need) {
bool nipc_service_platform_ensure_client_request_buffer(nipc_client_ctx_t *ctx,
size_t need) {
return nipc_service_posix_ensure_buffer(
&ctx->send_buf, &ctx->send_buf_size, need,
NIPC_POSIX_SERVICE_TEST_FAULT_CLIENT_SEND_BUF_REALLOC_INTERNAL);
&ctx->request_buf, &ctx->request_buf_size, need,
NIPC_POSIX_SERVICE_TEST_FAULT_CLIENT_REQUEST_BUF_REALLOC_INTERNAL);
}

bool nipc_service_platform_ensure_client_response_buffer(nipc_client_ctx_t *ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ static nipc_error_t do_apps_lookup_attempt(nipc_client_ctx_t *ctx,
goto cleanup;
}
/* next_request_count returns only sizes bounded by the uint32 transport cap. */
if (!nipc_service_platform_ensure_client_send_buffer(ctx, req_size)) {
if (!nipc_service_platform_ensure_client_request_buffer(ctx, req_size)) {
err = NIPC_ERR_OVERFLOW;
goto cleanup;
}

size_t req_len = nipc_apps_lookup_req_encode(
req_pids, req_count, ctx->send_buf, ctx->send_buf_size);
req_pids, req_count, ctx->request_buf, ctx->request_buf_size);
if (req_len == 0) {
err = NIPC_ERR_BAD_LAYOUT;
goto cleanup;
Expand All @@ -252,7 +252,7 @@ static nipc_error_t do_apps_lookup_attempt(nipc_client_ctx_t *ctx,
err = apps_lookup_remaining_timeout(ctx, s->deadline_ms, &timeout_ms);
if (err != NIPC_OK)
goto cleanup;
err = apps_lookup_do_raw_call_with_retry(ctx, ctx->send_buf, req_len,
err = apps_lookup_do_raw_call_with_retry(ctx, ctx->request_buf, req_len,
&payload, &payload_len,
timeout_ms);
if (err != NIPC_OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ static nipc_error_t do_cgroups_lookup_attempt(nipc_client_ctx_t *ctx,
goto cleanup;
}
/* next_request_count returns only sizes bounded by the uint32 transport cap. */
if (!nipc_service_platform_ensure_client_send_buffer(ctx, req_size)) {
if (!nipc_service_platform_ensure_client_request_buffer(ctx, req_size)) {
err = NIPC_ERR_OVERFLOW;
goto cleanup;
}

size_t req_len = nipc_cgroups_lookup_req_encode(
req_paths, req_count, ctx->send_buf, ctx->send_buf_size);
req_paths, req_count, ctx->request_buf, ctx->request_buf_size);
if (req_len == 0) {
err = NIPC_ERR_BAD_LAYOUT;
goto cleanup;
Expand All @@ -347,7 +347,7 @@ static nipc_error_t do_cgroups_lookup_attempt(nipc_client_ctx_t *ctx,
err = cgroups_lookup_remaining_timeout(ctx, s->deadline_ms, &timeout_ms);
if (err != NIPC_OK)
goto cleanup;
err = cgroups_lookup_do_raw_call_with_retry(ctx, ctx->send_buf, req_len,
err = cgroups_lookup_do_raw_call_with_retry(ctx, ctx->request_buf, req_len,
&payload, &payload_len,
timeout_ms);
if (err != NIPC_OK)
Expand Down
7 changes: 6 additions & 1 deletion src/libnetdata/netipc/src/service/netipc_service_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,13 @@ void nipc_service_common_client_status(const nipc_client_ctx_t *ctx,
void nipc_service_common_client_close_buffers(nipc_client_ctx_t *ctx) {
free(ctx->response_buf);
free(ctx->send_buf);
free(ctx->request_buf);
ctx->response_buf = NULL;
ctx->send_buf = NULL;
ctx->request_buf = NULL;
ctx->response_buf_size = 0;
ctx->send_buf_size = 0;
ctx->request_buf_size = 0;
ctx->state = NIPC_CLIENT_DISCONNECTED;
}

Expand Down Expand Up @@ -287,8 +290,10 @@ nipc_error_t nipc_service_common_client_prepare_shm_request(
if (!msg || msg_len > ctx->send_buf_size)
return NIPC_ERR_OVERFLOW;

/* The payload lives outside send_buf, so an in-call retry, which may
* reconnect and resize send_buf, resends it unchanged. */
if (payload_len > 0)
memmove(msg + NIPC_HEADER_LEN, payload, payload_len);
memcpy(msg + NIPC_HEADER_LEN, payload, payload_len);

hdr->magic = NIPC_MAGIC_MSG;
hdr->version = NIPC_VERSION;
Expand Down
4 changes: 2 additions & 2 deletions src/libnetdata/netipc/src/service/netipc_service_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void *nipc_service_platform_malloc(size_t size, int fault_site);
void *nipc_service_platform_calloc(size_t count, size_t size, int fault_site);
uint64_t nipc_service_platform_monotonic_ms(void);

bool nipc_service_platform_ensure_client_send_buffer(nipc_client_ctx_t *ctx,
size_t need);
bool nipc_service_platform_ensure_client_request_buffer(nipc_client_ctx_t *ctx,
size_t need);
bool nipc_service_platform_ensure_client_response_buffer(nipc_client_ctx_t *ctx,
size_t need);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum {
NIPC_POSIX_SERVICE_TEST_FAULT_CACHE_ITEMS_CALLOC_INTERNAL,
NIPC_POSIX_SERVICE_TEST_FAULT_CACHE_ITEM_NAME_MALLOC_INTERNAL,
NIPC_POSIX_SERVICE_TEST_FAULT_CACHE_ITEM_PATH_MALLOC_INTERNAL,
NIPC_POSIX_SERVICE_TEST_FAULT_CLIENT_REQUEST_BUF_REALLOC_INTERNAL,
};

void nipc_service_posix_sleep_us(unsigned int usec);
Expand Down
8 changes: 4 additions & 4 deletions src/libnetdata/netipc/src/service/netipc_service_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ uint64_t nipc_service_platform_monotonic_ms(void) {
return monotonic_time_ms();
}

bool nipc_service_platform_ensure_client_send_buffer(nipc_client_ctx_t *ctx,
size_t need) {
bool nipc_service_platform_ensure_client_request_buffer(nipc_client_ctx_t *ctx,
size_t need) {
return nipc_service_win_ensure_buffer(
&ctx->send_buf, &ctx->send_buf_size, need,
NIPC_WIN_SERVICE_TEST_FAULT_CLIENT_SEND_BUF_REALLOC_INTERNAL);
&ctx->request_buf, &ctx->request_buf_size, need,
NIPC_WIN_SERVICE_TEST_FAULT_CLIENT_REQUEST_BUF_REALLOC_INTERNAL);
}

bool nipc_service_platform_ensure_client_response_buffer(nipc_client_ctx_t *ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum {
NIPC_WIN_SERVICE_TEST_FAULT_CACHE_ITEMS_CALLOC_INTERNAL,
NIPC_WIN_SERVICE_TEST_FAULT_CACHE_ITEM_NAME_MALLOC_INTERNAL,
NIPC_WIN_SERVICE_TEST_FAULT_CACHE_ITEM_PATH_MALLOC_INTERNAL,
NIPC_WIN_SERVICE_TEST_FAULT_CLIENT_REQUEST_BUF_REALLOC_INTERNAL,
};

const nipc_service_common_client_ops_t *nipc_service_win_client_ops(void);
Expand Down
Loading
Loading