@@ -3220,44 +3220,65 @@ void cbm_daemon_ipc_listener_close(cbm_daemon_ipc_listener_t *listener) {
32203220 free (listener );
32213221}
32223222
3223- /* Touch through the held descriptor only after proving the path still names
3224- * it: refreshing by path would keep a replacement inode fresh and hide the
3225- * loss (#2178). */
3226- static bool posix_held_file_touch (int directory_fd , const char * base_name , int fd ) {
3227- return private_regular_file_snapshot (directory_fd , base_name , fd , 1 , NULL ) &&
3228- futimens (fd , NULL ) == 0 ;
3223+ /* Touch results: 1 refreshed, 0 lost (the path no longer names the owned
3224+ * file), -1 transient (a still-valid file could not be refreshed). Touch
3225+ * through the held descriptor only after proving the path still names it:
3226+ * refreshing by path would keep a replacement inode fresh and hide the loss
3227+ * (#2178). */
3228+ static int posix_touch_fold (int result , int next ) {
3229+ return result == 0 || next == 0 ? 0 : (result < 0 || next < 0 ? -1 : 1 );
32293230}
32303231
3231- static bool posix_held_lock_touch (int directory_fd , const process_lock_entry_t * entry , int fd ) {
3232- return entry && posix_held_file_touch (directory_fd , entry -> lock_name , fd );
3232+ static int posix_held_file_touch (int directory_fd , const char * base_name , int fd ) {
3233+ if (!private_regular_file_snapshot (directory_fd , base_name , fd , 1 , NULL )) {
3234+ return 0 ;
3235+ }
3236+ return futimens (fd , NULL ) == 0 ? 1 : -1 ;
3237+ }
3238+
3239+ static int posix_held_lock_touch (int directory_fd , const process_lock_entry_t * entry , int fd ) {
3240+ return entry ? posix_held_file_touch (directory_fd , entry -> lock_name , fd ) : 0 ;
3241+ }
3242+
3243+ static int posix_identity_marker_touch (const cbm_daemon_ipc_listener_t * listener ) {
3244+ /* The marker is not held open; reopen it and require the published inode.
3245+ * Only ENOENT proves loss: EMFILE and friends say nothing about the file. */
3246+ int marker_fd = openat (listener -> dir_fd , listener -> socket_identity_name ,
3247+ O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK );
3248+ if (marker_fd < 0 ) {
3249+ return errno == ENOENT ? 0 : -1 ;
3250+ }
3251+ struct stat marker_status ;
3252+ int result = 0 ;
3253+ if (private_regular_file_snapshot (listener -> dir_fd , listener -> socket_identity_name , marker_fd ,
3254+ 1 , & marker_status ) &&
3255+ marker_status .st_dev == listener -> identity_device &&
3256+ marker_status .st_ino == listener -> identity_inode ) {
3257+ result = futimens (marker_fd , NULL ) == 0 ? 1 : -1 ;
3258+ }
3259+ (void )close (marker_fd );
3260+ return result ;
32333261}
32343262
3235- bool cbm_daemon_ipc_listener_touch (cbm_daemon_ipc_listener_t * listener ) {
3263+ int cbm_daemon_ipc_listener_touch (cbm_daemon_ipc_listener_t * listener ,
3264+ cbm_daemon_ipc_participant_guard_t * external_guard ) {
32363265 if (!listener || listener -> dir_fd < 0 || listener -> owner_pid != getpid () ||
32373266 !listener -> lifetime_reservation ) {
3238- return false ;
3267+ return 0 ;
32393268 }
3240- bool lifetime =
3269+ int result =
32413270 posix_held_lock_touch (listener -> dir_fd , listener -> lifetime_reservation -> process_entry ,
32423271 listener -> lifetime_reservation -> fd );
3243- const cbm_daemon_ipc_participant_guard_t * guard = listener -> participant_guard ;
3244- bool participant =
3245- !guard ||
3246- posix_held_lock_touch (listener -> dir_fd , guard -> legacy_process_entry , guard -> legacy_fd );
3247- /* The marker is not held open; reopen it and require the published inode. */
3248- int marker_fd = openat (listener -> dir_fd , listener -> socket_identity_name ,
3249- O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK );
3250- struct stat marker_status ;
3251- bool marker = marker_fd >= 0 &&
3252- private_regular_file_snapshot (listener -> dir_fd , listener -> socket_identity_name ,
3253- marker_fd , 1 , & marker_status ) &&
3254- marker_status .st_dev == listener -> identity_device &&
3255- marker_status .st_ino == listener -> identity_inode &&
3256- futimens (marker_fd , NULL ) == 0 ;
3257- if (marker_fd >= 0 ) {
3258- (void )close (marker_fd );
3272+ const cbm_daemon_ipc_participant_guard_t * guards [] = {listener -> participant_guard ,
3273+ external_guard };
3274+ for (size_t i = 0 ; i < sizeof (guards ) / sizeof (guards [0 ]); i ++ ) {
3275+ if (guards [i ]) {
3276+ result = posix_touch_fold (result , posix_held_lock_touch (listener -> dir_fd ,
3277+ guards [i ]-> legacy_process_entry ,
3278+ guards [i ]-> legacy_fd ));
3279+ }
32593280 }
3260- return lifetime && participant && marker ;
3281+ return posix_touch_fold ( result , posix_identity_marker_touch ( listener )) ;
32613282}
32623283
32633284int cbm_daemon_ipc_accept (cbm_daemon_ipc_listener_t * listener , uint32_t timeout_ms ,
@@ -3643,10 +3664,12 @@ bool cbm_daemon_ipc_participant_guard_release(cbm_daemon_ipc_participant_guard_t
36433664 return true;
36443665}
36453666
3646- bool cbm_daemon_ipc_participant_guard_touch (const cbm_daemon_ipc_endpoint_t * endpoint ,
3647- cbm_daemon_ipc_participant_guard_t * guard ) {
3648- return endpoint && guard && guard -> owner_pid == getpid () &&
3649- posix_held_lock_touch (endpoint -> dir_fd , guard -> legacy_process_entry , guard -> legacy_fd );
3667+ int cbm_daemon_ipc_participant_guard_touch (const cbm_daemon_ipc_endpoint_t * endpoint ,
3668+ cbm_daemon_ipc_participant_guard_t * guard ) {
3669+ if (!endpoint || !guard || guard -> owner_pid != getpid ()) {
3670+ return 0 ;
3671+ }
3672+ return posix_held_lock_touch (endpoint -> dir_fd , guard -> legacy_process_entry , guard -> legacy_fd );
36503673}
36513674
36523675int cbm_daemon_ipc_local_transition_try_acquire (
@@ -6794,13 +6817,15 @@ bool cbm_daemon_ipc_participant_guard_release(cbm_daemon_ipc_participant_guard_t
67946817
67956818/* Windows has no age-based cleaner of the private runtime directory, and its
67966819 * held handles deny deletion; the #2178 heartbeat has nothing to refresh. */
6797- bool cbm_daemon_ipc_listener_touch (cbm_daemon_ipc_listener_t * listener ) {
6798- return listener != NULL ;
6820+ int cbm_daemon_ipc_listener_touch (cbm_daemon_ipc_listener_t * listener ,
6821+ cbm_daemon_ipc_participant_guard_t * external_guard ) {
6822+ (void )external_guard ;
6823+ return listener ? 1 : 0 ;
67996824}
68006825
6801- bool cbm_daemon_ipc_participant_guard_touch (const cbm_daemon_ipc_endpoint_t * endpoint ,
6802- cbm_daemon_ipc_participant_guard_t * guard ) {
6803- return endpoint && guard ;
6826+ int cbm_daemon_ipc_participant_guard_touch (const cbm_daemon_ipc_endpoint_t * endpoint ,
6827+ cbm_daemon_ipc_participant_guard_t * guard ) {
6828+ return endpoint && guard ? 1 : 0 ;
68046829}
68056830
68066831int cbm_daemon_ipc_local_transition_try_acquire (
0 commit comments