diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-12-01 15:23:35 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-12-01 15:23:35 +0200 |
commit | efd45e0a305dd0cc289d98b58141a40a3ddd3ffa (patch) | |
tree | 60859166c008e55034c1b6e84e113b72e909b2a6 /src | |
parent | 5017a2c0a3266540c2bb5895595f2c79ce869091 (diff) | |
download | wydawca-efd45e0a305dd0cc289d98b58141a40a3ddd3ffa.tar.gz wydawca-efd45e0a305dd0cc289d98b58141a40a3ddd3ffa.tar.bz2 |
Fix locking. Improve mail formatting.
* src/config.c (locking_kw): Remove retry-attempts and
retry-interval.
New keyword: timeout.
* src/job.c (job_queue_runner): Use lock_timeout.
* src/lock.c (lock_retry_attempts, lock_retry_interval): Remove.
(lock_timeout): New variable.
(wydawca_lock): Rewrite lock acquisition loop.
* src/wydawca.h (lock_retry_attempts, lock_retry_interval): Remove.
(lock_timeout): New extern.
* src/process.c (scan_spool): Analyze return from wydawca_lock.
* src/mail.c (mail_send_message): Set From header, unless
it is already present.
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 6 | ||||
-rw-r--r-- | src/job.c | 2 | ||||
-rw-r--r-- | src/lock.c | 18 | ||||
-rw-r--r-- | src/mail.c | 12 | ||||
-rw-r--r-- | src/process.c | 12 | ||||
-rw-r--r-- | src/wydawca.h | 3 |
6 files changed, 35 insertions, 18 deletions
diff --git a/src/config.c b/src/config.c index 4748a80..6c351d9 100644 --- a/src/config.c +++ b/src/config.c | |||
@@ -1343,10 +1343,8 @@ static struct grecs_keyword locking_kw[] = { | |||
1343 | grecs_type_string, &lockdir }, | 1343 | grecs_type_string, &lockdir }, |
1344 | { "expire-time", N_("interval"), N_("Define lock expiration interval"), | 1344 | { "expire-time", N_("interval"), N_("Define lock expiration interval"), |
1345 | grecs_type_string, &lock_expire_time, 0, cb_interval }, | 1345 | grecs_type_string, &lock_expire_time, 0, cb_interval }, |
1346 | { "retry-attempts", N_("n"), N_("Number of times to retry locking"), | 1346 | { "timeout", N_("interval"), N_("Locking timeout"), |
1347 | grecs_type_uint, &lock_retry_attempts }, | 1347 | grecs_type_string, &lock_timeout, 0, cb_interval }, |
1348 | { "retry-interval", N_("interval"), N_("Delay between locking attempts"), | ||
1349 | grecs_type_string, &lock_retry_interval, 0, cb_interval }, | ||
1350 | { NULL } | 1348 | { NULL } |
1351 | }; | 1349 | }; |
1352 | 1350 | ||
@@ -319,7 +319,7 @@ job_queue_runner () | |||
319 | if (WIFEXITED (job->exit_status) | 319 | if (WIFEXITED (job->exit_status) |
320 | && WEXITSTATUS (job->exit_status) == WYDAWCA_EX_AGAIN) | 320 | && WEXITSTATUS (job->exit_status) == WYDAWCA_EX_AGAIN) |
321 | { | 321 | { |
322 | time_t interval = lock_retry_attempts * lock_retry_interval; | 322 | time_t interval = lock_timeout; |
323 | if (interval == 0) | 323 | if (interval == 0) |
324 | interval = lock_expire_time; | 324 | interval = lock_expire_time; |
325 | /* Re-queue the job */ | 325 | /* Re-queue the job */ |
@@ -21,8 +21,7 @@ | |||
21 | int enable_locking = 1; | 21 | int enable_locking = 1; |
22 | char *lockdir; | 22 | char *lockdir; |
23 | time_t lock_expire_time = 5*60; | 23 | time_t lock_expire_time = 5*60; |
24 | unsigned lock_retry_attempts = 3; | 24 | time_t lock_timeout = 60; |
25 | time_t lock_retry_interval = 1; | ||
26 | 25 | ||
27 | #define LOCKFILE_MODE 0644 | 26 | #define LOCKFILE_MODE 0644 |
28 | 27 | ||
@@ -192,18 +191,19 @@ wydawca_lock (const char *lockname) | |||
192 | (unsigned long) time (NULL), xgethostname ()); | 191 | (unsigned long) time (NULL), xgethostname ()); |
193 | if (!tempname) | 192 | if (!tempname) |
194 | return LOCK_FAILURE; | 193 | return LOCK_FAILURE; |
195 | if (lock_retry_attempts) | 194 | if (lock_timeout) |
196 | { | 195 | { |
197 | unsigned i; | 196 | time_t start = time (NULL); |
198 | 197 | ||
199 | for (i = 0; i < lock_retry_attempts; i++) | 198 | do |
200 | { | 199 | { |
201 | rc = _lock_internal (lockname, tempname); | 200 | rc = _lock_internal (lockname, tempname); |
202 | if (rc == 0) | ||
203 | break; | ||
204 | if (rc == LOCK_RETRY) | 201 | if (rc == LOCK_RETRY) |
205 | sleep (lock_retry_interval); | 202 | sleep (1); |
203 | else | ||
204 | break; | ||
206 | } | 205 | } |
206 | while (time (NULL) - start < lock_timeout); | ||
207 | } | 207 | } |
208 | else | 208 | else |
209 | rc = _lock_internal (lockname, tempname); | 209 | rc = _lock_internal (lockname, tempname); |
@@ -55,7 +55,8 @@ mail_send_message (mu_address_t rcpt, const char *text) | |||
55 | static char *x_mailer = "wydawca (" PACKAGE_STRING ")"; | 55 | static char *x_mailer = "wydawca (" PACKAGE_STRING ")"; |
56 | size_t size; | 56 | size_t size; |
57 | char *buf; | 57 | char *buf; |
58 | 58 | const char *sval; | |
59 | |||
59 | mu_message_create (&msg, NULL); | 60 | mu_message_create (&msg, NULL); |
60 | 61 | ||
61 | mu_message_get_stream (msg, &stream); | 62 | mu_message_get_stream (msg, &stream); |
@@ -70,6 +71,15 @@ mail_send_message (mu_address_t rcpt, const char *text) | |||
70 | mu_header_set_value (hdr, "To", buf, 1); | 71 | mu_header_set_value (hdr, "To", buf, 1); |
71 | free (buf); | 72 | free (buf); |
72 | 73 | ||
74 | if (from_address && mu_header_sget_value (hdr, "From", &sval)) | ||
75 | { | ||
76 | mu_address_to_string (from_address, NULL, 0, &size); | ||
77 | buf = xmalloc (size + 1); | ||
78 | mu_address_to_string (from_address, buf, size + 1, NULL); | ||
79 | mu_header_set_value (hdr, "From", buf, 1); | ||
80 | free (buf); | ||
81 | } | ||
82 | |||
73 | if (debug_level > 1) | 83 | if (debug_level > 1) |
74 | { | 84 | { |
75 | mu_debug_t debug; | 85 | mu_debug_t debug; |
diff --git a/src/process.c b/src/process.c index d04121c..a998edb 100644 --- a/src/process.c +++ b/src/process.c | |||
@@ -230,10 +230,20 @@ scan_spool (const struct spool *spool, int uc, uid_t *uv) | |||
230 | { | 230 | { |
231 | char *lockfile = wydawca_lockname (spool->tag); | 231 | char *lockfile = wydawca_lockname (spool->tag); |
232 | int rc = wydawca_lock (lockfile); | 232 | int rc = wydawca_lock (lockfile); |
233 | if (rc == LOCK_OK) | 233 | switch (rc) |
234 | { | 234 | { |
235 | case LOCK_OK: | ||
235 | scan_spool_unlocked (spool, uc, uv); | 236 | scan_spool_unlocked (spool, uc, uv); |
236 | wydawca_unlock (lockfile); | 237 | wydawca_unlock (lockfile); |
238 | break; | ||
239 | |||
240 | case LOCK_FAILURE: | ||
241 | logmsg (LOG_ERR, _("cannot lock spool %s"), spool->tag); | ||
242 | break; | ||
243 | |||
244 | case LOCK_RETRY: | ||
245 | logmsg (LOG_WARNING, _("timed out while looking spool %s"), spool->tag); | ||
246 | break; | ||
237 | } | 247 | } |
238 | free (lockfile); | 248 | free (lockfile); |
239 | return rc; | 249 | return rc; |
diff --git a/src/wydawca.h b/src/wydawca.h index 15d803b..bd81b88 100644 --- a/src/wydawca.h +++ b/src/wydawca.h | |||
@@ -332,8 +332,7 @@ extern int force_startup; | |||
332 | 332 | ||
333 | extern char *lockdir; | 333 | extern char *lockdir; |
334 | extern time_t lock_expire_time; | 334 | extern time_t lock_expire_time; |
335 | unsigned lock_retry_attempts; | 335 | extern time_t lock_timeout; |
336 | time_t lock_retry_interval; | ||
337 | extern int enable_locking; | 336 | extern int enable_locking; |
338 | 337 | ||
339 | extern int daemon_mode; | 338 | extern int daemon_mode; |