1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3
<title>sbuild: sbuild/sbuild-lock.h Source File</title>
4
<link href="tabs.css" rel="stylesheet" type="text/css">
5
<link href="doxygen.css" rel="stylesheet" type="text/css">
7
<!-- Generated by Doxygen 1.5.9 -->
8
<div class="navigation" id="top">
11
<li><a href="index.html"><span>Main Page</span></a></li>
12
<li><a href="pages.html"><span>Related Pages</span></a></li>
13
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
14
<li><a href="annotated.html"><span>Classes</span></a></li>
15
<li class="current"><a href="files.html"><span>Files</span></a></li>
16
<li><a href="dirs.html"><span>Directories</span></a></li>
21
<li><a href="files.html"><span>File List</span></a></li>
22
<li><a href="globals.html"><span>File Members</span></a></li>
25
<div class="navpath"><a class="el" href="dir_5769d7dd62c6719d79ec5ec7998dae58.html">sbuild</a>
28
<div class="contents">
29
<h1>sbuild-lock.h</h1><a href="sbuild-lock_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright © 2005-2007 Roger Leigh <rleigh@debian.org></span>
30
<a name="l00002"></a>00002 <span class="comment"> *</span>
31
<a name="l00003"></a>00003 <span class="comment"> * schroot is free software: you can redistribute it and/or modify it</span>
32
<a name="l00004"></a>00004 <span class="comment"> * under the terms of the GNU General Public License as published by</span>
33
<a name="l00005"></a>00005 <span class="comment"> * the Free Software Foundation, either version 3 of the License, or</span>
34
<a name="l00006"></a>00006 <span class="comment"> * (at your option) any later version.</span>
35
<a name="l00007"></a>00007 <span class="comment"> *</span>
36
<a name="l00008"></a>00008 <span class="comment"> * schroot is distributed in the hope that it will be useful, but</span>
37
<a name="l00009"></a>00009 <span class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</span>
38
<a name="l00010"></a>00010 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
39
<a name="l00011"></a>00011 <span class="comment"> * General Public License for more details.</span>
40
<a name="l00012"></a>00012 <span class="comment"> *</span>
41
<a name="l00013"></a>00013 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
42
<a name="l00014"></a>00014 <span class="comment"> * along with this program. If not, see</span>
43
<a name="l00015"></a>00015 <span class="comment"> * <http://www.gnu.org/licenses/>.</span>
44
<a name="l00016"></a>00016 <span class="comment"> *</span>
45
<a name="l00017"></a>00017 <span class="comment"> *********************************************************************/</span>
46
<a name="l00018"></a>00018
47
<a name="l00019"></a>00019 <span class="preprocessor">#ifndef SBUILD_LOCK_H</span>
48
<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define SBUILD_LOCK_H</span>
49
<a name="l00021"></a>00021 <span class="preprocessor"></span>
50
<a name="l00022"></a>00022 <span class="preprocessor">#include <<a class="code" href="sbuild-custom-error_8h.html">sbuild/sbuild-custom-error.h</a>></span>
51
<a name="l00023"></a>00023
52
<a name="l00024"></a>00024 <span class="preprocessor">#include <string></span>
53
<a name="l00025"></a>00025
54
<a name="l00026"></a>00026 <span class="preprocessor">#include <sys/time.h></span>
55
<a name="l00027"></a>00027 <span class="preprocessor">#include <fcntl.h></span>
56
<a name="l00028"></a>00028 <span class="preprocessor">#include <signal.h></span>
57
<a name="l00029"></a>00029
58
<a name="l00030"></a>00030 <span class="keyword">namespace </span>sbuild
59
<a name="l00031"></a>00031 {
60
<a name="l00032"></a>00032
61
<a name="l00037"></a><a class="code" href="classsbuild_1_1lock.html">00037</a> <span class="keyword">class </span><a class="code" href="classsbuild_1_1lock.html" title="Advisory locking.">lock</a>
62
<a name="l00038"></a>00038 {
63
<a name="l00039"></a>00039 <span class="keyword">public</span>:
64
<a name="l00041"></a><a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9">00041</a> <span class="keyword">enum</span> <a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9" title="Lock type.">type</a>
65
<a name="l00042"></a>00042 {
66
<a name="l00043"></a><a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a973a272d53c08adac5b44286cf39cf5b0">00043</a> <a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a973a272d53c08adac5b44286cf39cf5b0" title="A shared (read) lock.">LOCK_SHARED</a> = F_RDLCK,
67
<a name="l00044"></a><a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9521887538376a8970aa8c30947ac4fd1">00044</a> <a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9521887538376a8970aa8c30947ac4fd1" title="An exclusive (write) lock.">LOCK_EXCLUSIVE</a> = F_WRLCK,
68
<a name="l00045"></a><a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9ee7062940214451a6308be6457f1817b">00045</a> <a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9ee7062940214451a6308be6457f1817b" title="No lock.">LOCK_NONE</a> = F_UNLCK
69
<a name="l00046"></a>00046 };
70
<a name="l00047"></a>00047
71
<a name="l00049"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad">00049</a> <span class="keyword">enum</span> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad" title="Error codes.">error_code</a>
72
<a name="l00050"></a>00050 {
73
<a name="l00051"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad1aba1b3b4bf7fc9340eab1482037a52a">00051</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad1aba1b3b4bf7fc9340eab1482037a52a" title="Failed to set timeout handler.">TIMEOUT_HANDLER</a>,
74
<a name="l00052"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adbf17fa696d4bd7ba64be22af3988be12">00052</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adbf17fa696d4bd7ba64be22af3988be12" title="Failed to set timeout.">TIMEOUT_SET</a>,
75
<a name="l00053"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad1a2ec528212f871a66465fbfdf399e79">00053</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad1a2ec528212f871a66465fbfdf399e79" title="Failed to cancel timeout.">TIMEOUT_CANCEL</a>,
76
<a name="l00054"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adc3add0ddc3fd83957717c1438b8a29fd">00054</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adc3add0ddc3fd83957717c1438b8a29fd" title="Failed to lock file.">LOCK</a>,
77
<a name="l00055"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adca719b6c74156c027b079c781afc0056">00055</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adca719b6c74156c027b079c781afc0056" title="Failed to unlock file.">UNLOCK</a>,
78
<a name="l00056"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad11fce2183aeb9557387b2835401114f1">00056</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad11fce2183aeb9557387b2835401114f1" title="Failed to lock file (timed out).">LOCK_TIMEOUT</a>,
79
<a name="l00057"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adcf2c6644649d7ac489005753a60cf8f2">00057</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adcf2c6644649d7ac489005753a60cf8f2" title="Failed to unlock file (timed out).">UNLOCK_TIMEOUT</a>,
80
<a name="l00058"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad2526e9f4e7f3ae5abab02e6e4e25c66c">00058</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad2526e9f4e7f3ae5abab02e6e4e25c66c" title="Failed to lock device.">DEVICE_LOCK</a>,
81
<a name="l00059"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adaa29a1137199b2abfbd7a094cb5776be">00059</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adaa29a1137199b2abfbd7a094cb5776be" title="Failed to lock device (timed out).">DEVICE_LOCK_TIMEOUT</a>,
82
<a name="l00060"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad128a1e31e55230ce905767c87ea2a579">00060</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad128a1e31e55230ce905767c87ea2a579" title="Failed to test device lock.">DEVICE_TEST</a>,
83
<a name="l00061"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adc8f83356ad88748b1a0d1c44919c5005">00061</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0adc8f83356ad88748b1a0d1c44919c5005" title="Failed to unlock device.">DEVICE_UNLOCK</a>,
84
<a name="l00062"></a><a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad16d8c5ca2b0ee2ed2123d00dce581e1c">00062</a> <a class="code" href="classsbuild_1_1lock.html#d10227b655006fec0115c6ea7dc8a0ad16d8c5ca2b0ee2ed2123d00dce581e1c" title="Failed to unlock device (timed out).">DEVICE_UNLOCK_TIMEOUT</a>
85
<a name="l00063"></a>00063 };
86
<a name="l00064"></a>00064
87
<a name="l00066"></a><a class="code" href="classsbuild_1_1lock.html#720366c557ce305d98f400a44b6cc410">00066</a> <span class="keyword">typedef</span> <a class="code" href="classsbuild_1_1custom__error.html" title="Custom error.">custom_error<error_code></a> <a class="code" href="classsbuild_1_1custom__error.html" title="Custom error.">error</a>;
88
<a name="l00067"></a>00067
89
<a name="l00074"></a>00074 <span class="keyword">virtual</span> <span class="keywordtype">void</span>
90
<a name="l00075"></a>00075 <a class="code" href="classsbuild_1_1lock.html#2fecbce8474389e8ddc48efecd451ae4" title="Acquire a lock.">set_lock</a> (<a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9" title="Lock type.">type</a> lock_type,
91
<a name="l00076"></a>00076 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> timeout) = 0;
92
<a name="l00077"></a>00077
93
<a name="l00082"></a>00082 <span class="keyword">virtual</span> <span class="keywordtype">void</span>
94
<a name="l00083"></a>00083 <a class="code" href="classsbuild_1_1lock.html#cc6b19c17ddb9aa86c6298fc178737e6" title="Release a lock.">unset_lock</a> () = 0;
95
<a name="l00084"></a>00084
96
<a name="l00085"></a>00085 <span class="keyword">protected</span>:
97
<a name="l00087"></a>00087 <a class="code" href="classsbuild_1_1lock.html#50f07760e0ecc88f17310b820d38e7e3" title="The constructor.">lock</a> ();
98
<a name="l00089"></a>00089 <span class="keyword">virtual</span> <a class="code" href="classsbuild_1_1lock.html#9ae4b76aa090f41d326754ba647afaa7" title="The destructor.">~lock</a> ();
99
<a name="l00090"></a>00090
100
<a name="l00096"></a>00096 <span class="keywordtype">void</span>
101
<a name="l00097"></a>00097 <a class="code" href="classsbuild_1_1lock.html#f8465caad2c2f399faff84ac0c668d3d" title="Set the SIGALARM handler.">set_alarm</a> ();
102
<a name="l00098"></a>00098
103
<a name="l00103"></a>00103 <span class="keywordtype">void</span>
104
<a name="l00104"></a>00104 <a class="code" href="classsbuild_1_1lock.html#5416388f76405e6feda937f4dcf49b31" title="Restore the state of SIGALRM prior to starting lock acquisition.">clear_alarm</a> ();
105
<a name="l00105"></a>00105
106
<a name="l00115"></a>00115 <span class="keywordtype">void</span>
107
<a name="l00116"></a>00116 <a class="code" href="classsbuild_1_1lock.html#e43e1943eb30fb5f78cf86a06b41a216" title="Set up an itimer for future expiry.">set_timer</a> (<span class="keyword">struct</span> itimerval <span class="keyword">const</span>& timer);
108
<a name="l00117"></a>00117
109
<a name="l00124"></a>00124 <span class="keywordtype">void</span>
110
<a name="l00125"></a>00125 <a class="code" href="classsbuild_1_1lock.html#a61110b2f4f0b4028cb3642dab5ee9d8" title="Remove any itimer currently set up.">unset_timer</a> ();
111
<a name="l00126"></a>00126
112
<a name="l00127"></a>00127 <span class="keyword">private</span>:
113
<a name="l00129"></a><a class="code" href="classsbuild_1_1lock.html#fc0e611a5b18eb88ebba4c3bdcd74d9e">00129</a> <span class="keyword">struct </span>sigaction <a class="code" href="classsbuild_1_1lock.html#fc0e611a5b18eb88ebba4c3bdcd74d9e" title="Signals saved during timeout.">saved_signals</a>;
114
<a name="l00130"></a>00130 };
115
<a name="l00131"></a>00131
116
<a name="l00136"></a><a class="code" href="classsbuild_1_1file__lock.html">00136</a> <span class="keyword">class </span><a class="code" href="classsbuild_1_1file__lock.html" title="File lock.">file_lock</a> : <span class="keyword">public</span> <a class="code" href="classsbuild_1_1lock.html" title="Advisory locking.">lock</a>
117
<a name="l00137"></a>00137 {
118
<a name="l00138"></a>00138 <span class="keyword">public</span>:
119
<a name="l00144"></a>00144 <a class="code" href="classsbuild_1_1file__lock.html#7186e9ab070201236148022ed854abe7" title="The constructor.">file_lock</a> (<span class="keywordtype">int</span> <a class="code" href="classsbuild_1_1file__lock.html#3b5091c71442d4ee737649f2a6c673e2" title="The file descriptor to lock.">fd</a>);
120
<a name="l00145"></a>00145
121
<a name="l00147"></a>00147 <span class="keyword">virtual</span> <a class="code" href="classsbuild_1_1file__lock.html#e85c6ad6b25cb26bb51cfc96f085e6cc" title="The destructor.">~file_lock</a> ();
122
<a name="l00148"></a>00148
123
<a name="l00149"></a>00149 <span class="keyword">virtual</span> <span class="keywordtype">void</span>
124
<a name="l00150"></a>00150 <a class="code" href="classsbuild_1_1file__lock.html#11122738ba50f9ec91812799dea926cd" title="Acquire a lock.">set_lock</a> (<a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9" title="Lock type.">lock::type</a> lock_type,
125
<a name="l00151"></a>00151 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> timeout);
126
<a name="l00152"></a>00152
127
<a name="l00153"></a>00153 <span class="keyword">virtual</span> <span class="keywordtype">void</span>
128
<a name="l00154"></a>00154 <a class="code" href="classsbuild_1_1file__lock.html#5438aeb0cfe12bdd6693e52171db7943" title="Release a lock.">unset_lock</a> ();
129
<a name="l00155"></a>00155
130
<a name="l00156"></a>00156 <span class="keyword">private</span>:
131
<a name="l00158"></a><a class="code" href="classsbuild_1_1file__lock.html#3b5091c71442d4ee737649f2a6c673e2">00158</a> <span class="keywordtype">int</span> fd;
132
<a name="l00160"></a><a class="code" href="classsbuild_1_1file__lock.html#edbd92765c919ff416568875e30db071">00160</a> <span class="keywordtype">bool</span> <a class="code" href="classsbuild_1_1file__lock.html#edbd92765c919ff416568875e30db071" title="Is the file locked?">locked</a>;
133
<a name="l00161"></a>00161 };
134
<a name="l00162"></a>00162
135
<a name="l00169"></a><a class="code" href="classsbuild_1_1device__lock.html">00169</a> <span class="keyword">class </span><a class="code" href="classsbuild_1_1device__lock.html" title="Device lock.">device_lock</a> : <span class="keyword">public</span> <a class="code" href="classsbuild_1_1lock.html" title="Advisory locking.">lock</a>
136
<a name="l00170"></a>00170 {
137
<a name="l00171"></a>00171 <span class="keyword">public</span>:
138
<a name="l00177"></a>00177 <a class="code" href="classsbuild_1_1device__lock.html#1516398c3fdcda9622d4ce5b363c71d5" title="The constructor.">device_lock</a> (std::string <span class="keyword">const</span>& <a class="code" href="classsbuild_1_1device__lock.html#6f8308c5da0bfbf69222ca697f8d9d93" title="The device to lock.">device</a>);
139
<a name="l00178"></a>00178
140
<a name="l00180"></a>00180 <span class="keyword">virtual</span> <a class="code" href="classsbuild_1_1device__lock.html#c32c325b39071a29a1a5be1d2e389a07" title="The destructor.">~device_lock</a> ();
141
<a name="l00181"></a>00181
142
<a name="l00182"></a>00182 <span class="keyword">virtual</span> <span class="keywordtype">void</span>
143
<a name="l00183"></a>00183 <a class="code" href="classsbuild_1_1device__lock.html#c0c4a8c888e749ca672798347032bc24" title="Acquire a lock.">set_lock</a> (<a class="code" href="classsbuild_1_1lock.html#b6bc5fe9d9385747cc40de315bd810a9" title="Lock type.">lock::type</a> lock_type,
144
<a name="l00184"></a>00184 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> timeout);
145
<a name="l00185"></a>00185
146
<a name="l00186"></a>00186 <span class="keyword">virtual</span> <span class="keywordtype">void</span>
147
<a name="l00187"></a>00187 <a class="code" href="classsbuild_1_1device__lock.html#33dfb206677fa330a91c97cff07ea2fc" title="Release a lock.">unset_lock</a> ();
148
<a name="l00188"></a>00188
149
<a name="l00189"></a>00189 <span class="keyword">private</span>:
150
<a name="l00191"></a><a class="code" href="classsbuild_1_1device__lock.html#6f8308c5da0bfbf69222ca697f8d9d93">00191</a> std::string device;
151
<a name="l00193"></a><a class="code" href="classsbuild_1_1device__lock.html#c557fbee066108f9d32450773158486d">00193</a> <span class="keywordtype">bool</span> <a class="code" href="classsbuild_1_1device__lock.html#c557fbee066108f9d32450773158486d" title="Is the file locked?">locked</a>;
152
<a name="l00194"></a>00194 };
153
<a name="l00195"></a>00195
154
<a name="l00196"></a>00196 }
155
<a name="l00197"></a>00197
156
<a name="l00198"></a>00198 <span class="preprocessor">#endif </span><span class="comment">/* SBUILD_LOCK_H */</span>
157
<a name="l00199"></a>00199
158
<a name="l00200"></a>00200 <span class="comment">/*</span>
159
<a name="l00201"></a>00201 <span class="comment"> * Local Variables:</span>
160
<a name="l00202"></a>00202 <span class="comment"> * mode:C++</span>
161
<a name="l00203"></a>00203 <span class="comment"> * End:</span>
162
<a name="l00204"></a>00204 <span class="comment"> */</span>
164
<hr size="1"><address style="text-align: right;"><small>Generated on Sun May 17 18:38:55 2009 for sbuild by
165
<a href="http://www.doxygen.org/index.html">
166
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>