00001 #ifndef LWATCH_H 00002 #define LWATCH_H 00003 00004 /*****************************************************************************/ 00005 /******************************** Documentation ******************************/ 00006 /*****************************************************************************/ 00007 00008 /** 00009 * \file 00010 * Public interface for watching log files. 00011 */ 00012 00013 /*****************************************************************************/ 00014 /******************************* Include Files *******************************/ 00015 /*****************************************************************************/ 00016 00017 #include <sys/param.h> 00018 00019 #include "watch_database.h" 00020 00021 /*****************************************************************************/ 00022 /*********************************** Defines *********************************/ 00023 /*****************************************************************************/ 00024 00025 /** 00026 * Base error code (minimum value) for log watch errors 00027 */ 00028 #define LWATCH_ERROR_BASE -4000 00029 /** 00030 * Maximum error code for log watch errors 00031 */ 00032 #define LWATCH_ERROR_LIMIT (LWATCH_ERROR_BASE + 50) 00033 /** 00034 * Return true if error code is within the range for log watch errors. 00035 * 00036 * \param[in] error The error code to test if it's a log watch error code. 00037 * \return True if error code is a log watch error. 00038 */ 00039 #define IS_LWATCH_ERROR(error) (((error) >= LWATCH_ERROR_BASE) && ((error) < LWATCH_ERROR_LIMIT)) 00040 00041 #define LWATCH_ERROR_CANNOT_MONITOR (LWATCH_ERROR_BASE + 1) /**< cannot monitor target */ 00042 #define LWATCH_ERROR_CANNOT_FIND_PATH_INFO (LWATCH_ERROR_BASE + 2) /**< cannot find path info */ 00043 #define LWATCH_ERROR_LOST_RENAME (LWATCH_ERROR_BASE + 3) /**< one of the paths for a rename event is unknown */ 00044 #define LWATCH_ERROR_STAT_NOT_VALID (LWATCH_ERROR_BASE + 4) /**< stat information is not valid */ 00045 00046 /*****************************************************************************/ 00047 /******************************* Type Definitions ****************************/ 00048 /*****************************************************************************/ 00049 00050 /** 00051 * The set of log watch event types. 00052 */ 00053 typedef enum { 00054 LWATCH_EVENT_CREATE, /**< a file or directory was created */ 00055 LWATCH_EVENT_DELETE, /**< a file or directory was deleted */ 00056 LWATCH_EVENT_RENAME, /**< a file or directory was renamed */ 00057 LWATCH_EVENT_MODIFY, /**< a file or directory was modified */ 00058 LWATCH_EVENT_OPEN, /**< a file or directory was opened */ 00059 LWATCH_EVENT_CLOSE /**< a file or directory was closed */ 00060 } lwatch_event_type; 00061 00062 /** 00063 * Watch event. Changes to the filesystem are abstracted into events of this 00064 * type and sent to interested listeners. This decouples the subsystem used to 00065 * watch for filesystem changes from the code used to interpret the filesystem 00066 * change. See \ref WatchEventDoc. 00067 */ 00068 struct lwatch_event_t { 00069 lwatch_event_type event_type; /**< the type of the event */ 00070 union { 00071 char path[PATH_MAX]; /**< for anything other than a rename, this is 00072 the pathname associated with the event */ 00073 struct { 00074 char prev_path[PATH_MAX]; /**< previous pathname for a rename, may be empty */ 00075 char new_path[PATH_MAX]; /**< new pathname for a rename, may be empty */ 00076 } rename; /**< if the event was a rename, these are the 00077 pair of pathnames, one of the two may be empty 00078 if we don't know what it was renamed from or to */ 00079 }; 00080 }; 00081 00082 /** 00083 * This callback is used when a watch event occurs. Parties interested in 00084 * receiving watch events register a callback of this type. When a watch event 00085 * occurs their callback is invoked passing the watch event to it. 00086 */ 00087 typedef int (*lwatch_event_callback_t)(struct lwatch_event_t *event); 00088 00089 /*****************************************************************************/ 00090 /************************* External Global Variables ***********************/ 00091 /*****************************************************************************/ 00092 00093 /*****************************************************************************/ 00094 /**************************** Exported Functions ***************************/ 00095 /*****************************************************************************/ 00096 00097 int destroy_path_info(struct lwatch_path_info_t **ppath_info); 00098 int update_stat_info(struct stat *cur_stat_info, struct lwatch_path_info_t *path_info); 00099 bool is_log_backup(const char *path); 00100 00101 #endif