summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2009-12-01 13:23:35 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2009-12-01 13:23:35 (GMT)
commitefd45e0a305dd0cc289d98b58141a40a3ddd3ffa (patch) (side-by-side diff)
tree60859166c008e55034c1b6e84e113b72e909b2a6
parent5017a2c0a3266540c2bb5895595f2c79ce869091 (diff)
downloadwydawca-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 (more/less context) (ignore whitespace changes)
-rw-r--r--src/config.c6
-rw-r--r--src/job.c2
-rw-r--r--src/lock.c18
-rw-r--r--src/mail.c12
-rw-r--r--src/process.c12
-rw-r--r--src/wydawca.h3
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[] = {
grecs_type_string, &lockdir },
{ "expire-time", N_("interval"), N_("Define lock expiration interval"),
grecs_type_string, &lock_expire_time, 0, cb_interval },
- { "retry-attempts", N_("n"), N_("Number of times to retry locking"),
- grecs_type_uint, &lock_retry_attempts },
- { "retry-interval", N_("interval"), N_("Delay between locking attempts"),
- grecs_type_string, &lock_retry_interval, 0, cb_interval },
+ { "timeout", N_("interval"), N_("Locking timeout"),
+ grecs_type_string, &lock_timeout, 0, cb_interval },
{ NULL }
};
diff --git a/src/job.c b/src/job.c
index fb65fb1..baf4cec 100644
--- a/src/job.c
+++ b/src/job.c
@@ -319,7 +319,7 @@ job_queue_runner ()
if (WIFEXITED (job->exit_status)
&& WEXITSTATUS (job->exit_status) == WYDAWCA_EX_AGAIN)
{
- time_t interval = lock_retry_attempts * lock_retry_interval;
+ time_t interval = lock_timeout;
if (interval == 0)
interval = lock_expire_time;
/* Re-queue the job */
diff --git a/src/lock.c b/src/lock.c
index b9ea0dc..e974c61 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -21,8 +21,7 @@
int enable_locking = 1;
char *lockdir;
time_t lock_expire_time = 5*60;
-unsigned lock_retry_attempts = 3;
-time_t lock_retry_interval = 1;
+time_t lock_timeout = 60;
#define LOCKFILE_MODE 0644
@@ -192,18 +191,19 @@ wydawca_lock (const char *lockname)
(unsigned long) time (NULL), xgethostname ());
if (!tempname)
return LOCK_FAILURE;
- if (lock_retry_attempts)
+ if (lock_timeout)
{
- unsigned i;
-
- for (i = 0; i < lock_retry_attempts; i++)
+ time_t start = time (NULL);
+
+ do
{
rc = _lock_internal (lockname, tempname);
- if (rc == 0)
- break;
if (rc == LOCK_RETRY)
- sleep (lock_retry_interval);
+ sleep (1);
+ else
+ break;
}
+ while (time (NULL) - start < lock_timeout);
}
else
rc = _lock_internal (lockname, tempname);
diff --git a/src/mail.c b/src/mail.c
index beb88d4..a40e4b4 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -55,7 +55,8 @@ mail_send_message (mu_address_t rcpt, const char *text)
static char *x_mailer = "wydawca (" PACKAGE_STRING ")";
size_t size;
char *buf;
-
+ const char *sval;
+
mu_message_create (&msg, NULL);
mu_message_get_stream (msg, &stream);
@@ -70,6 +71,15 @@ mail_send_message (mu_address_t rcpt, const char *text)
mu_header_set_value (hdr, "To", buf, 1);
free (buf);
+ if (from_address && mu_header_sget_value (hdr, "From", &sval))
+ {
+ mu_address_to_string (from_address, NULL, 0, &size);
+ buf = xmalloc (size + 1);
+ mu_address_to_string (from_address, buf, size + 1, NULL);
+ mu_header_set_value (hdr, "From", buf, 1);
+ free (buf);
+ }
+
if (debug_level > 1)
{
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)
{
char *lockfile = wydawca_lockname (spool->tag);
int rc = wydawca_lock (lockfile);
- if (rc == LOCK_OK)
+ switch (rc)
{
+ case LOCK_OK:
scan_spool_unlocked (spool, uc, uv);
wydawca_unlock (lockfile);
+ break;
+
+ case LOCK_FAILURE:
+ logmsg (LOG_ERR, _("cannot lock spool %s"), spool->tag);
+ break;
+
+ case LOCK_RETRY:
+ logmsg (LOG_WARNING, _("timed out while looking spool %s"), spool->tag);
+ break;
}
free (lockfile);
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;
extern char *lockdir;
extern time_t lock_expire_time;
-unsigned lock_retry_attempts;
-time_t lock_retry_interval;
+extern time_t lock_timeout;
extern int enable_locking;
extern int daemon_mode;

Return to:

Send suggestions and report system problems to the System administrator.