1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>logfs.fstracer — Autodep documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<link rel="top" title="Autodep documentation" href="../../index.html" />
<link rel="up" title="Module code" href="../index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">Autodep</a> »</li>
<li><a href="../index.html" accesskey="U">Module code</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<h1>Source code for logfs.fstracer</h1><div class="highlight"><pre>
<span class="c">#!/usr/bin/env python2</span>
<span class="sd">"""</span>
<span class="sd">This module is a bridge between low-level logging services and high level </span>
<span class="sd">handling dependency logic.</span>
<span class="sd">It can be used to launch a program and get all file events</span>
<span class="sd">"""</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">stat</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">tempfile</span>
<span class="kn">import</span> <span class="nn">socket</span>
<span class="kn">import</span> <span class="nn">select</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">signal</span>
<span class="kn">import</span> <span class="nn">logger_hooklib</span>
<span class="kn">import</span> <span class="nn">logger_fusefs</span>
<span class="n">stop</span><span class="o">=</span><span class="bp">False</span><span class="p">;</span>
<span class="n">stoptime</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">def</span> <span class="nf">parse_message</span><span class="p">(</span><span class="n">message</span><span class="p">):</span>
<span class="n">ret</span><span class="o">=</span><span class="n">message</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">"</span><span class="se">\0</span><span class="s">"</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span>
<span class="c">#check if process is zombie</span>
<span class="k">def</span> <span class="nf">iszombie</span><span class="p">(</span><span class="n">pid</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">statfile</span><span class="o">=</span><span class="nb">open</span><span class="p">(</span><span class="s">"/proc/</span><span class="si">%d</span><span class="s">/stat"</span> <span class="o">%</span> <span class="n">pid</span><span class="p">,</span><span class="s">"r"</span><span class="p">)</span>
<span class="n">line</span><span class="o">=</span><span class="n">statfile</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
<span class="n">statfile</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">line</span><span class="o">=</span><span class="n">line</span><span class="o">.</span><span class="n">rsplit</span><span class="p">(</span><span class="s">")"</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span> <span class="c"># find last ")" char</span>
<span class="n">line</span><span class="o">=</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="n">match</span><span class="o">=</span><span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s">r"^(\w)"</span><span class="p">,</span><span class="n">line</span><span class="p">)</span>
<span class="k">if</span> <span class="n">match</span><span class="o">==</span><span class="bp">None</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"Failed to get check if process is zombie. Format of /proc/<pid>/stat is incorrect. Did you change a kernel?"</span>
<span class="k">return</span> <span class="bp">False</span>
<span class="k">return</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">==</span><span class="s">"Z"</span>
<span class="k">except</span> <span class="ne">IOError</span><span class="p">,</span><span class="n">e</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">True</span>
<span class="c"># default access filter. Allow acess to all files</span>
<span class="k">def</span> <span class="nf">defaultfilter</span><span class="p">(</span><span class="n">eventname</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">stage</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">True</span>
<div class="viewcode-block" id="getfsevents"><a class="viewcode-back" href="../../api.html#logfs.fstracer.getfsevents">[docs]</a><span class="k">def</span> <span class="nf">getfsevents</span><span class="p">(</span><span class="n">prog_name</span><span class="p">,</span><span class="n">arguments</span><span class="p">,</span><span class="n">approach</span><span class="o">=</span><span class="s">"hooklib"</span><span class="p">,</span><span class="n">filterproc</span><span class="o">=</span><span class="n">defaultfilter</span><span class="p">):</span>
<span class="sd">""" </span>
<span class="sd"> Launches a program and gets file access events</span>
<span class="sd"> :param prog_name: name of program</span>
<span class="sd"> :param arguments: list of program's arguments</span>
<span class="sd"> :param approach: a logging approach('hooklib' or 'fusefs')</span>
<span class="sd"> :param filterproc: filter function, this function should take 3 strings:</span>
<span class="sd"> name of event, name of file and stage, and return a *True* if event is </span>
<span class="sd"> allowed and *False* instead. Name of event is one of *'open'*, *'read'* or</span>
<span class="sd"> *'write'*. Default function always returns *True*. </span>
<span class="sd"> :returns: **list** with two elements - *success* events and *failed* events.</span>
<span class="sd"> Each element is dictionary **stage->file information**.</span>
<span class="sd"> File information is also a dictionary **filename->type of events**.</span>
<span class="sd"> Type of events for success events is a 2-element tuple: *(was file readed,</span>
<span class="sd"> was file writed)*. For failed events it is also 2-element tuple:</span>
<span class="sd"> *(was file not found, was file blocked by filterproc)*. Each element of </span>
<span class="sd"> tuple can be *True* or *False*. Both elements of tuple can be *False*.</span>
<span class="sd"> Stage can be *'unknown'*</span>
<span class="sd"> """</span>
<span class="n">events</span><span class="o">=</span><span class="p">{}</span>
<span class="c"># generate a random socketname</span>
<span class="n">tmpdir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">()</span>
<span class="n">socketname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tmpdir</span><span class="p">,</span> <span class="s">'socket'</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">sock_listen</span><span class="o">=</span><span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">AF_UNIX</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SOCK_SEQPACKET</span><span class="p">)</span>
<span class="n">sock_listen</span><span class="o">.</span><span class="n">setsockopt</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">SOL_SOCKET</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SO_REUSEADDR</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">sock_listen</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">socketname</span><span class="p">)</span>
<span class="n">sock_listen</span><span class="o">.</span><span class="n">listen</span><span class="p">(</span><span class="mi">64</span><span class="p">)</span>
<span class="c"># enable connect a socket for anyone</span>
<span class="n">os</span><span class="o">.</span><span class="n">chmod</span><span class="p">(</span><span class="n">tmpdir</span><span class="p">,</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IRUSR</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IWUSR</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IXUSR</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IROTH</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IWOTH</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IXOTH</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">chmod</span><span class="p">(</span><span class="n">socketname</span><span class="p">,</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IRUSR</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IWUSR</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IXUSR</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IROTH</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IWOTH</span><span class="o">|</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IXOTH</span><span class="p">)</span>
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"Failed to create a socket for exchange data with the logger: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">e</span>
<span class="k">return</span> <span class="p">[]</span>
<span class="k">else</span><span class="p">:</span>
<span class="c">#print socketname</span>
<span class="n">pid</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">fork</span><span class="p">()</span>
<span class="k">if</span> <span class="n">pid</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
<span class="n">logger</span><span class="o">=</span><span class="bp">None</span>
<span class="k">if</span> <span class="n">approach</span><span class="o">==</span><span class="s">"hooklib"</span><span class="p">:</span>
<span class="n">logger</span><span class="o">=</span><span class="n">logger_hooklib</span><span class="o">.</span><span class="n">logger</span><span class="p">(</span><span class="n">socketname</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">approach</span><span class="o">==</span><span class="s">"fusefs"</span><span class="p">:</span>
<span class="n">logger</span><span class="o">=</span><span class="n">logger_fusefs</span><span class="o">.</span><span class="n">logger</span><span class="p">(</span><span class="n">socketname</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"Unknown logging approach"</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">execprog</span><span class="p">(</span><span class="n">prog_name</span><span class="p">,</span><span class="n">arguments</span><span class="p">)</span>
<span class="c"># should not get here</span>
<span class="k">print</span> <span class="s">"Launch likely was unsuccessful"</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">signal_handler</span><span class="p">(</span><span class="n">sig</span><span class="p">,</span> <span class="n">frame</span><span class="p">):</span>
<span class="k">print</span> <span class="s">"You pressed Ctrl+C!"</span>
<span class="k">global</span> <span class="n">stoptime</span>
<span class="k">if</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">stoptime</span><span class="o">></span><span class="mi">5</span><span class="p">):</span>
<span class="k">print</span> <span class="s">"Sending SIGINT to child"</span>
<span class="k">print</span> <span class="s">"Press again in 5 seconds to force exit"</span>
<span class="n">stoptime</span><span class="o">=</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"Sending SIGKILL to child"</span>
<span class="n">os</span><span class="o">.</span><span class="n">kill</span><span class="p">(</span><span class="n">pid</span><span class="p">,</span><span class="n">signal</span><span class="o">.</span><span class="n">SIGKILL</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">_exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">signal</span> <span class="c"># signal must to be in this scope</span>
<span class="c"># global signal not works</span>
<span class="n">signal</span><span class="o">.</span><span class="n">signal</span><span class="p">(</span><span class="n">signal</span><span class="o">.</span><span class="n">SIGINT</span><span class="p">,</span> <span class="n">signal_handler</span><span class="p">)</span>
<span class="n">epoll</span><span class="o">=</span><span class="n">select</span><span class="o">.</span><span class="n">epoll</span><span class="p">()</span>
<span class="n">epoll</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">sock_listen</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">select</span><span class="o">.</span><span class="n">EPOLLIN</span><span class="p">)</span>
<span class="n">connects</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">clients</span><span class="o">=</span><span class="p">{}</span>
<span class="n">was_first_connect</span><span class="o">=</span><span class="bp">False</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">sock_events</span> <span class="o">=</span> <span class="n">epoll</span><span class="o">.</span><span class="n">poll</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="k">for</span> <span class="n">fileno</span><span class="p">,</span> <span class="n">sock_event</span> <span class="ow">in</span> <span class="n">sock_events</span><span class="p">:</span>
<span class="k">if</span> <span class="n">fileno</span> <span class="o">==</span> <span class="n">sock_listen</span><span class="o">.</span><span class="n">fileno</span><span class="p">():</span>
<span class="c">#print "\n\nEVENT\n\n"</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">sock_listen</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span>
<span class="c">#print ret</span>
<span class="k">if</span> <span class="n">ret</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="c"># print "\n\nPASS\n\n"</span>
<span class="k">pass</span>
<span class="k">else</span><span class="p">:</span>
<span class="p">(</span><span class="n">client</span><span class="p">,</span><span class="n">addr</span><span class="p">)</span><span class="o">=</span><span class="n">ret</span>
<span class="c"># print client</span>
<span class="n">connects</span><span class="o">+=</span><span class="mi">1</span><span class="p">;</span> <span class="c"># client accepted</span>
<span class="n">was_first_connect</span><span class="o">=</span><span class="bp">True</span>
<span class="n">epoll</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">select</span><span class="o">.</span><span class="n">EPOLLIN</span><span class="p">)</span>
<span class="n">clients</span><span class="p">[</span><span class="n">client</span><span class="o">.</span><span class="n">fileno</span><span class="p">()]</span><span class="o">=</span><span class="n">client</span>
<span class="c">#print "opened %d" % client.fileno()</span>
<span class="c">#elif sock_event & select.EPOLLHUP:</span>
<span class="c">#epoll.unregister(fileno)</span>
<span class="c">#clients[fileno].close()</span>
<span class="c">#del clients[fileno]</span>
<span class="c">#connects-=1</span>
<span class="k">elif</span> <span class="n">sock_event</span> <span class="o">&</span> <span class="n">select</span><span class="o">.</span><span class="n">EPOLLIN</span><span class="p">:</span>
<span class="n">s</span><span class="o">=</span><span class="n">clients</span><span class="p">[</span><span class="n">fileno</span><span class="p">]</span>
<span class="n">record</span><span class="o">=</span><span class="n">s</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">8192</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">record</span><span class="p">:</span> <span class="c"># if connection was closed</span>
<span class="n">epoll</span><span class="o">.</span><span class="n">unregister</span><span class="p">(</span><span class="n">fileno</span><span class="p">)</span>
<span class="n">clients</span><span class="p">[</span><span class="n">fileno</span><span class="p">]</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">del</span> <span class="n">clients</span><span class="p">[</span><span class="n">fileno</span><span class="p">]</span>
<span class="n">connects</span><span class="o">-=</span><span class="mi">1</span>
<span class="c">#print "closed %d"%fileno</span>
<span class="k">continue</span>
<span class="n">message</span><span class="o">=</span><span class="n">record</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">"</span><span class="se">\0</span><span class="s">"</span><span class="p">)</span>
<span class="c">#if message[3]=="compile": #and message[1]=="debug":</span>
<span class="c">#print message</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">if</span> <span class="n">message</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span><span class="o">==</span><span class="s">"ASKING"</span><span class="p">:</span>
<span class="k">if</span> <span class="n">filterproc</span><span class="p">(</span><span class="n">message</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">message</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="n">message</span><span class="p">[</span><span class="mi">3</span><span class="p">]):</span>
<span class="c">#print "Allowing an access to %s" % message[2]</span>
<span class="n">s</span><span class="o">.</span><span class="n">sendall</span><span class="p">(</span><span class="s">"ALLOW</span><span class="se">\0</span><span class="s">"</span><span class="p">);</span> <span class="c"># TODO: think about flush here</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"Blocking an access to </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">message</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="n">s</span><span class="o">.</span><span class="n">sendall</span><span class="p">(</span><span class="s">"DENY</span><span class="se">\0</span><span class="s">"</span><span class="p">);</span> <span class="c"># TODO: think about flush here</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">eventname</span><span class="p">,</span><span class="n">filename</span><span class="p">,</span><span class="n">stage</span><span class="p">,</span><span class="n">result</span><span class="o">=</span><span class="n">message</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">stage</span> <span class="ow">in</span> <span class="n">events</span><span class="p">:</span>
<span class="n">events</span><span class="p">[</span><span class="n">stage</span><span class="p">]</span><span class="o">=</span><span class="p">[{},{}]</span>
<span class="n">hashofsucesses</span><span class="o">=</span><span class="n">events</span><span class="p">[</span><span class="n">stage</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="n">hashoffailures</span><span class="o">=</span><span class="n">events</span><span class="p">[</span><span class="n">stage</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
<span class="k">if</span> <span class="n">result</span><span class="o">==</span><span class="s">"OK"</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">hashofsucesses</span><span class="p">:</span>
<span class="n">hashofsucesses</span><span class="p">[</span><span class="n">filename</span><span class="p">]</span><span class="o">=</span><span class="p">[</span><span class="bp">False</span><span class="p">,</span><span class="bp">False</span><span class="p">]</span>
<span class="n">readed_or_writed</span><span class="o">=</span><span class="n">hashofsucesses</span><span class="p">[</span><span class="n">filename</span><span class="p">]</span>
<span class="k">if</span> <span class="n">eventname</span><span class="o">==</span><span class="s">"read"</span><span class="p">:</span>
<span class="n">readed_or_writed</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="bp">True</span>
<span class="k">elif</span> <span class="n">eventname</span><span class="o">==</span><span class="s">"write"</span><span class="p">:</span>
<span class="n">readed_or_writed</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="bp">True</span>
<span class="k">elif</span> <span class="n">result</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span><span class="o">==</span><span class="s">"ERR"</span> <span class="ow">or</span> <span class="n">result</span><span class="o">==</span><span class="s">"DENIED"</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">hashoffailures</span><span class="p">:</span>
<span class="n">hashoffailures</span><span class="p">[</span><span class="n">filename</span><span class="p">]</span><span class="o">=</span><span class="p">[</span><span class="bp">False</span><span class="p">,</span><span class="bp">False</span><span class="p">]</span>
<span class="n">notfound_or_blocked</span><span class="o">=</span><span class="n">hashoffailures</span><span class="p">[</span><span class="n">filename</span><span class="p">]</span>
<span class="k">if</span> <span class="n">result</span><span class="o">==</span><span class="s">"ERR/2"</span><span class="p">:</span>
<span class="n">notfound_or_blocked</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="bp">True</span>
<span class="k">elif</span> <span class="n">result</span><span class="o">==</span><span class="s">"DENIED"</span><span class="p">:</span>
<span class="n">notfound_or_blocked</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="bp">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"Error in logger module<->analyser protocol"</span>
<span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"IndexError while parsing </span><span class="si">%s</span><span class="s">"</span><span class="o">%</span><span class="n">record</span>
<span class="k">except</span> <span class="ne">IOError</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
<span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">errno</span><span class="o">!=</span><span class="mi">4</span><span class="p">:</span> <span class="c"># handling "Interrupted system call" errors</span>
<span class="k">raise</span>
<span class="k">if</span> <span class="n">was_first_connect</span> <span class="ow">and</span> <span class="n">connects</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
<span class="k">break</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">sock_events</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">clients</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
<span class="c"># # seems like there is no connect</span>
<span class="k">print</span> <span class="s">"It seems like a logger module was unable to start or failed to finish</span><span class="se">\n</span><span class="s">"</span> <span class="o">+</span> \
<span class="s">"Check that you are not launching a suid program under non-root user."</span>
<span class="k">return</span> <span class="p">[]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">clients</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span> <span class="ow">and</span> <span class="n">iszombie</span><span class="p">(</span><span class="n">pid</span><span class="p">):</span>
<span class="k">break</span>
<span class="n">epoll</span><span class="o">.</span><span class="n">unregister</span><span class="p">(</span><span class="n">sock_listen</span><span class="o">.</span><span class="n">fileno</span><span class="p">())</span>
<span class="n">epoll</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">sock_listen</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">_</span><span class="p">,</span> <span class="n">exit_status</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">waitpid</span><span class="p">(</span><span class="n">pid</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">signal</span><span class="p">,</span><span class="n">exit_status</span><span class="o">=</span><span class="n">exit_status</span><span class="o">%</span><span class="mi">256</span><span class="p">,</span><span class="n">exit_status</span><span class="o">/</span><span class="mi">256</span>
<span class="k">print</span> <span class="s">"Signal: </span><span class="si">%s</span><span class="s"> Exit status: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">signal</span><span class="p">,</span><span class="n">exit_status</span><span class="p">)</span>
<span class="k">return</span> <span class="n">events</span>
</pre></div></div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">Autodep</a> »</li>
<li><a href="../index.html" >Module code</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2011, Alexander Bersenev.
Last updated on Aug 20, 2011.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
</div>
</body>
</html>
|