⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locking.txt

📁 SIP 1.5.0源代码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
A useful experiment would be to kill them and see if imapd is affectedin any way, but I decline to do so without an OK from UCS!  ;-) Ifkilling statd/lockd can be done without breaking fcntl() on localfiles, this would become one of the primary means of dealing with thisproblem.     The statd and lockd daemons have quite a reputation for extremefragility.  There have been numerous reports about the lockingmechanism being wedged on a systemwide or even clusterwide basis,requiring a reboot to clear.  It is rumored that this wedge, once ithappens, also blocks local locking.  Presumably killing and restartingstatd would suffice to clear the wedge, but I haven't verified this.     There appears to be a limit to how many locks may be in use at atime on the system, although the documentation only mentions it inpassing.  On some of their systems, UCS has increased lockd's ``sizeof the socket buffer'', whatever that means.C-CLIENT USAGE     c-client uses flock().  On System V systems, flock() is simulatedby an emulator that calls fcntl().  This emulator is provided by somesystems (e.g. AIX), or uses c-client's flock.c module.BEZERK AND MMDF     Locking in the traditional UNIX formats was largely dictated bythe status quo in other applications; however, additional protectionis added against inadvertantly running multiple instances of ac-client application on the same mail file.     (1) c-client attempts to create a .lock file (mail file name with``.lock'' appended) whenever it reads from, or writes to, the mailfile.  This is an exclusive lock, and is held only for short periodsof time while c-client is actually doing the I/O.  There is a 5-minutetimeout for this lock, after which it is broken on the presumptionthat it is a stale lock.  If it can not create the .lock file due toan EACCES (protection failure) error, it once silently proceededwithout this lock; this was for systems which protect /usr/spool/mailfrom unprivileged processes creating files.  Today, c-client reportsan error unless it is built otherwise.  The purpose of this lock is toprevent against unfavorable interactions with mail delivery.     (2) c-client applies a shared flock() to the mail file wheneverit reads from the mail file, and an exclusive flock() whenever itwrites to the mail file.  This lock is freed as soon as it finishesreading.  The purpose of this lock is to prevent against unfavorableinteractions with mail delivery.     (3) c-client applies an exclusive flock() to a file on /tmp(whose name represents the device and inode number of the file) whenit opens the mail file.  This lock is maintained throughout thesession, although c-client has a feature (called ``kiss of death'')which permits c-client to forcibly and irreversibly seize the lockfrom a cooperating c-client application that surrenders the lock ondemand.  The purpose of this lock is to prevent against unfavorableinteractions with other instances of c-client (rewriting the mailfile).     Mail delivery daemons use lock (1), (2), or both.  Lock (1) worksover NFS; lock (2) is the only one that works on sites that protect/usr/spool/mail against unprivileged file creation.  Prudent maildelivery daemons use both forms of locking, and of course so doesc-client.     If only lock (2) is used, then multiple processes can read fromthe mail file simultaneously, although in real life this doesn'treally change things.  The normal state of locks (1) and (2) isunlocked except for very brief periods.TENEX AND MTX     The design of the locking mechanism of these formats wasmotivated by a design to enable multiple simultaneous read/writeaccess.  It is almost the reverse of how locking works withbezerk/mmdf.     (1) c-client applies a shared flock() to the mail file when itopens the mail file.  It upgrades this lock to exclusive whenever ittries to expunge the mail file.  Because of the flock() bug thatupgrading a lock actually releases it, it will not do so until it hasacquired an exclusive lock (2) first.  The purpose of this lock is toprevent against expunge taking place while some other c-client has themail file open (and thus knows where all the messages are).     (2) c-client applies a shared flock() to a file on /tmp (whosename represents the device and inode number of the file) when itparses the mail file.  It applies an exclusive flock() to this filewhen it appends new mail to the mail file, as well as before itattempts to upgrade lock (1) to exclusive.  The purpose of this lockis to prevent against data being appended while some other c-client isparsing mail in the file (to prevent reading of incomplete messages).It also protects against the lock-releasing timing race on lock (1).OBSERVATIONS     In a perfect world, locking works.  You are protected againstunfavorable interactions with the mailer and against your own mistakeby running more than one instance of your mail reader.  In tenex/mtxformats, you have the additional benefit that multiple simultaneousread/write access works, with the sole restriction being that youcan't expunge if there are any sharers of the mail file.     If the mail file is NFS-mounted, then flock() locking is a silentno-op.  This is the way BSD implements flock(), and c-client'semulation of flock() through fcntl() tests for NFS files andduplicates this functionality.  There is no locking protection fortenex/mtx mail files at all, and only protection against the mailerfor bezerk/mmdf mail files.  This has been the accepted state ofaffairs on UNIX for many sad years.     If you can not create .lock files, it should not affect locking,since the flock() locks suffice for all protection.  This is, however,not true if the mailer does not check for flock() locking, or if thethe mail file is NFS-mounted.     What this means is that there is *no* locking protection at allin the case of a client using an NFS-mounted /usr/spool/mail that doesnot permit file creation by unprivileged programs.  It is impossible,under these circumstances, for an unprivileged program to do anythingabout it.  Worse, if EACCES errors on .lock file creation are no-op'ed, the user won't even know about it.  This is arguably a siteconfiguration error.     The problem with not being able to create .lock files exists onSystem V as well, but the failure modes for flock() -- which isimplemented via fcntl() -- are different.     On System V, if the mail file is NFS-mounted and either theclient or the server lacks a functioning statd/lockd pair, then thelock attempt would have hung forever if it weren't for the fact thatc-client tests for NFS and no-ops the flock() emulator in this case.Systemwide or clusterwide failures of statd/lockd have been known tooccur which cause all locks in all processes to hang (includinglocal?).  Without the special NFS test made by c-client, there wouldbe no way to request BSD-style no-op behavior, nor is there any way todetermine that this is happening other than the system being hung.     The additional locking introduced by c-client was shown to causemuch more stress on the System V locking mechanism than hastraditionally been placed upon it.  If it was stressed too far, allhell broke loose.  Fortunately, this is now past history.TRADEOFFS     c-client based applications have a reasonable chance of winningas long as you don't use NFS for remote access to mail files.  That'swhat IMAP is for, after all.  It is, however, very important torealize that you can *not* use the lock-upgrade feature by itselfbecause it releases the lock as an interim step -- you need to havelock-upgrading guarded by another lock.     If you have the misfortune of using System V, you are likely torun into problems sooner or later having to do with statd/lockd.  Youbasically end up with one of three unsatisfactory choices:	1) Grit your teeth and live with it.	2) Try to make it work:	   a) avoid NFS access so as not to stress statd/lockd.	   b) try to understand the code in statd/lockd and hack it	      to be more robust.	   c) hunt out the system limit of locks, if there is one,	      and increase it.  Figure on at least two locks per	      simultaneous imapd process and four locks per Pine	      process.  Better yet, make the limit be 10 times the	      maximum number of processes.	   d) increase the socket buffer (-S switch to lockd) if	      it is offered.  I don't know what this actually does,	      but giving lockd more resources to do its work can't	      hurt.  Maybe.	3) Decide that it can't possibly work, and turn off the 	   fcntl() calls in your program.	4) If nuking statd/lockd can be done without breaking local	   locking, then do so.  This would make SVR4 have the same	   limitations as BSD locking, with a couple of additional	   bugs.	5) Check for NFS, and don't do the fcntl() in the NFS case.	   This is what c-client does.     Note that if you are going to use NFS to access files on a serverwhich does not have statd/lockd running, your only choice is (3), (4),or (5).  Here again, IMAP can bail you out.     These problems aren't unique to c-client applications; they havealso been reported with Elm, Mediamail, and other email tools.     Of the other two SVR4 locking bugs:     Programmer awareness is necessary to deal with the bug that youcan not get an exclusive lock unless the file is open for write.  Ibelieve that c-client has fixed all of these cases.     The problem about opening a second designator smashing anycurrent locks on the file has not been addressed satisfactorily yet.This is not an easy problem to deal with, especially in c-client whichreally doesn't know what other files/streams may be open by Pine.     Aren't you so happy that you bought an System V system?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -