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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>SystemTap: io.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<h1>io.c</h1><a href="io_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef _IO_C_ </span><span class="comment">/* -*- linux-c -*- */</span>
00002 <span class="preprocessor">#define _IO_C_</span>
00003 <span class="preprocessor"></span>
00004 <span class="preprocessor">#include "relay-app.h"</span>
00005 <span class="preprocessor">#include "print.c"</span>
00006 <span class="comment"></span>
00007 <span class="comment">/** @file io.c</span>
00008 <span class="comment"> * @brief I/O functions</span>
00009 <span class="comment"> */</span><span class="comment"></span>
00010 <span class="comment">/** @addtogroup io I/O</span>
00011 <span class="comment"> * I/O functions</span>
00012 <span class="comment"> * @{</span>
00013 <span class="comment"> */</span>
00014 <span class="comment"></span>
00015 <span class="comment">/** private buffer for _stp_log() */</span>
<a name="l00016"></a><a class="code" href="group__io.html#ga9">00016</a> <span class="preprocessor">#define STP_LOG_BUF_LEN 2047</span>
00017 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">char</span> _stp_lbuf[NR_CPUS][<a class="code" href="group__io.html#ga9">STP_LOG_BUF_LEN</a> + 1];
00018 <span class="comment"></span>
00019 <span class="comment">/** Logs Data.</span>
00020 <span class="comment"> * This function prints to the system log if stpd has not connected</span>
00021 <span class="comment"> * yet. Otherwise it sends the message immediately to stpd.</span>
00022 <span class="comment"> * @param fmt A variable number of args.</span>
00023 <span class="comment"> * @note Lines are limited in length by printk buffer. If there is</span>
00024 <span class="comment"> * no newline in the format string, then other syslog output could</span>
00025 <span class="comment"> * get appended to the SystemTap line.</span>
00026 <span class="comment"> * @todo Evaluate if this function is necessary.</span>
00027 <span class="comment"> */</span>
00028
<a name="l00029"></a><a class="code" href="group__io.html#ga2">00029</a> <span class="keywordtype">void</span> <a class="code" href="group__io.html#ga2">_stp_log</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, ...)
00030 {
00031 <span class="keywordtype">int</span> num;
00032 <span class="keywordtype">char</span> *buf = &_stp_lbuf[smp_processor_id()][0];
00033 va_list args;
00034 va_start(args, fmt);
00035 num = vscnprintf (buf, <a class="code" href="group__io.html#ga9">STP_LOG_BUF_LEN</a>, fmt, args);
00036 va_end(args);
00037 buf[num] = <span class="charliteral">'\0'</span>;
00038
00039 <span class="keywordflow">if</span> (app.logging)
00040 send_reply (STP_REALTIME_DATA, buf, num + 1, stpd_pid);
00041 <span class="keywordflow">else</span>
00042 printk(<span class="stringliteral">"STP: %s"</span>, buf);
00043 }
00044
00045 <span class="keyword">static</span> <span class="keywordtype">void</span> stpd_app_started(<span class="keywordtype">void</span>)
00046 {
00047 printk (<span class="stringliteral">"stpd has started.\n"</span>);
00048 }
00049
00050 <span class="keyword">static</span> <span class="keywordtype">void</span> stpd_app_stopped(<span class="keywordtype">void</span>)
00051 {
00052 printk (<span class="stringliteral">"stpd has stopped.\n"</span>);
00053 }
00054
00055 <span class="keyword">static</span> <span class="keywordtype">void</span> probe_exit(<span class="keywordtype">void</span>);
00056
00057 <span class="preprocessor">#include <linux/delay.h></span>
00058 <span class="keyword">static</span> <span class="keywordtype">int</span> stpd_command (<span class="keywordtype">int</span> type, <span class="keywordtype">void</span> *data)
00059 {
00060 <span class="keywordflow">if</span> (type == STP_EXIT) {
00061 printk (<span class="stringliteral">"STP_EXIT received\n"</span>);
00062 probe_exit();
00063 <span class="preprocessor">#ifndef STP_NETLINK_ONLY</span>
00064 <span class="preprocessor"></span> relay_flush(app.chan);
00065 ssleep(2); <span class="comment">/* FIXME: time for data to be flushed */</span>
00066 <span class="preprocessor">#endif</span>
00067 <span class="preprocessor"></span> send_reply (STP_EXIT, __this_module.name, strlen(__this_module.name) + 1, stpd_pid);
00068 <span class="keywordflow">return</span> 1;
00069 }
00070 <span class="keywordflow">return</span> 0;
00071 }
00072
00073 <span class="comment">/*</span>
00074 <span class="comment"> * relay-app callbacks</span>
00075 <span class="comment"> */</span>
00076 <span class="keyword">static</span> <span class="keyword">struct </span>relay_app_callbacks stp_callbacks =
00077 {
00078 .app_started = stpd_app_started,
00079 .app_stopped = stpd_app_stopped,
00080 .user_command = stpd_command
00081 };
00082 <span class="comment"></span>
00083 <span class="comment">/** Opens netlink and relayfs connections to stpd.</span>
00084 <span class="comment"> * This must be called before any I/O is done, probably </span>
00085 <span class="comment"> * at the start of module initialization.</span>
00086 <span class="comment"> */</span>
<a name="l00087"></a><a class="code" href="group__io.html#ga7">00087</a> <span class="keywordtype">int</span> <a class="code" href="group__io.html#ga7">_stp_netlink_open</a>(<span class="keywordtype">void</span>)
00088 {
00089 <span class="keywordflow">if</span> (init_relay_app(<span class="stringliteral">"stpd"</span>, <span class="stringliteral">"cpu"</span>, &stp_callbacks)) {
00090 printk (<span class="stringliteral">"STP: couldn't init relay app\n"</span>);
00091 <span class="keywordflow">return</span> -1;
00092 }
00093 <span class="keywordflow">return</span> 0;
00094 }
00095 <span class="comment"></span>
00096 <span class="comment">/** Closes netlink and relayfs connections to stpd.</span>
00097 <span class="comment"> * This must be called after all I/O is done, probably </span>
00098 <span class="comment"> * at the end of module cleanup.</span>
00099 <span class="comment"> * @returns 0 on success. -1 if there is a problem establishing</span>
00100 <span class="comment"> * a connection.</span>
00101 <span class="comment"> */</span>
00102
<a name="l00103"></a><a class="code" href="group__io.html#ga8">00103</a> <span class="keywordtype">void</span> <a class="code" href="group__io.html#ga8">_stp_netlink_close</a> (<span class="keywordtype">void</span>)
00104 {
00105 send_reply (STP_DONE, NULL, 0, stpd_pid);
00106 close_relay_app();
00107 }
00108 <span class="comment"></span>
00109 <span class="comment">/** @} */</span>
00110 <span class="preprocessor">#endif </span><span class="comment">/* _IO_C_ */</span>
</pre></div></body></html>
|