Mercurial > dovecot > core-2.2
annotate src/lib/file-create-locked.h @ 22664:fea53c2725c0
director: Fix director_max_parallel_moves/kicks type
Should be uint, not time.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 09 Nov 2017 12:24:16 +0200 |
parents | 99a2b945045f |
children |
rev | line source |
---|---|
18740 | 1 #ifndef FILE_CREATE_LOCKED_H |
2 #define FILE_CREATE_LOCKED_H | |
3 | |
18744
57f8c2a6209b
lib: file_create_locked() lock method is now configurable
Timo Sirainen <tss@iki.fi>
parents:
18740
diff
changeset
|
4 #include "file-lock.h" |
18740 | 5 |
6 struct file_create_settings { | |
7 /* 0 = try locking without waiting */ | |
8 unsigned int lock_timeout_secs; | |
9 | |
18744
57f8c2a6209b
lib: file_create_locked() lock method is now configurable
Timo Sirainen <tss@iki.fi>
parents:
18740
diff
changeset
|
10 enum file_lock_method lock_method; |
18740 | 11 /* 0 = 0600 */ |
12 int mode; | |
13 /* 0 = default */ | |
14 uid_t uid; | |
15 /* 0 = default */ | |
16 gid_t gid; | |
17 const char *gid_origin; | |
22272
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
18 |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
19 /* If parent directory doesn't exist, mkdir() it with this mode. |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
20 0 = don't mkdir(). The parent directories are assumed to be |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
21 potentially rmdir() simultaneously, so the mkdir()+locking may be |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
22 attempted multiple times. */ |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
23 int mkdir_mode; |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
24 /* 0 = default */ |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
25 uid_t mkdir_uid; |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
26 /* 0 = default */ |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
27 gid_t mkdir_gid; |
651fa80715a3
lib: file_create_locked() - Add settings to mkdir() missing parent directories
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18744
diff
changeset
|
28 const char *mkdir_gid_origin; |
18740 | 29 }; |
30 | |
31 /* Either open an existing file and lock it, or create the file locked. | |
32 The creation is done by creating a temp file and link()ing it to path. | |
33 If link() fails, opening is retried again. Returns fd on success, | |
34 -1 on error. errno is preserved for the last failed syscall, so most | |
35 importantly ENOENT could mean that the directory doesn't exist and EAGAIN | |
22501
99a2b945045f
lib: file_lock_set_unlink_on_free() - Avoid unlink() if another process is waiting on the lock
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22272
diff
changeset
|
36 means locking timed out. |
99a2b945045f
lib: file_lock_set_unlink_on_free() - Avoid unlink() if another process is waiting on the lock
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22272
diff
changeset
|
37 |
99a2b945045f
lib: file_lock_set_unlink_on_free() - Avoid unlink() if another process is waiting on the lock
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22272
diff
changeset
|
38 If this function is used to create lock files, file_lock_set_unlink_on_free() |
99a2b945045f
lib: file_lock_set_unlink_on_free() - Avoid unlink() if another process is waiting on the lock
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22272
diff
changeset
|
39 should be used for the resulting lock. It attempts to avoid unlinking the |
99a2b945045f
lib: file_lock_set_unlink_on_free() - Avoid unlink() if another process is waiting on the lock
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22272
diff
changeset
|
40 file if there are already other processes using the lock. That can help to |
99a2b945045f
lib: file_lock_set_unlink_on_free() - Avoid unlink() if another process is waiting on the lock
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22272
diff
changeset
|
41 avoid "Creating a locked file ... keeps failing" errors */ |
18740 | 42 int file_create_locked(const char *path, const struct file_create_settings *set, |
43 struct file_lock **lock_r, bool *created_r, | |
44 const char **error_r); | |
45 | |
46 #endif |