|
31 | 31 | CBM_DAEMON_IPC_RETRY_INTERVAL_MS = 10, |
32 | 32 | CBM_DAEMON_IPC_COORDINATION_CLEANUP_MS = 500, |
33 | 33 | CBM_DAEMON_IPC_WINDOWS_RENDEZVOUS_RETRY_MS = 250, |
| 34 | + CBM_DAEMON_IPC_RELEASE_ERROR = -1, |
| 35 | + CBM_DAEMON_IPC_RELEASE_COMPLETE = 1, |
34 | 36 | }; |
35 | 37 |
|
36 | 38 | /* Last private-namespace validation refusal, set at the exact failing check. |
@@ -3988,27 +3990,27 @@ bool cbm_daemon_ipc_local_transition_begin_work(cbm_daemon_ipc_local_transition_ |
3988 | 3990 | return true; |
3989 | 3991 | } |
3990 | 3992 |
|
3991 | | -bool cbm_daemon_ipc_local_transition_release(cbm_daemon_ipc_local_transition_t **transition_io) { |
| 3993 | +int cbm_daemon_ipc_local_transition_try_release(cbm_daemon_ipc_local_transition_t **transition_io) { |
3992 | 3994 | if (!transition_io) { |
3993 | | - return false; |
| 3995 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
3994 | 3996 | } |
3995 | 3997 | cbm_daemon_ipc_local_transition_t *transition = *transition_io; |
3996 | 3998 | if (!transition) { |
3997 | | - return true; |
| 3999 | + return CBM_DAEMON_IPC_RELEASE_COMPLETE; |
3998 | 4000 | } |
3999 | 4001 | if (transition->legacy_fd < 0 || !transition->legacy_process_entry || |
4000 | 4002 | transition->owner_pid != getpid() || |
4001 | 4003 | (!transition->work_begun && |
4002 | 4004 | (transition->startup_v2_fd < 0 || !transition->startup_v2_process_entry))) { |
4003 | | - return false; |
| 4005 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
4004 | 4006 | } |
4005 | 4007 | posix_named_lock_release(transition->legacy_fd, transition->legacy_process_entry); |
4006 | 4008 | if (!transition->work_begun) { |
4007 | 4009 | posix_named_lock_release(transition->startup_v2_fd, transition->startup_v2_process_entry); |
4008 | 4010 | } |
4009 | 4011 | free(transition); |
4010 | 4012 | *transition_io = NULL; |
4011 | | - return true; |
| 4013 | + return CBM_DAEMON_IPC_RELEASE_COMPLETE; |
4012 | 4014 | } |
4013 | 4015 |
|
4014 | 4016 | #else /* _WIN32 */ |
@@ -6203,35 +6205,39 @@ static void win_participant_group_release_complete(cbm_private_file_lock_t **gro |
6203 | 6205 | } |
6204 | 6206 | } |
6205 | 6207 |
|
6206 | | -static bool win_participant_state_release(const cbm_daemon_ipc_endpoint_t *endpoint, |
6207 | | - cbm_private_lock_directory_t *directory, |
6208 | | - cbm_private_file_lock_t **startup_v2_io, |
6209 | | - win_legacy_mutex_guard_t **legacy_guard_io, |
6210 | | - cbm_private_file_lock_t **group_io, HANDLE *sentinel_io) { |
| 6208 | +static int win_participant_state_release(const cbm_daemon_ipc_endpoint_t *endpoint, |
| 6209 | + cbm_private_lock_directory_t *directory, |
| 6210 | + cbm_private_file_lock_t **startup_v2_io, |
| 6211 | + win_legacy_mutex_guard_t **legacy_guard_io, |
| 6212 | + cbm_private_file_lock_t **group_io, HANDLE *sentinel_io) { |
6211 | 6213 | if (!endpoint || !directory || !startup_v2_io || !legacy_guard_io || !group_io || |
6212 | 6214 | !sentinel_io) { |
6213 | | - return false; |
| 6215 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
6214 | 6216 | } |
6215 | 6217 | if (!*startup_v2_io) { |
6216 | 6218 | int startup = win_startup_v2_try_acquire(directory, startup_v2_io); |
6217 | 6219 | if (startup != 1) { |
6218 | | - return false; |
| 6220 | + return startup; |
6219 | 6221 | } |
6220 | 6222 | } |
6221 | 6223 | if (!*legacy_guard_io) { |
6222 | 6224 | int legacy = win_legacy_mutex_guard_try_acquire(endpoint, legacy_guard_io); |
6223 | 6225 | if (legacy != 1) { |
6224 | | - (void)cbm_private_file_lock_release(startup_v2_io); |
6225 | | - return false; |
| 6226 | + if (cbm_private_file_lock_release(startup_v2_io) != CBM_PRIVATE_FILE_LOCK_OK) { |
| 6227 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
| 6228 | + } |
| 6229 | + return legacy; |
6226 | 6230 | } |
6227 | 6231 | } |
6228 | 6232 | if (!win_participant_group_release_locked(group_io, sentinel_io)) { |
6229 | | - return false; |
| 6233 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
6230 | 6234 | } |
6231 | 6235 | if (!win_legacy_mutex_guard_release(legacy_guard_io)) { |
6232 | | - return false; |
| 6236 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
6233 | 6237 | } |
6234 | | - return cbm_private_file_lock_release(startup_v2_io) == CBM_PRIVATE_FILE_LOCK_OK; |
| 6238 | + return cbm_private_file_lock_release(startup_v2_io) == CBM_PRIVATE_FILE_LOCK_OK |
| 6239 | + ? CBM_DAEMON_IPC_RELEASE_COMPLETE |
| 6240 | + : CBM_DAEMON_IPC_RELEASE_ERROR; |
6235 | 6241 | } |
6236 | 6242 |
|
6237 | 6243 | cbm_daemon_ipc_listener_t *cbm_daemon_ipc_listen_reserved( |
@@ -7007,9 +7013,9 @@ bool cbm_daemon_ipc_startup_lock_release(cbm_daemon_ipc_startup_lock_t **lock_io |
7007 | 7013 | if (!lock) { |
7008 | 7014 | return true; |
7009 | 7015 | } |
7010 | | - if (!win_participant_state_release(lock->endpoint, lock->directory, &lock->startup_v2_lock, |
7011 | | - &lock->legacy_guard, &lock->group_lock, |
7012 | | - &lock->legacy_sentinel)) { |
| 7016 | + if (win_participant_state_release(lock->endpoint, lock->directory, &lock->startup_v2_lock, |
| 7017 | + &lock->legacy_guard, &lock->group_lock, |
| 7018 | + &lock->legacy_sentinel) != CBM_DAEMON_IPC_RELEASE_COMPLETE) { |
7013 | 7019 | return false; |
7014 | 7020 | } |
7015 | 7021 | cbm_private_lock_directory_close(lock->directory); |
@@ -7072,9 +7078,10 @@ bool cbm_daemon_ipc_participant_guard_release(cbm_daemon_ipc_participant_guard_t |
7072 | 7078 | if (!guard) { |
7073 | 7079 | return true; |
7074 | 7080 | } |
7075 | | - if (!win_participant_state_release( |
7076 | | - guard->endpoint, guard->directory, &guard->teardown_startup_v2_lock, |
7077 | | - &guard->teardown_legacy_guard, &guard->group_lock, &guard->legacy_sentinel)) { |
| 7081 | + if (win_participant_state_release(guard->endpoint, guard->directory, |
| 7082 | + &guard->teardown_startup_v2_lock, |
| 7083 | + &guard->teardown_legacy_guard, &guard->group_lock, |
| 7084 | + &guard->legacy_sentinel) != CBM_DAEMON_IPC_RELEASE_COMPLETE) { |
7078 | 7085 | return false; |
7079 | 7086 | } |
7080 | 7087 | cbm_private_lock_directory_close(guard->directory); |
@@ -7169,39 +7176,45 @@ bool cbm_daemon_ipc_local_transition_begin_work(cbm_daemon_ipc_local_transition_ |
7169 | 7176 | return true; |
7170 | 7177 | } |
7171 | 7178 |
|
7172 | | -bool cbm_daemon_ipc_local_transition_release(cbm_daemon_ipc_local_transition_t **transition_io) { |
| 7179 | +int cbm_daemon_ipc_local_transition_try_release(cbm_daemon_ipc_local_transition_t **transition_io) { |
7173 | 7180 | if (!transition_io) { |
7174 | | - return false; |
| 7181 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
7175 | 7182 | } |
7176 | 7183 | cbm_daemon_ipc_local_transition_t *transition = *transition_io; |
7177 | 7184 | if (!transition) { |
7178 | | - return true; |
| 7185 | + return CBM_DAEMON_IPC_RELEASE_COMPLETE; |
7179 | 7186 | } |
7180 | 7187 | if (!transition->endpoint || !transition->directory) { |
7181 | | - return false; |
| 7188 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
7182 | 7189 | } |
7183 | 7190 | if (transition->group_lock || transition->legacy_sentinel != INVALID_HANDLE_VALUE || |
7184 | 7191 | transition->teardown_legacy_guard) { |
7185 | | - if (!win_participant_state_release(transition->endpoint, transition->directory, |
7186 | | - &transition->startup_v2_lock, |
7187 | | - &transition->teardown_legacy_guard, |
7188 | | - &transition->group_lock, &transition->legacy_sentinel)) { |
7189 | | - return false; |
| 7192 | + int released = win_participant_state_release( |
| 7193 | + transition->endpoint, transition->directory, &transition->startup_v2_lock, |
| 7194 | + &transition->teardown_legacy_guard, &transition->group_lock, |
| 7195 | + &transition->legacy_sentinel); |
| 7196 | + if (released != CBM_DAEMON_IPC_RELEASE_COMPLETE) { |
| 7197 | + return released; |
7190 | 7198 | } |
7191 | 7199 | } else if (transition->startup_v2_lock && |
7192 | 7200 | cbm_private_file_lock_release(&transition->startup_v2_lock) != |
7193 | 7201 | CBM_PRIVATE_FILE_LOCK_OK) { |
7194 | | - return false; |
| 7202 | + return CBM_DAEMON_IPC_RELEASE_ERROR; |
7195 | 7203 | } |
7196 | 7204 | cbm_private_lock_directory_close(transition->directory); |
7197 | 7205 | transition->directory = NULL; |
7198 | 7206 | free(transition); |
7199 | 7207 | *transition_io = NULL; |
7200 | | - return true; |
| 7208 | + return CBM_DAEMON_IPC_RELEASE_COMPLETE; |
7201 | 7209 | } |
7202 | 7210 |
|
7203 | 7211 | #endif /* _WIN32 */ |
7204 | 7212 |
|
| 7213 | +bool cbm_daemon_ipc_local_transition_release(cbm_daemon_ipc_local_transition_t **transition_io) { |
| 7214 | + return cbm_daemon_ipc_local_transition_try_release(transition_io) == |
| 7215 | + CBM_DAEMON_IPC_RELEASE_COMPLETE; |
| 7216 | +} |
| 7217 | + |
7205 | 7218 | bool cbm_daemon_ipc_send_frame(cbm_daemon_ipc_connection_t *connection, |
7206 | 7219 | cbm_daemon_frame_type_t type, uint16_t flags, const void *payload, |
7207 | 7220 | uint32_t length) { |
|
0 commit comments