Debian Codegraph @

doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-inodewatch2.xml

raw
1 <?xml version='1.0'?>
2 <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
3 ]>
4
5
6 <section id="inodewatch2sect">
7 <title>Monitoring Changes to File Attributes</title>
8
9 <indexterm>
10 <primary>script examples</primary>
11 <secondary>monitoring changes to file attributes</secondary>
12 </indexterm>
13
14 <indexterm>
15 <primary>examples of SystemTap scripts</primary>
16 <secondary>monitoring changes to file attributes</secondary>
17 </indexterm>
18
19 <indexterm>
20 <primary>monitoring changes to file attributes</primary>
21 <secondary>examples of SystemTap scripts</secondary>
22 </indexterm>
23
24 <indexterm>
25 <primary>changes to file attributes, monitoring</primary>
26 <secondary>examples of SystemTap scripts</secondary>
27 </indexterm>
28
29 <indexterm>
30 <primary>file attributes, monitoring changes to</primary>
31 <secondary>examples of SystemTap scripts</secondary>
32 </indexterm>
33
34
35 <remark>
36 WAR STORY: monitoring more inode activity http://sourceware.org/systemtap/wiki/WSFileMonitor2?highlight=((WarStories))
37 </remark>
38
39 <remark>
40 no script in examples
41 </remark>
42
43
44 <para>This section describes how to monitor if any processes are changing the attributes of a targeted file, in real time. </para>
45
46 <formalpara id="inodewatch2">
47 <title>inodewatch2.stp</title>
48 <para>
49 <programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/io/inodewatch2.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
50 </para>
51 </formalpara>
52
53 <para>Like <xref linkend="inodewatch"/> from <xref linkend="inodewatchsect"/>, <xref linkend="inodewatch2"/> takes the targeted file's device number (in integer format) and <command>inode</command> number as arguments. For more information on how to retrieve this information, refer to <xref linkend="inodewatchsect"/>.</para>
54
55 <para>The output for <xref linkend="inodewatch2"/> is similar to that of <xref linkend="inodewatch"/>, except that <xref linkend="inodewatch2"/> also contains the attribute changes to the monitored file, as well as the ID of the user responsible (<command>uid()</command>). <xref linkend="inodewatch2output"/> shows the output of <xref linkend="inodewatch2"/> while monitoring <filename>/home/joe/bigfile</filename> when user <computeroutput>joe</computeroutput> executes <command>chmod 777 /home/joe/bigfile</command> and <command>chmod 666 /home/joe/bigfile</command>.</para>
56
57
58
59 <example id="inodewatch2output">
60 <title><xref linkend="inodewatch2"/> Sample Output</title>
61 <screen>chmod(17448) inode_setattr 0x800005/6011835 100777 500
62 chmod(17449) inode_setattr 0x800005/6011835 100666 500</screen>
63 </example>
64 <!--
65 global ATTR_MODE = 1
66
67 probe kernel.function("inode_setattr") {
68 dev_nr = $inode->i_sb->s_dev
69 inode_nr = $inode->i_ino
70
71 if (dev_nr == ($1 &lt;&lt; 20 | $2) # major/minor device
72 &amp;&amp; inode_nr == $3
73 &amp;&amp; $attr->ia_valid &amp; ATTR_MODE)
74 printf ("%s(%d) %s 0x%x/%u %o %d\n",
75 execname(), pid(), probefunc(), dev_nr, inode_nr, $attr->ia_mode, uid())
76 }
77
78
79 -->
80
81 </section>
82