@@ -119,6 +119,47 @@ cbm_daemon_bootstrap_probe_status_t cbm_daemon_bootstrap_classify_failed_connect
119119typedef void * cbm_daemon_bootstrap_lock_t ;
120120typedef void * cbm_daemon_bootstrap_cohort_t ;
121121
122+ /* Durable daemon start-failure record (#1828). A detached daemon has no
123+ * stderr and no channel back to the client that launched it; when its
124+ * listener publication fails (a full /tmp, for instance) the client used to
125+ * respawn it for the whole startup deadline and then report "active or
126+ * starting". The host now appends one record per failed start to
127+ * <cache>/logs/cbm-daemon.start-failures.log -- the same owner-only log
128+ * directory as cbm-daemon.log, deliberately NOT the runtime directory: that
129+ * one is exactly what a full /tmp cannot write, and a new artifact there
130+ * would entangle stale-generation cleanup. A waiting client reads the newest
131+ * record for its endpoint that is not older than its own spawn and fails
132+ * immediately with the cause. Diagnostic only: policy never reads it. */
133+ enum { CBM_DAEMON_BOOTSTRAP_COMPONENT_CAP = 32 };
134+ typedef struct {
135+ uint64_t recorded_at_s ; /* wall clock, seconds */
136+ uint64_t pid ;
137+ char component [CBM_DAEMON_BOOTSTRAP_COMPONENT_CAP ]; /* host component that refused */
138+ char stage [CBM_DAEMON_IPC_LISTEN_FAILURE_STAGE_CAP ]; /* IPC stage, "" when none */
139+ int errno_value ; /* 0 when unknown */
140+ char path [CBM_DAEMON_IPC_LISTEN_FAILURE_PATH_CAP ]; /* "" when none */
141+ } cbm_daemon_bootstrap_start_failure_t ;
142+
143+ /* <cache>/logs, the owner-only directory that holds every daemon log. */
144+ bool cbm_daemon_bootstrap_log_directory (char * out , size_t capacity );
145+ /* Append one record for this process's most recent listener failure detail
146+ * (cbm_daemon_ipc_listen_failure_detail) under `component`. */
147+ bool cbm_daemon_bootstrap_start_failure_record (const char * log_directory ,
148+ const cbm_daemon_ipc_endpoint_t * endpoint ,
149+ const char * component );
150+ /* Newest record for `endpoint` recorded at or after not_before_s. Returns 1
151+ * and fills out_failure, 0 when none matches, -1 when the log directory or
152+ * file cannot be validated. */
153+ int cbm_daemon_bootstrap_start_failure_read (const char * log_directory ,
154+ const cbm_daemon_ipc_endpoint_t * endpoint ,
155+ uint64_t not_before_s ,
156+ cbm_daemon_bootstrap_start_failure_t * out_failure );
157+ /* The client-facing sentence: "CBM daemon failed to start: <stage> failed
158+ * with ENOSPC (No space left on device) at <path>; see <log>". */
159+ void cbm_daemon_bootstrap_start_failure_format (const cbm_daemon_bootstrap_start_failure_t * failure ,
160+ const char * log_directory , char * out ,
161+ size_t capacity );
162+
122163/* Injectable OS/runtime boundary used by the deterministic unit contract.
123164 * Production callers use cbm_daemon_bootstrap_execute(), whose built-in
124165 * operations delegate to daemon IPC/runtime and write visible diagnostics to
@@ -149,13 +190,30 @@ typedef struct {
149190 bool (* startup_lock_release )(void * context , cbm_daemon_bootstrap_lock_t * lock_io );
150191 bool (* spawn_daemon )(void * context , const cbm_daemon_bootstrap_launch_spec_t * spec );
151192 void (* visible_diagnostic )(void * context , const char * message );
193+ /* Optional. After this attempt spawned a daemon, report a start-failure
194+ * record for the endpoint not older than not_before_s (1 found, 0 none,
195+ * -1 unreadable). A found record ends the wait immediately (#1828). */
196+ int (* start_failure_probe )(void * context , const cbm_daemon_ipc_endpoint_t * endpoint ,
197+ uint64_t not_before_s ,
198+ cbm_daemon_bootstrap_start_failure_t * out_failure );
152199} cbm_daemon_bootstrap_ops_t ;
153200
154201cbm_daemon_bootstrap_status_t cbm_daemon_bootstrap_execute (
155202 const cbm_daemon_bootstrap_config_t * config , cbm_daemon_bootstrap_result_t * result_out );
156203
157204/* Test seam for the same state machine. All callbacks are synchronous and
158205 * borrowed for the duration of the call. */
206+ #ifdef CBM_ENABLE_TEST_SEAMS
207+ /* Replace ONLY the production spawn while every other production operation
208+ * (cohort, probe, startup lock, handoff) stays real. A test forks a real
209+ * daemon host in place of exec'ing the product binary, so the complete
210+ * client/daemon rendezvous runs in one deterministic process tree (#1828). */
211+ typedef bool (* cbm_daemon_bootstrap_spawn_fn )(void * context ,
212+ const cbm_daemon_bootstrap_launch_spec_t * spec );
213+ void cbm_daemon_bootstrap_spawn_override_set_for_test (cbm_daemon_bootstrap_spawn_fn spawn ,
214+ void * context );
215+ #endif
216+
159217cbm_daemon_bootstrap_status_t cbm_daemon_bootstrap_execute_with_ops (
160218 const cbm_daemon_bootstrap_config_t * config , const cbm_daemon_bootstrap_ops_t * ops ,
161219 cbm_daemon_bootstrap_result_t * result_out );
0 commit comments