;;;; -*- coding: utf-8; -*-
+changes in sbcl-1.0.16 relative to 1.0.15:
+ * enhancement: add support for fcntl's struct flock to SB-POSIX.
+
changes in sbcl-1.0.15 relative to sbcl-1.0.14:
* enhancement: cleaner backtraces for interactive interrupts, as
well as other cases where the interesting frames used to be
(:integer f-setlkw "F_SETLKW" nil t)
(:integer f-getown "F_GETOWN" nil t)
(:integer f-setown "F_SETOWN" nil t)
+ (:integer f-rdlck "F_RDLCK" nil t)
+ (:integer f-wrlck "F_WRLCK" nil t)
+ (:integer f-unlck "F_UNLCK" nil t)
+
+ (:structure alien-flock
+ ("struct flock"
+ (short type "short" "l_type")
+ (short whence "short" "l_whence")
+ (off-t start "off_t" "l_start")
+ (off-t len "off_t" "l_len")
+ (pid-t pid "pid_t" "l_pid")))
;; lockf()
(:integer f-lock "F_LOCK" nil t)
#:stat-mode #:stat-ino #:stat-dev #:stat-nlink #:stat-uid
#:stat-gid #:stat-size #:stat-atime #:stat-mtime #:stat-ctime
#:termios-iflag #:termios-oflag #:termios-cflag
- #:termios-lflag #:termios-cc #:timeval-sec #:timeval-usec))
+ #:termios-lflag #:termios-cc #:timeval-sec #:timeval-usec
+ #:flock-type #:flock-whence #:flock-start #:flock-len
+ #:flock-pid))
#+win32
(load-shared-object "msvcrt.dll")
(define-call-internally fcntl-with-pointer-arg "fcntl" int minusp
(fd file-descriptor) (cmd int)
(arg alien-pointer-to-anything-or-nil))
+ (define-protocol-class flock alien-flock ()
+ ((type :initarg :type :accessor flock-type
+ :documentation "Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.")
+ (whence :initarg :whence :accessor flock-whence
+ :documentation "Flag for starting offset.")
+ (start :initarg :start :accessor flock-start
+ :documentation "Relative offset in bytes.")
+ (len :initarg :len :accessor flock-len
+ :documentation "Size; if 0 then until EOF.")
+ ;; Note: PID isn't initable, and is read-only. But other stuff in
+ ;; SB-POSIX right now loses when a protocol-class slot is unbound,
+ ;; so we initialize it to 0.
+ (pid :initform 0 :reader flock-pid
+ :documentation
+ "Process ID of the process holding the lock; returned with F_GETLK."))
+ (:documentation "Class representing locks used in fcntl(2)."))
(define-entry-point "fcntl" (fd cmd &optional (arg nil argp))
(if argp
(etypecase arg
((alien int) (fcntl-with-int-arg fd cmd arg))
- ((or (alien (* t)) null) (fcntl-with-pointer-arg fd cmd arg)))
+ ((or (alien (* t)) null) (fcntl-with-pointer-arg fd cmd arg))
+ (flock (with-alien-flock a-flock ()
+ (flock-to-alien arg a-flock)
+ (let ((r (fcntl-with-pointer-arg fd cmd a-flock)))
+ (alien-to-flock a-flock arg)
+ r))))
(fcntl-without-arg fd cmd)))
;; uid, gid
sb-posix::o-nonblock)))
t)
+(deftest fcntl.flock.1
+ (locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note))
+ (let ((flock (make-instance 'sb-posix:flock
+ :type sb-posix:f-wrlck
+ :whence sb-posix:seek-set
+ :start 0 :len 10))
+ (pathname "fcntl.flock.1")
+ kid-status)
+ (catch 'test
+ (with-open-file (f pathname :direction :output)
+ (write-line "1234567890" f)
+ (assert (zerop (sb-posix:fcntl f sb-posix:f-setlk flock)))
+ (let ((pid (sb-posix:fork)))
+ (if (zerop pid)
+ (progn
+ (multiple-value-bind (nope error)
+ (ignore-errors (sb-posix:fcntl f sb-posix:f-setlk flock))
+ (sb-ext:quit
+ :unix-status
+ (cond ((not (null nope)) 1)
+ ((= (sb-posix:syscall-errno error) sb-posix:eagain)
+ 42)
+ (t 86))
+ :recklessly-p t #| don't delete the file |#)))
+ (progn
+ (setf kid-status
+ (sb-posix:wexitstatus
+ (nth-value
+ 1 (sb-posix:waitpid pid 0))))
+ (throw 'test nil))))))
+ kid-status))
+ 42)
+
+
+(deftest fcntl.flock.2
+ (locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note))
+ (let ((flock (make-instance 'sb-posix:flock
+ :type sb-posix:f-wrlck
+ :whence sb-posix:seek-set
+ :start 0 :len 10))
+ (pathname "fcntl.flock.2")
+ kid-status)
+ (catch 'test
+ (with-open-file (f pathname :direction :output)
+ (write-line "1234567890" f)
+ (assert (zerop (sb-posix:fcntl f sb-posix:f-setlk flock)))
+ (let ((ppid (sb-posix:getpid))
+ (pid (sb-posix:fork)))
+ (if (zerop pid)
+ (let ((r (sb-posix:fcntl f sb-posix:f-getlk flock)))
+ (sb-ext:quit
+ :unix-status
+ (cond ((not (zerop r)) 1)
+ ((= (sb-posix:flock-pid flock) ppid) 42)
+ (t 86))
+ :recklessly-p t #| don't delete the file |#))
+ (progn
+ (setf kid-status
+ (sb-posix:wexitstatus
+ (nth-value
+ 1 (sb-posix:waitpid pid 0))))
+ (throw 'test nil))))))
+ kid-status))
+ 42)
+
(deftest opendir.1
(let ((dir (sb-posix:opendir "/")))
(unwind-protect (sb-alien:null-alien dir)
slots for those structures.
@itemize
+
+@item flock
+@include class-sb-posix-flock.texinfo
+
@item passwd
@include class-sb-posix-passwd.texinfo
;;; checkins which aren't released. (And occasionally for internal
;;; versions, especially for internal versions off the main CVS
;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.15.1"
+"1.0.15.2"