~ chicken-core (chicken-5) 245c96bc72702296679e49c706bff18e3fc55232
commit 245c96bc72702296679e49c706bff18e3fc55232 Author: Mario Domenech Goulart <mario@parenteses.org> AuthorDate: Sat Jun 7 21:45:23 2025 +0200 Commit: felix <felix@call-with-current-continuation.org> CommitDate: Sun Jun 8 10:07:53 2025 +0200 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. Signed-off-by: felix <felix@call-with-current-continuation.org> 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)Trap