aboutsummaryrefslogtreecommitdiff
path: root/src/job.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-05 15:49:15 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-03-05 15:49:32 +0200
commit47576447626ac40b61f978836ccb5becbd2b9091 (patch)
tree8afff1cc0c69b676973a790dfc48bed8face988a /src/job.c
parent514797c56e431f37de9a00834281f990a7b15c46 (diff)
downloadwydawca-47576447626ac40b61f978836ccb5becbd2b9091.tar.gz
wydawca-47576447626ac40b61f978836ccb5becbd2b9091.tar.bz2
Improve locking.
* gconf/gconf-gram.y (string_convert): Rename to gconf_string_convert, make extern. All uses updated. * gconf/gconf.h (gconf_string_convert): New proto. (wydawca_kw): `locking' block statement. * src/job.c: Introduce a delay before restarting a tempfailed job. Do not trigger error reporting on tempfail * src/lock.c: Retry locking attempts, according to configuration. * src/wydawca.h (lock_retry_attempts, lock_retry_interval): New declarations.
Diffstat (limited to 'src/job.c')
-rw-r--r--src/job.c63
1 files changed, 55 insertions, 8 deletions
diff --git a/src/job.c b/src/job.c
index 1baa0af..6d88add 100644
--- a/src/job.c
+++ b/src/job.c
@@ -47,6 +47,14 @@ queue_signal (int sig)
signal (sig, queue_signal);
}
+void
+set_timer (time_t interval)
+{
+ wakeup = 0;
+ if (interval)
+ alarm (interval);
+}
+
struct job *
job_locate (const struct spool *spool, uid_t uid)
{
@@ -120,6 +128,8 @@ job_start (struct job *job)
signal (SIGQUIT, SIG_DFL);
signal (SIGINT, SIG_DFL);
signal (SIGCHLD, SIG_DFL);
+ signal (SIGALRM, SIG_DFL);
+ alarm (0);
for (i = getdtablesize (); i > 2; i--)
close (i);
exit (wydawca_scanner (job) ? WYDAWCA_EX_AGAIN : 0);
@@ -214,18 +224,26 @@ print_status (struct job *job, int expect_term)
if (WIFEXITED (status))
{
- if (WEXITSTATUS (status) == 0)
+ int exit_code = WEXITSTATUS (status);
+ if (exit_code == 0)
{
if (debug_level)
logmsg (LOG_DEBUG,
_("%lu (%s, %s) exited successfully"),
(unsigned long) job->pid, job->spool->tag, pw->pw_name);
}
+ else if (exit_code == WYDAWCA_EX_AGAIN)
+ {
+ if (debug_level)
+ logmsg (LOG_DEBUG,
+ _("%lu (%s, %s) reported tempfail"),
+ (unsigned long) job->pid, job->spool->tag, pw->pw_name);
+ }
else
logmsg (LOG_ERR,
_("%lu (%s, %s) failed with status %d"),
(unsigned long) job->pid, job->spool->tag, pw->pw_name,
- WEXITSTATUS (status));
+ exit_code);
}
else if (WIFSIGNALED (status))
{
@@ -266,7 +284,9 @@ job_queue_runner ()
{
int status;
struct job *job;
-
+ time_t now = time (NULL);
+ time_t min_interval = 0;
+
if (!wakeup)
return;
wakeup = 0;
@@ -298,21 +318,48 @@ job_queue_runner ()
{
if (WIFEXITED (job->exit_status)
&& WEXITSTATUS (job->exit_status) == WYDAWCA_EX_AGAIN)
- /* Re-queue the job */
- job->state = STATE_QUEUED;
+ {
+ time_t interval = lock_retry_attempts * lock_retry_interval;
+ if (interval == 0)
+ interval = lock_expire_time;
+ /* Re-queue the job */
+ job->state = STATE_QUEUED;
+ job->timestamp = now + interval;
+ }
else
job_remove (job);
}
}
+
if (job->state == STATE_QUEUED)
- if (job_start (job))
- pause ();
+ {
+ time_t interval;
+
+ if (job->timestamp >= now)
+ {
+ if (job_start (job))
+ pause (); /* FIXME */
+ now = time (NULL);
+ }
+ else
+ {
+ time_t interval = job->timestamp - now;
+ if (min_interval == 0 || interval < min_interval)
+ min_interval = interval;
+ }
+ }
+
job = next;
- }
+ }
+
+ if (debug_level > 1)
+ logmsg (LOG_DEBUG, _("computed interval: %lu"), min_interval);
+ set_timer (min_interval);
}
void
job_init ()
{
signal (SIGCHLD, queue_signal);
+ signal (SIGALRM, queue_signal);
}

Return to:

Send suggestions and report system problems to the System administrator.