File: locks.man

package info (click to toggle)
libbash 0.9.11-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 776 kB
  • sloc: sh: 1,402; makefile: 53
file content (270 lines) | stat: -rw-r--r-- 6,237 bytes parent folder | download | duplicates (3)
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
.\" Process this file with
.\" groff -mdoc -Tascii <filename>
.\"
.Dd July 28, 2009
.Os Linux
.Dt LOCKS \&3 "libbash locks Library Manual"
.\"
.Sh NAME
.\"
.\"
.Nm locks
.Nd libbash library that implements locking (directory based).
.Pp
.Sy This library is not throughoutly tested - use with caution!
.\"
.\"
.Sh SYNOPSIS
.\"
.Bl -tag -compact -width 123456789012345
.\"
.It Cm dirInitLock
.Aq object
.Op Aq spin
.\"
.It Cm dirTryLock
.Aq object
.\"
.It Cm dirLock
.Aq object
.\"
.It Cm dirUnlock
.Aq object
.\"
.It Cm dirDestroyLock
.Aq object
.\"
.\"
.\"
.El
.\"
.\"
.Sh DESCRIPTION
.\"
.\" GENERAL
.Ss General
.Nm
is a collection of functions that implement locking (mutex like) in bash scripting language.
The whole idea is based on the fact that directory creation/removal is an atomic process.
The creation of this library was inspired by studying CVS locks management.
.Pp
Same lock object can by used by several processes to serialize access to some shared resource.
(Well, yeah, this what locks were invented for...) To actually do this, processes just need
to access lock object by the same name.
.Pp
.Ss Functions list:
.Bl -tag -width hashdelete12345 -offset ident
.It Sy dirInitLock
Initialize a lock object for your proccess
.It Sy dirTryLock
Try to lock the lock object - give up if its already locked
.It Sy dirLock
Lock the lock object - will block until object is unlocked
.It Sy dirUnlock
Unlock the lock object
.It Sy dirDestroyLock
Destroy the lock object - free resources
.El
.Pp
Detailed interface description follows.
.\"
.\"
.Sh FUNCTIONS DESCRIPTIONS
.\"
.\" dirInitLock SUBSECTION
.Ss Cm dirInitLock Ao Ns Fa object Ns Ac Bq Aq Ns Fa spin Ns
.\"
Initialize a lock object for your process.
Only after a lock is initialized, your proccess will be able to use it.
.\"
.Sy Notice: 
This action does not lock the object. 
.Pp
The lock can be set on two types of objects. The first is an existing directory.
In this case, Aq dir must be a path (relative or full). The path must contain a 
.Ql / .
The second is an abstract object used as a lock. In this case, the name of the lock will
not contain any 
.Ql / .
This can be used to create locks without creating real directories for them.
.\"
.Sy Notice: 
Do not call your lock object 
.Ql .lock .
.Pp
Parameters:
.Bl -tag -width 1 -offset 12
.It  Aq Ns Fa object Ns Li
The name of the lock object (either existing directory or abstract name)
.It  Aq Ns Fa spin Ns Li 
The time (in seconds) that the funtion 
.Em dirLock 
will wait between two runs of 
.Em dirTryLock .
This parameter is optional, and its value generally should be less then 1.
If ommited, a default value (0.01) is set.
.El
.Pp
Return Value:
.Bd -filled -offset 12
One of the following:
.Bl -tag -width 123 -compact
.It Sy 0 
The action finished successfully.
.It Sy 1
The action failed. You do not have permissions to preform it.
.It Sy 3
The directory path could not be resolved. Possibly parameter does 
contain 
.Ql / ,
but refers to directory that does not exist.
.El
.Ed
.\"
.\"
.\" dirTryLock SUBSECTION
.Ss Cm dirTryLock Aq  Ns Fa object Ns Li
.\"
Try to lock the lock object. The function always returns
immediately.
.Pp
Parameters:
.Bl -tag -width 1 -offset 12
.It Aq Ns Fa object Ns Li 
The object that the lock is set on.
.El
.Pp
Return Value:
.Bd -filled -offset 12
One of the following:
.Bl -tag -width 123 -compact
.It Sy 0
The action finished successfully.
.It Sy 1
The action failed. The object is already locked.
.It Sy 2
The action failed. Your proccess did not initialize a lock for the object.
.It Sy 3
The directory path could not be resolved.
.El
.Ed
.\"
.\"
.\" dirLock SUBSECTION
.Ss Cm dirLock Aq Ns Fa object Ns Li
.\"
Lock given lock object.
If the object is already locked - the function will block untill the object is unlocked.
After each try (dirTryLock) the function will sleep for spin seconds (spin is defined using 
.Em dirInitLock
).
.Pp
Parameters:
.Bl -tag -width 1 -offset 12
.It Aq Ns Fa object Ns Li
The directory that the lock is set on.
.El
.Pp
Return Value:
.Bd -filled -offset 12
One of the following:
.Bl -tag -width 123 -compact
.It Sy 0
The action finished successfully.
.It Sy 2
The action failed. Your proccess did not initialize a lock for the directory.
.It Sy 3
The directory path could not be resolved.
.El
.Ed
.\"
.\"
.\" dirUnlock SUBSECTION
.Ss Cm dirUnlock Aq Ns Fa dir Ns Li
.\"
Unlock the lock object.
.Pp
Parameters:
.Bl -tag -width 1 -offset 12
.It Aq Ns Fa object Ns Li
The object that the lock is set on.
.El
.Pp
Return Value:
.Bd -filled -offset 12
One of the following:
.Bl -tag -width 123 -compact
.It Sy 0
The action finished successfully.
.It Sy 2
The action failed. Your proccess did not initialize the lock.
.It Sy 3
The directory path could not be resolved.
.El
.Ed
.\"
.\"
.\" dirDestroyLock SUBSECTION
.Ss Cm dirDestroyLock Aq Ns Fa object Ns Li
.\"
Destroys the lock object.
After this action the proccess will no longer be able to use the lock object.
To use  the object after this action is done, one must initialize the lock,
using 
.Em dirInitLock .
.Pp
Parameters:
.Bl -tag -width 1 -offset 12
.It Aq Ns Fa object Ns Li 
The directory that the lock is set on.
.El
.Pp
Return Value:
.Bd -filled -offset 12
One of the following:
.Bl -tag -width 123 -compact
.It Sy 0
The action finished successfully.
.It Sy 1
The action failed. The directory is locked by your own proccess. Unlock it first.
.It Sy 2
The action failed. Your proccess did not initialize the lock.
.It Sy 3
The directory path could not be resolved.
.El
.Ed
.\"
.\"
.Sh EXAMPLES
.\"
.\"
Creating an abstract lock named mylock, with 0.1 second spintime:
.D1 $ dirInitLock mylock 0.1 # $?=0
Locking it:
.D1 $ dirLock mylock # $?=0
Trying once to lock it again:
.D1 $ dirTryLock mylock # $?=1
Trying to lock it again:
.D1 $ dirLock mylock # Will wait forever
Unlocking:
.D1 $ dirUnlock mylock # $?=0
Destroying the lock:
.D1 $ dirDestroyLock mylock # $?=0
Trying to lock again:
.D1 $ dirLock mylock # $?=2
Creating a lock on the directory ./mydir, with default spin time:
.D1 $ dirInitLock ./mydir # $?=0
.\"
.\"
.\"
.\"
.Sh AUTHORS
.\"
.\"
.An "Hai Zaar" Aq haizaar@haizaar.com
.An "Gil Ran" Aq gil@ran4.net
.\"
.\"
.Sh SEE ALSO
.Xr ldbash 1 ,
.Xr libbash 1