From: Tanaka Akira Date: 2002-09-28T02:55:59+09:00 Subject: [ruby-dev:18405] Re: pstore.rb can make a broken store In article <200209271620.g8RGKtG02161@edge.back-street.net>, Takahiro Kambe writes: > $B8E$/$O(BINN$B$+2?$+$N%a!<%j%s%0%j%9%H$@$C$?$H;W$$$^$7$?$,!"(BNetBSD($B$K8B$i$J(B > $B$$$H;W$$$^$9$,(B)$B$N(Bfcntl(2)$B$K$"$j$^$7$?!#(B > > This interface follows the completely stupid semantics of AT&T System V > UNIX and IEEE Std 1003.1-1988 (``POSIX'') that require that all locks as- > sociated with a file for a given process are removed when any file de- > scriptor for that file is closed by that process. This semantic means > that applications must be aware of any files that a subroutine library > may access. For example if an application for updating the password file > ... > database. Another minor semantic problem with this interface is that > locks are not inherited by a child process created using the fork(2) > function. The flock(2) interface has much more rational last close se- > mantics and allows locks to be inherited by child processes. Calling > flock(2) is recommended for applications that want to ensure the integri- > ty of their locks when using library routines or wish to pass locks to > their children. Note that flock(2) and fcntl(2) locks may be safely used > concurrently. $B$*$)!#(Bfcntl $B$rH/9T$7$?0J30$N(B file descriptor $B$G$bF1$8%U%!%$%k$K$D$J$,$C(B $B$F$k$N$r(B close $B$9$k$H(B unlock $B$5$l$k$H$$$&$N$O3N$+$K4qL/$G$9$M!#$3$l$,(B $BJQ$@$H$$$&$N$OG flock(2)$B$NJ}$K$O!"(B > > NOTES > Locks are on files, not file descriptors. That is, file descriptors du- > plicated through dup(2) or fork(2) do not result in multiple instances of > a lock, but rather multiple references to a single lock. If a process > holding a lock on a file forks and the child explicitly unlocks the file, > the parent will lose its lock. > > $B$H$$$C$?5-=R$b$"$j$^$9!#%U%!%$%k$r(Bunlink(2)$B$9$k>l9g$O!":G8e$K%*!<%W%s(B > $B$5$l$F$$$?%U%!%$%k5-=R;R$,(Bclose$B$5$l$?;~E@$GC$($k$3$H$HBPHf$9$k(B > $B$H!"6K$a$FIT<+A3$K;W$($^$9!#(B > > > $B;W$&$K!"(Block $B$O(B fork $B$7$F$b flock(2)$B$Oe5-$N(B NOTE $B$NKAF,$G=R$Y$i$l$F$kOC$G!"FI$_J}$,B-$j$J$+$C$?(B $B$G$9!#(B -- [$BEDCf(B $BE/(B][$B$?$J$+(B $B$"$-$i(B][Tanaka Akira] $B!V$U$($m(B! $B$o$+$a$A$c$s:n@o$G$9$(C"=$B!W(B(Little Worker, $B7KM7@84](B)