| 2493 | } |
| 2494 | |
| 2495 | cbm_daemon_runtime_service_t *cbm_daemon_runtime_service_start( |
| 2496 | const cbm_daemon_runtime_service_config_t *config) { |
| 2497 | if (!config || !config->endpoint) { |
| 2498 | return NULL; |
| 2499 | } |
| 2500 | cbm_daemon_ipc_startup_lock_t *startup_lock = NULL; |
| 2501 | if (cbm_daemon_ipc_startup_lock_try_acquire(config->endpoint, &startup_lock) != 1) { |
| 2502 | return NULL; |
| 2503 | } |
| 2504 | int generation = |
| 2505 | cbm_daemon_ipc_generation_probe_under_startup_lock(config->endpoint, startup_lock); |
| 2506 | if (generation != 0 || !cbm_daemon_ipc_startup_lock_prepare_handoff(startup_lock)) { |
| 2507 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2508 | return NULL; |
| 2509 | } |
| 2510 | cbm_daemon_ipc_participant_guard_t *participant_guard = NULL; |
| 2511 | if (cbm_daemon_ipc_participant_guard_try_join(config->endpoint, &participant_guard) != 1) { |
| 2512 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2513 | return NULL; |
| 2514 | } |
| 2515 | cbm_daemon_ipc_lifetime_reservation_t *reservation = NULL; |
| 2516 | if (cbm_daemon_ipc_lifetime_reservation_try_acquire(config->endpoint, &reservation) != 1) { |
| 2517 | if (!runtime_participant_guard_release_complete(&participant_guard, |
| 2518 | config->shutdown_timeout_ms)) { |
| 2519 | runtime_cleanup_fail_stop("participant_guard_cleanup"); |
| 2520 | } |
| 2521 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2522 | return NULL; |
| 2523 | } |
| 2524 | cbm_daemon_runtime_service_t *service = |
| 2525 | cbm_daemon_runtime_service_start_reserved(config, &reservation); |
| 2526 | cbm_daemon_ipc_lifetime_reservation_release(reservation); |
| 2527 | if (!service) { |
| 2528 | if (!runtime_participant_guard_release_complete(&participant_guard, |
| 2529 | config->shutdown_timeout_ms)) { |
| 2530 | runtime_cleanup_fail_stop("participant_guard_cleanup"); |
| 2531 | } |
| 2532 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2533 | return NULL; |
| 2534 | } |
| 2535 | service->owned_participant_guard = participant_guard; |
| 2536 | runtime_startup_lock_release_complete(&startup_lock, config->shutdown_timeout_ms); |
| 2537 | return service; |
| 2538 | } |
| 2539 | |
| 2540 | cbm_daemon_runtime_service_state_t cbm_daemon_runtime_service_state( |
| 2541 | cbm_daemon_runtime_service_t *service) { |