entangler 0.4.1 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,212 +0,0 @@
1
- /******************************************************************************
2
- *******************************************************************************
3
- *******************************************************************************
4
-
5
-
6
- kernel-filesystem-monitor-daemon
7
- Copyright (C) 2005 Ben Martin
8
-
9
- This program is free software; you can redistribute it and/or modify
10
- it under the terms of the GNU General Public License as published by
11
- the Free Software Foundation; either version 2 of the License, or
12
- (at your option) any later version.
13
-
14
- This program is distributed in the hope that it will be useful,
15
- but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- GNU General Public License for more details.
18
-
19
- You should have received a copy of the GNU General Public License
20
- along with this program; if not, write to the Free Software
21
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
-
23
- For more details see the COPYING file in the root directory of this
24
- distribution.
25
-
26
- $Id: kernel-filesystem-monitor-daemon.hh,v 1.3 2008/01/03 21:31:06 ben Exp $
27
-
28
- *******************************************************************************
29
- *******************************************************************************
30
- ******************************************************************************/
31
-
32
- #ifndef _ALREADY_INCLUDED_KERNEL_FILESYSTEM_MONITOR_DAEMON_HH_
33
- #define _ALREADY_INCLUDED_KERNEL_FILESYSTEM_MONITOR_DAEMON_HH_
34
-
35
- #include <sys/stat.h>
36
-
37
- #include <sys/inotify.h>
38
- #include <popt.h>
39
-
40
- #include <string>
41
- #include <map>
42
- #include <set>
43
- #include <list>
44
-
45
- using namespace std;
46
-
47
- extern unsigned long Verbose;
48
-
49
- string getHomeDir( const char* homedir_CSTR );
50
-
51
- /********************************************************************************/
52
- /********************************************************************************/
53
- /********************************************************************************/
54
-
55
- template< class STREAM >
56
- void print_mask(STREAM& ss,int mask)
57
- {
58
- if (mask & IN_ACCESS)
59
- {
60
- ss << "ACCESS ";
61
- }
62
- if (mask & IN_MODIFY)
63
- {
64
- ss << "MODIFY ";
65
- }
66
- if (mask & IN_ATTRIB)
67
- {
68
- ss << "ATTRIB ";
69
- }
70
- if (mask & IN_CLOSE)
71
- {
72
- ss << "CLOSE ";
73
- }
74
- if (mask & IN_OPEN)
75
- {
76
- ss << "OPEN ";
77
- }
78
- if (mask & IN_MOVED_FROM)
79
- {
80
- ss << "MOVE_FROM ";
81
- }
82
- if (mask & IN_MOVED_TO)
83
- {
84
- ss << "MOVE_TO ";
85
- }
86
- #ifdef IN_DELETE_SUBDIR
87
- if (mask & IN_DELETE_SUBDIR)
88
- {
89
- ss << "DELETE_SUBDIR ";
90
- }
91
- #endif
92
- #ifdef IN_DELETE
93
- if (mask & IN_DELETE)
94
- {
95
- ss << "DELETE ";
96
- }
97
- #endif
98
- #ifdef IN_DELETE_FILE
99
- if (mask & IN_DELETE_FILE)
100
- {
101
- ss << "DELETE_FILE ";
102
- }
103
- #endif
104
- #ifdef IN_DELETE_SELF
105
- if (mask & IN_DELETE_SELF)
106
- {
107
- ss << "DELETE_SELF ";
108
- }
109
- #endif
110
- #ifdef IN_CREATE_SUBDIR
111
- if (mask & IN_CREATE_SUBDIR)
112
- {
113
- ss << "CREATE_SUBDIR ";
114
- }
115
- #endif
116
- #ifdef IN_CREATE_FILE
117
- if (mask & IN_CREATE_FILE)
118
- {
119
- ss << "CREATE_FILE ";
120
- }
121
- #endif
122
- #ifdef IN_CREATE
123
- if (mask & IN_CREATE)
124
- {
125
- ss << "CREATE ";
126
- }
127
- #endif
128
- if (mask & IN_DELETE_SELF)
129
- {
130
- ss << "DELETE_SELF ";
131
- }
132
- if (mask & IN_UNMOUNT)
133
- {
134
- ss << "UNMOUNT ";
135
- }
136
- if (mask & IN_Q_OVERFLOW)
137
- {
138
- ss << "Q_OVERFLOW ";
139
- }
140
- if (mask & IN_IGNORED)
141
- {
142
- ss << "IGNORED" ;
143
- }
144
- }
145
-
146
- /********************************************************************************/
147
- /********************************************************************************/
148
- /********************************************************************************/
149
-
150
- class KernelFileSystemMonitorDaemon
151
- {
152
- bool m_runInForground;
153
-
154
- #define ALL_MASK 0xffffffff
155
- int watch_mask;
156
- int dev_fd;
157
-
158
- unsigned long m_inotify_queue_threshold_bytes;
159
- unsigned long long m_inotify_queue_sleep_threshold_ns;
160
- unsigned long m_nanosleep_ns;
161
-
162
- void background_into_daemon();
163
-
164
- void priv_handle_event( struct inotify_event *pevent, time_t tt );
165
- void priv_Closedown();
166
-
167
- bool handle_create_subdir_event_by_maybe_watching( struct inotify_event *pevent, time_t tt );
168
-
169
- void HandleSleepForQueueSize();
170
-
171
- protected:
172
- typedef map< int, string > m_workingDirToURL_t;
173
- m_workingDirToURL_t m_workingDirToURL;
174
-
175
- typedef list< string > m_ignorePrefixes_t;
176
- m_ignorePrefixes_t m_ignorePrefixes;
177
-
178
- typedef list< string > stringlist_t;
179
- stringlist_t m_watchRoots;
180
-
181
- void print_event (struct inotify_event *event);
182
-
183
- bool shouldAddSubObject( int wd, const std::string& fn );
184
- virtual void candidateObject( int wd, const std::string& fn, struct stat& statbuf );
185
- virtual void setupWorkingDirToPersistentDirIDMapping( long wd, const string& earl ) = 0;
186
- virtual void event_batch_start( time_t tt );
187
- virtual void event_batch_end( time_t tt );
188
- virtual void handle_event( struct inotify_event *pevent, time_t tt ) = 0;
189
- virtual void Closedown();
190
-
191
- public:
192
- KernelFileSystemMonitorDaemon();
193
- ~KernelFileSystemMonitorDaemon();
194
-
195
- void setRunInForground( bool v );
196
-
197
- void setupWatches();
198
- void setupSignalHandlers();
199
- bool shouldWatch( const string& earl );
200
- void add_watches_recursive( const string& earl );
201
-
202
- void addIgnorePrefix( const string& s );
203
- void ParseWatchOptions( poptContext& optCon );
204
-
205
- int run();
206
-
207
-
208
- struct ::poptOption* getPopTable();
209
-
210
- };
211
-
212
- #endif