Commit e8674181 e86741813eb537dc19491a9f69f8ebc12815ac0e by Sergey Poznyakoff

Rewrite

1 parent 525ec621
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -47,34 +47,53 @@ enum mu_locker_set_mode ...@@ -47,34 +47,53 @@ enum mu_locker_set_mode
47 47
48 /* mu_locker_create() flags */ 48 /* mu_locker_create() flags */
49 49
50 #define MU_LOCKER_SIMPLE 0x00 50 /* Locker types */
51
52 #define MU_LOCKER_TYPE_DOTLOCK 0
53 #define MU_LOCKER_TYPE_EXTERNAL 1
54 /* Use an external program to lock the file. This is necessary
55 for programs having permission to access a file, but do not
56 have write permission on the directory that contains that file. */
57 #define MU_LOCKER_TYPE_KERNEL 2
58 /* Use kernel locking (flock, lockf or ioctl) */
59 #define MU_LOCKER_TYPE_NULL 3
60 /* Special locker type: means no lock. This is to be used with
61 temporary mailboxes stored in memory. */
62
63 #define MU_LOCKER_TYPE_TO_FLAG(t) ((t) << 8)
64 #define MU_LOCKER_FLAG_TO_TYPE(f) ((f) >> 8)
65 #define MU_LOCKER_IS_TYPE(f,t) (MU_LOCKER_FLAG_TO_TYPE(f) == (t))
66 #define MU_LOCKER_SET_TYPE(f,t) ((f) = MU_LOCKER_TYPE_TO_FLAG(t) | MU_LOCKER_OPTIONS(f))
67 #define MU_LOCKER_TYPE_MASK 0xff00
68 #define MU_LOCKER_OPTION_MASK 0x00ff
69 #define MU_LOCKER_OPTIONS(f) ((f) & MU_LOCKER_OPTION_MASK)
70
71 #define MU_LOCKER_NULL MU_LOCKER_TYPE_TO_FLAG(MU_LOCKER_TYPE_NULL)
72 #define MU_LOCKER_DOTLOCK MU_LOCKER_TYPE_TO_FLAG(MU_LOCKER_TYPE_DOTLOCK)
73 #define MU_LOCKER_EXTERNAL MU_LOCKER_TYPE_TO_FLAG(MU_LOCKER_TYPE_EXTERNAL)
74 #define MU_LOCKER_KERNEL MU_LOCKER_TYPE_TO_FLAG(MU_LOCKER_TYPE_KERNEL)
75
76 /* Options */
77
78 #define MU_LOCKER_SIMPLE 0x0000
51 /* Just try and dotlock the file, not the default because its usually 79 /* Just try and dotlock the file, not the default because its usually
52 better to retry. */ 80 better to retry. */
53 #define MU_LOCKER_RETRY 0x01 81 #define MU_LOCKER_RETRY 0x0001
54 /* This requests that we loop retries times, sleeping retry_sleep 82 /* This requests that we loop retries times, sleeping retry_sleep
55 seconds in between trying to obtain the lock before failing with 83 seconds in between trying to obtain the lock before failing with
56 MU_LOCK_CONFLICT. */ 84 MU_LOCK_CONFLICT. */
57 #define MU_LOCKER_TIME 0x02 85 #define MU_LOCKER_TIME 0x0002
58 /* This mode checks the last update time of the lock, then removes 86 /* This mode checks the last update time of the lock, then removes
59 it if older than MU_LOCKER_EXPIRE_TIME. If a client uses this, 87 it if older than MU_LOCKER_EXPIRE_TIME. If a client uses this,
60 then the servers better periodically update the lock on the 88 then the servers better periodically update the lock on the
61 file... do they? */ 89 file... do they? */
62 #define MU_LOCKER_PID 0x04 90 #define MU_LOCKER_PID 0x0004
63 /* PID locking is only useful for programs that aren't using 91 /* PID locking is only useful for programs that aren't using
64 an external dotlocker, non-setgid programs will use a dotlocker, 92 an external dotlocker, non-setgid programs will use a dotlocker,
65 which locks and exits imediately. This is a protection against 93 which locks and exits imediately. This is a protection against
66 a server crashing, it's not generally useful. */ 94 a server crashing, it's not generally useful. */
67 #define MU_LOCKER_EXTERNAL 0x08
68 /* Use an external program to lock the file. This is necessary
69 for programs having permission to access a file, but do not
70 have write permission on the directory that contains that file. */
71 #define MU_LOCKER_NULL 0x10
72 /* Special locker type: means no lock. This is to be used with
73 temporary mailboxes stored in memory. */
74 #define MU_LOCKER_KERNEL 0x20
75 /* Use kernel locking (flock, lockf or ioctl) */
76 95
77 #define MU_LOCKER_DEFAULT (MU_LOCKER_RETRY) 96 #define MU_LOCKER_DEFAULT (MU_LOCKER_DOTLOCK | MU_LOCKER_RETRY)
78 97
79 /* Use these flags for as the default locker flags (the default defaults 98 /* Use these flags for as the default locker flags (the default defaults
80 * to MU_LOCKER_DEFAULT). A flags of 0 resets the flags back to the 99 * to MU_LOCKER_DEFAULT). A flags of 0 resets the flags back to the
...@@ -104,6 +123,14 @@ extern int mu_locker_get_retries (mu_locker_t, int*); ...@@ -104,6 +123,14 @@ extern int mu_locker_get_retries (mu_locker_t, int*);
104 extern int mu_locker_get_retry_sleep (mu_locker_t, int*); 123 extern int mu_locker_get_retry_sleep (mu_locker_t, int*);
105 extern int mu_locker_get_external (mu_locker_t, char**); 124 extern int mu_locker_get_external (mu_locker_t, char**);
106 125
126 enum mu_locker_mode
127 {
128 mu_lck_shr, /* Shared (advisory) lock */
129 mu_lck_exc, /* Exclusive lock */
130 mu_lck_opt /* Optional lock = shared, if the locker supports it, no
131 locking otherwise */
132 };
133
107 extern int mu_locker_lock (mu_locker_t); 134 extern int mu_locker_lock (mu_locker_t);
108 extern int mu_locker_touchlock (mu_locker_t); 135 extern int mu_locker_touchlock (mu_locker_t);
109 extern int mu_locker_unlock (mu_locker_t); 136 extern int mu_locker_unlock (mu_locker_t);
......