📄 fam.3x
字号:
'\"macro stdmacro.if n .pH g3x.fam @(#)fam 30.3 of 1/19/86.nr X.if \nX=0 .ds x} FAM 3X "Specialized Libraries" "\&".if \nX=1 .ds x} FAM 3X "Specialized Libraries".if \nX=2 .ds x} FAM 3X "" "\&".if \nX=3 .ds x} FAM "" "" "\&".TH \*(x}.SH NAMEfam \- File Alteration Monitor (FAM) library routines.SH SYNOPSIS.nf.B #include <fam.h>.P.B "extern int FAMOpen(FAMConnection* fc);".PP.B "extern int FAMClose(FAMConnection* fc);".PP.B "extern int FAMMonitorDirectory(FAMConnection *fc,".B " char *filename,".B " FAMRequest* fr,".B " void* userData);".PP.B "extern int FAMMonitorFile(FAMConnection *fc, .B " char *filename,".B " FAMRequest* fr,".B " void* userData);".PP.B "int FAMSuspendMonitor(FAMConnection *fc, FAMRequest *fr);".PP.B "int FAMResumeMonitor(FAMConnection *fc, FAMRequest *fr);".PP.B "int FAMCancelMonitor(FAMConnection *fc, FAMRequest *fr);".PP.B "int FAMNextEvent(FAMConnection *fc, FAMEvent *fe);".PP.B "int FAMPending(FAMConnection* fc);".PP.B "typedef struct {".B " int fd;".B "} FAMConnection;".PP.B "#define FAMCONNECTION_GETFD(fc) (fc->fd)".PP.B "typedef struct {".B " int reqnum;".B "} FAMRequest;".PP.B "enum FAMCodes { FAMChanged=1, FAMDeleted=2, FAMStartExecuting=3, ".B " FAMStopExecuting=4, FAMCreated=5, FAMMoved=6, FAMAcknowledge=7,".B " FAMExists=8, FAMEndExist=9 };".PP.B "typedef struct {".B " FAMConnection* fc;".B " FAMRequest fr;".B " char hostname[MAXHOSTNAMELEN];".B " char filename[NAME_MAX];".B " void *userdata;".B " FAMCodes code;".B "} FAMEvent;".PP.B "extern int FAMErrno;".PP.B "extern char *FamErrlist[];".PP.SH DESCRIPTION\fIFAM\fP monitors files and directories, notifying interestedapplications of changes. Routines for communicating with the fam(1M)server process are found in ``libfam.a'', which is loaded if theoption ``-lfam'' is used with cc(1) or ld(1). The library``libC.a'' (``-lC'') must also be specified..PPAn application calls routines described here to establish a list offiles for \fIfam \fPto monitor. \fIFam \fPgenerates events on a socket tocommunicate with the application. The \fIfam\fP process is started whenthe first connection from any application to it is opened. It exitsafter all connections to it have been closed..PP.SH USING FAMHere are the steps required to use \fIFAM \fPin an application:.PP.AL.LI.IP 1.Create a connection to \fIfam\fP by calling FAMOpen. This routinewill pass back a FAMConnection structure used in all \fIfam \fPprocedures. .IP 2.Tell \fIfam\fP which files and directories to monitor by callingFAMMonitorFile and FAMMonitorDirectory to express interest infiles and directories, respectively..IP 3.Select on the \fIfam\fP socket file descriptor and callFAMPending when the \fIfam \fPsocket is active, and FAMNextEvent whenFAMPending indicates that an event is available. Alternatively,call FAMPending (or FAMNextEvent)periodically to check the socket connection to \fIfam\fP to seeif any new information has arrived. If there are no eventspending, FAMNextEvent blocks until an event occurs..IP 4.When the application is through monitoring a file or directory, itshould call FAMCancelMonitor. If the application wants totemporarily suspend monitoring of a file or directory, it may callFAMSuspendMonitor. When the application is ready to startmonitoring again, it calls FAMResumeMonitor..IP 5.Before the application exits, it should call FAMClose to freeresources associated with files still being monitored and to close theconnection to \fIfam.\fP.PP.SH DATA STRUCTURES.B "The FAMConnection Structure".PPThe FAMConnection data structure is created when opening a connectionto \fIFAM.\fP Subsequently it is passed into all \fIFAM \fPprocedures. Thisstructure has all the information in it to communicate to \fIfam\fP..PPUse the macro FAMCONNECTION_GETFD to access the file descriptor inside theFAMConnection, rather than accessing it directly..PP.B "The FAMRequest Structure".PPWhen \fIfam\fP is called on to monitor a file, it passes back aFAMRequest structure. This structure uniquely identifies the requestso that it may be cancelled, using FAMCancelMonitoror suspended, using FAMSuspendMonitor..PP.B "The FAMEvent Structure".PPChanges to files and directories are encoded in the FAMEventstructure. The \fIcode \fPfield of this structure contains one of thefollowing enumeration constants:.TP .90i.SM FAMChangedSome value which can be obtained with fstat(1) changed for a file ordirectory being monitored..TP.SM FAMDeletedA file or directory being monitored was deleted or its name was changed.This event is also generated when monitoring starts on a nonexistent file or directory..TP.SM FAMStartExecutingAn executable file or shared librarybeing monitored started executing. If multiple processes executethe same file, this event only occurs when the first process starts..TP.SM FAMStopExecutingAn executable file being monitored which was running finished. Ifmultiple processes from an executable are running, this event is onlygenerated when the last one finishes..TP.SM FAMCreatedA file was created in a directory being monitored. Note: this eventis only generated for files created directly in a directory beingmonitored; subdirectories are not automatically monitored..TP.SM FAMMovedFAMMoved events never occur. The name remains defined so thatprograms that reference it will still compile..TP.SM FAMAcknowledgeAfter a FAMCancelMonitor, \fIfam \fPgenerates a FAMAcknowledge event.Also, if an invalid pathname is specified, \fIfam \fP generates aFAMAcknowledge event..TP.SM FAMExistsWhen the application requests a file be monitored, \fIfam\fPgenerates a FAMExists event for that file. When the applicationrequests a directory be monitored, \fIfam\fP generates a FAMExistsevent for that directory and every file directly contained in thatdirectory..TP.SM FAMEndExistWhen the application requests a file directory be monitored, a series ofFAMExists events is generated as described above. After the lastFAMExists message, \fIfam \fPgenerates a FAMEndExist message..PPIf a FAM event applies to a file or directory being monitored, theFAMEvent's \fIfilename \fPfield contains the full pathnamethat was passed to fam.If an event applies to an entry in a monitored directory, the\fIfilename \fPfield contains the relative path only. Forexample, if the directory \fI/usr/tmp/xyzzy \fPwere monitored,and the file \fI/usr/tmp/xyzzy/plugh \fP were deleted, a FAMDeletedevent would be generated containing "plugh" in \fIfilename\fP.If the directory itself were deleted, \fIfilename \fPwould contain"/usr/tmp/xyzzy"..\".SH ERROR HANDLING.\"If an error occurs inside of \fIFAM, \fPa global named FAMErrno is set to a.\"non-zero value and the routine that generated the error in will return an error.\"value. The value of FAMErrno is valid until the next \fIFAM \fProutine is.\"called. The FAMErrno can be translated in to a character string using the.\"global array FAMErrlist..PP.SH PROCEDURES.B "FAMOpen, FAMClose".PPThe application opens a connection to \fIfam \fPby calling FAMOpen. FAMOpeninitializes the FAMConnection structure passed in to it and returns 0 ifsuccessful, otherwise -1. The variable char* appName should be set to the name of your application. The FAMConnection structure is passed to allsubsequent \fIFAM \fPprocedure calls.FAMClose frees resources associated with files still being monitored and closesa \fIfam \fPconnection. It returns 0 if successful and -1 otherwise..PP.B "FAMMonitorDirectory, FAMMonitorFile".PPFAMMonitorDirectory and FAMMonitorFile tell \fIFAM \fPto startmonitoring a directory or file, respectively. The parameters to thisfunction are a FAMConnection (initialized by FAMOpen), a FAMRequeststructure, a filename and a user data pointer. The FAMRequeststructure is modified to subsequently identify this request. Whenthe file or directory changes, a \fIFAM \fPevent structure will begenerated. The application can retrieve this structure by callingFAMNextEvent (see description under FAMNextEvent)..PPFAMMonitorDirectory monitors changes that happens to the contents of thedirectory (as well as the directory file itself); FAMMonitorFile monitors onlywhat happens to a particular file. Both routines return 0 if successful and -1otherwise..PPThe filename argument must be a full pathname..B "FAMSuspendMonitor, FAMResumeMonitor".PPFAMSuspendMonitor temporarily suspends monitoring of files or directories.This is useful when an application is not displaying information about files,when it is iconified, for example. FAMResumeMonitor signals \fIfam \fPtostart monitoring the file or directory again. Changes which occur whilemonitoring is suspended are enqueued and delivered when monitoring isresumed..PPBoth of these routines take a FAMConnection and a FAMRequest structure.The FAMRequest Structure is returned from the FAMMonitorFile orFAMMonitorDirectory routines and return 0 if successful and -1 otherwise..PPBecause fam runs as an asynchronous process, FAMNextEvent may returna few events regarding a given request after that request has been suspended..B "FAMCancelMonitor".PPWhen an application is through monitoring a file or directory, it shouldcall FAMCancelMonitor. This routine will signal \fIfam \fPnot to monitorthis directory anymore. The FAMRequest structure is returned from theFAMMonitorFile or FAMMonitorDirectory routines. FAMCancelMonitor returns 0 ifsuccessful and -1 otherwise..PP.B "FAMPending, FAMNextEvent".PPFAMPending returns 1 if an event is waiting and 0 if no event is waiting. Italso returns 1 if an error has been encountered. This routine returnsimmediately to the caller..PPFAMNextEvent will get the next \fIFAM \fPevent. If there are no \fIFAM\fPevents waiting, then the calling application blocks until a \fIFAM \fPeventis received. If blocking is not desirable, call FAMPending beforeFAMNextEvent, and only call FAMNextEvent when FAMPending says an event isavailable..PPThere are two ways to for applications to receive \fIFAM \fPevents:.PP.AL.LI1. The Select approach - The application selects on the file descriptor returned from FAMOpen, in the FAMConnection structure. When this file descriptor becomes active, the application calls FAMPending to determine whether a complete event is ready, and FAMNextEvent to retrieve the pending \fIFAM \fPevent..PP2. The Polling approach - The application calls FAMPending periodically (usually when the system is waiting for input). When FAMPending returns 1, the application calls FAMNextEvent to retrieve the pending \fIFAM \fP event..PPFAMNextEvent reads any information that is on the \fIfam \fPsocket,and returns it to the application in the form of a FAMEvent..PPFAMNextEvent returns 1 if successful and -1 otherwise..SH SEE ALSOfam(1M)..SH BUGSThe FAMMoved event is not currently supported..PPFAMNextEvent may not initialize the FAMEvent's filename fieldfor FAMEndExist and FAMAcknowledge events.Use the request number to determine the file or directoryto which those events refer..PPFAMErrno and FamErrlist are not set when errors occur..PPWhen a shell script is run, notification is generated for the shellexecuting the script, typically sh(1) or csh(1)..PPEach process is limited to 1000 active requests at a time.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -