| 2313 | } |
| 2314 | |
| 2315 | cbm_daemon_runtime_service_t *cbm_daemon_runtime_service_start( |
| 2316 | const cbm_daemon_runtime_service_config_t *config) { |
| 2317 | if (!config || !config->endpoint) { |
| 2318 | return NULL; |
| 2319 | } |
| 2320 | cbm_daemon_ipc_startup_lock_t *startup_lock = NULL; |
| 2321 | if (cbm_daemon_ipc_startup_lock_try_acquire(config->endpoint, &startup_lock) != 1) { |
| 2322 | return NULL; |
| 2323 | } |
| 2324 | int generation = |
| 2325 | cbm_daemon_ipc_generation_probe_under_startup_lock(config->endpoint, startup_lock); |
| 2326 | if (generation != 0 || !cbm_daemon_ipc_startup_lock_prepare_handoff(startup_lock)) { |
| 2327 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2328 | return NULL; |
| 2329 | } |
| 2330 | cbm_daemon_ipc_participant_guard_t *participant_guard = NULL; |
| 2331 | if (cbm_daemon_ipc_participant_guard_try_join(config->endpoint, &participant_guard) != 1) { |
| 2332 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2333 | return NULL; |
| 2334 | } |
| 2335 | cbm_daemon_ipc_lifetime_reservation_t *reservation = NULL; |
| 2336 | if (cbm_daemon_ipc_lifetime_reservation_try_acquire(config->endpoint, &reservation) != 1) { |
| 2337 | if (!runtime_participant_guard_release_complete(&participant_guard, |
| 2338 | config->shutdown_timeout_ms)) { |
| 2339 | runtime_cleanup_fail_stop("participant_guard_cleanup"); |
| 2340 | } |
| 2341 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2342 | return NULL; |
| 2343 | } |
| 2344 | cbm_daemon_runtime_service_t *service = |
| 2345 | cbm_daemon_runtime_service_start_reserved(config, &reservation); |
| 2346 | cbm_daemon_ipc_lifetime_reservation_release(reservation); |
| 2347 | if (!service) { |
| 2348 | if (!runtime_participant_guard_release_complete(&participant_guard, |
| 2349 | config->shutdown_timeout_ms)) { |
| 2350 | runtime_cleanup_fail_stop("participant_guard_cleanup"); |
| 2351 | } |
| 2352 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2353 | return NULL; |
| 2354 | } |
| 2355 | service->owned_participant_guard = participant_guard; |
| 2356 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2357 | return service; |
| 2358 | } |
| 2359 | |
| 2360 | cbm_daemon_runtime_service_state_t cbm_daemon_runtime_service_state( |
| 2361 | cbm_daemon_runtime_service_t *service) { |