>From 558548f8682e9ca76157a1d7e3d79fe0da0bc151 Mon Sep 17 00:00:00 2001 From: Mario Domenech Goulart Date: Sat, 7 Jun 2025 21:45:23 +0200 Subject: [PATCH] posixunix.scm: Check for _eagain in file-lock Everywhere else we check for both _eagain and _ewouldblock, so do that as well in file-lock. Add a helper inline procedure to reduce code duplication and prevent future similar cases. --- posixunix.scm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/posixunix.scm b/posixunix.scm index f329dada..7b539d2a 100644 --- a/posixunix.scm +++ b/posixunix.scm @@ -778,6 +778,9 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime) (when (fx< (link old new) 0) (posix-error #:file-error 'hard-link "could not create hard link" old new) ) ) ) ) +(define-inline (eagain/ewouldblock? e) + (or (fx= e _ewouldblock) + (fx= e _eagain))) (define ##sys#custom-input-port (lambda (loc nam fd #!optional (nonblocking? #f) (bufi 1) (on-close void) (more? #f) enc) @@ -791,8 +794,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime) (lambda () (let ((res (##sys#file-select-one fd))) (if (fx= -1 res) - (if (or (fx= _errno _ewouldblock) - (fx= _errno _eagain)) + (if (eagain/ewouldblock? _errno) #f (posix-error #:file-error loc "cannot select" fd nam)) (fx= 1 res))))] @@ -809,8 +811,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime) (let ([cnt (##core#inline "C_read" fd buf bufsiz)]) (cond ((fx= cnt -1) (cond - ((or (fx= _errno _ewouldblock) - (fx= _errno _eagain)) + ((eagain/ewouldblock? _errno) (##sys#thread-block-for-i/o! ##sys#current-thread fd #:input) (##sys#thread-yield!) (loop) ) @@ -826,8 +827,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime) (loop) ) (let ([cnt (##core#inline "C_read" fd buf bufsiz)]) (when (fx= cnt -1) - (if (or (fx= _errno _ewouldblock) - (fx= _errno _eagain)) + (if (eagain/ewouldblock? _errno) (set! cnt 0) (posix-error #:file-error loc "cannot read" fd nam) ) ) (set! buflen cnt) @@ -934,8 +934,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime) (let ((cnt (##core#inline "C_write" fd bv start len))) (cond ((fx= -1 cnt) (cond - ((or (fx= _errno _ewouldblock) - (fx= _errno _eagain)) + ((eagain/ewouldblock? _errno) (##sys#thread-yield!) (poke bv start len) ) ((fx= _errno _eintr) @@ -1023,7 +1022,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime) (##core#inline "C_fixnum_or" _lock_nb (if shared _lock_sh _lock_ex))))) (cond ((eq? r 0) #t) ((fx= _errno _eintr) (loop)) - ((fx= _errno _ewouldblock) #f) + ((eagain/ewouldblock? _errno) #f) (else (err "locking file failed" port 'file-lock))))))) (set! chicken.file.posix#file-lock/blocking (lambda (port #!optional shared) -- 2.47.2