Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/file-lock.h @ 8590:b9faf4db2a9f HEAD
Updated copyright notices to include year 2009.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 06 Jan 2009 09:25:38 -0500 |
parents | f472f9ad69be |
children |
rev | line source |
---|---|
6410
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
1 #ifndef FILE_LOCK_H |
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
2 #define FILE_LOCK_H |
222
cf4d065f2f85
lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 |
cf4d065f2f85
lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include <unistd.h> |
cf4d065f2f85
lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include <fcntl.h> |
cf4d065f2f85
lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 |
490
fd0181ae25f6
file_wait_lock() now takes timeout-parameter so one badly behaving process
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
7 #define DEFAULT_LOCK_TIMEOUT 120 |
fd0181ae25f6
file_wait_lock() now takes timeout-parameter so one badly behaving process
Timo Sirainen <tss@iki.fi>
parents:
222
diff
changeset
|
8 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
9 struct file_lock; |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
10 |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
11 enum file_lock_method { |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
12 FILE_LOCK_METHOD_FCNTL, |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
13 FILE_LOCK_METHOD_FLOCK, |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
14 FILE_LOCK_METHOD_DOTLOCK |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
15 }; |
222
cf4d065f2f85
lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
8264
f472f9ad69be
Moved file lock type string parsing code to file-lock.c
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
17 /* Parse lock method from given string. Returns TRUE if ok, |
f472f9ad69be
Moved file lock type string parsing code to file-lock.c
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
18 FALSE if name is unknown. */ |
f472f9ad69be
Moved file lock type string parsing code to file-lock.c
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
19 bool file_lock_method_parse(const char *name, enum file_lock_method *method_r); |
f472f9ad69be
Moved file lock type string parsing code to file-lock.c
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
20 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
21 /* Lock the file. Returns 1 if successful, 0 if file is already locked, |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
22 or -1 if error. lock_type is F_WRLCK or F_RDLCK. */ |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
23 int file_try_lock(int fd, const char *path, int lock_type, |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
24 enum file_lock_method lock_method, |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
25 struct file_lock **lock_r); |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
26 /* Like lock_try_lock(), but return 0 only after having tried to lock for |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
27 timeout_secs. */ |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
28 int file_wait_lock(int fd, const char *path, int lock_type, |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
29 enum file_lock_method lock_method, |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
30 unsigned int timeout_secs, |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
31 struct file_lock **lock_r); |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
32 /* Change the lock type. */ |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
33 int file_lock_try_update(struct file_lock *lock, int lock_type); |
674
b7aefd0d7611
Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents:
490
diff
changeset
|
34 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
35 /* Unlock and free the lock. */ |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
36 void file_unlock(struct file_lock **lock); |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
37 /* Free the lock without unlocking it (because you're closing the fd anyway). */ |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
953
diff
changeset
|
38 void file_lock_free(struct file_lock **lock); |
222
cf4d065f2f85
lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 |
cf4d065f2f85
lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 #endif |