Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'cancel -x -a' starts all pending jobs before stopping them #4648

Closed
michaelrsweet opened this issue Jun 23, 2015 · 8 comments
Closed

'cancel -x -a' starts all pending jobs before stopping them #4648

michaelrsweet opened this issue Jun 23, 2015 · 8 comments

Comments

@michaelrsweet
Copy link
Collaborator

Version: 2.0.3
CUPS.org User: twaugh.redhat

When using 'cancel -a' to cancel all the jobs, each time a processing job is stopped another pending job is started before it, too, is stopped.

This can be avoided by dealing with the pending jobs first, then dealing with other jobs.

The cause is that finalize_job() (from cupsdSetJobState()) calls cupsdCheckJobs() right at the end.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: twaugh.redhat

Patch attached.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Need to look at this some more, but we should be delaying any job scheduling decisions until Cancel-[My-]Jobs processing is complete (which is supposed to be an atomic operation...)

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: twaugh.redhat

Actually you need to use 'cancel -x -a' to reproduce this. It happens with e.g. 2.0.3.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: twaugh.redhat

This seems to fix it.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Fixed in Subversion repository.

I've attached an alternate patch which fixes when cupsdCheckJobs is called.

@michaelrsweet
Copy link
Collaborator Author

"0001-In-cupsdCancelJobs-handle-pending-jobs-first-STR-464.patch":

From 82b82b2d5023cb8ada5834612793b2909dd6ea82 Mon Sep 17 00:00:00 2001
From: Tim Waugh twaugh@redhat.com
Date: Tue, 23 Jun 2015 17:32:37 +0100
Subject: [PATCH] In cupsdCancelJobs(), handle pending jobs first (STR #4648)


scheduler/job.c | 46 +++++++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/scheduler/job.c b/scheduler/job.c
index 956f9ff..43f7caf 100644
--- a/scheduler/job.c
+++ b/scheduler/job.c
@@ -188,29 +188,41 @@ cupsdCancelJobs(const char dest, / I - Destination to cancel /
const char *username, /
I - Username or NULL /
int purge) /
I - Purge jobs? */
{

  • int pass;
    cupsd_job_t job; / Current job */
  • for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
  •   job;
    
  •   job = (cupsd_job_t *)cupsArrayNext(Jobs))
    
  • for (pass = 0; pass < 2; pass++)
    {
  • if ((!job->dest || !job->username) && !cupsdLoadJob(job))

- continue;

  • if ((!dest || !strcmp(job->dest, dest)) &&
  •    (!username || !strcmp(job->username, username)))
    
  • for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
  •     job;
    
  •     job = (cupsd_job_t *)cupsArrayNext(Jobs))
    
    {
  • /*
    
  •  \* Cancel all jobs matching this destination/user...
    
  •  */
    
  •  if ((!job->dest || !job->username) && !cupsdLoadJob(job))
    
  •    continue;
    
  •  /*
    
  •   \* Cancel all the pending jobs first so they don't get started
    
  •   \* meanwhile...
    
  •   */
    
  •  if (pass == 0 && job->state_value != IPP_JOB_PENDING)
    
  •    continue;
    
  •  if (purge)
    
  • cupsdSetJobState(job, IPP_JOB_CANCELED, CUPSD_JOB_PURGE,
  •                "Job purged by user.");
    
  •  else if (job->state_value < IPP_JOB_CANCELED)
    
  • cupsdSetJobState(job, IPP_JOB_CANCELED, CUPSD_JOB_DEFAULT,
  •        "Job canceled by user.");
    
  •  if ((!dest || !strcmp(job->dest, dest)) &&
    
  •      (!username || !strcmp(job->username, username)))
    
  •  {
    
  •    /*
    
  •     \* Cancel all jobs matching this destination/user...
    
  •     */
    
  •    if (purge)
    
  •      cupsdSetJobState(job, IPP_JOB_CANCELED, CUPSD_JOB_PURGE,
    
  •                       "Job purged by user.");
    
  •    else if (job->state_value < IPP_JOB_CANCELED)
    
  •      cupsdSetJobState(job, IPP_JOB_CANCELED, CUPSD_JOB_DEFAULT,
    
  •                       "Job canceled by user.");
    
  •  }
    
    }
    }

2.4.3

@michaelrsweet
Copy link
Collaborator Author

"0001-Don-t-call-cupsdCheckJobs-from-finalize_job-STR-4648.patch":

From 701f12da6b102dc1d7f34fa4ab36e5bd481d11a7 Mon Sep 17 00:00:00 2001
From: Tim Waugh twaugh@redhat.com
Date: Tue, 30 Jun 2015 09:19:44 +0100
Subject: [PATCH] Don't call cupsdCheckJobs() from finalize_job() (STR #4648).


scheduler/job.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/scheduler/job.c b/scheduler/job.c
index 82c5306..db3f194 100644
--- a/scheduler/job.c
+++ b/scheduler/job.c
@@ -1373,11 +1373,22 @@ cupsdDeleteJob(cupsd_job_t job, / I - Job /
cupsd_jobaction_t action)/
I - Action /
{
int i; /
Looping var */

  • ipp_pstate_t printer_state;

if (job->printer)

  • {
  • printer_state = job->printer->state;
    finalize_job(job, 1);
  • /*
  • \* Try printing another job...
    
  • */
    
  • if (printer_state != IPP_PRINTER_STOPPED)
  •  cupsdCheckJobs();
    
  • }

if (action == CUPSD_JOB_PURGE)
remove_job_history(job);

@@ -3526,13 +3537,6 @@ finalize_job(cupsd_job_t job, / I - Job */

job->printer->job = NULL;

job->printer = NULL;

  • /*
  • * Try printing another job...

- */

  • if (printer_state != IPP_PRINTER_STOPPED)
  • cupsdCheckJobs();
    }

2.4.3

@michaelrsweet
Copy link
Collaborator Author

"str4648.patch":

Index: scheduler/ipp.c

--- scheduler/ipp.c (revision 12776)
+++ scheduler/ipp.c (working copy)
@@ -3312,6 +3312,8 @@
}

con->response->request.status.status_code = IPP_OK;
+

  • cupsdCheckJobs();
    }

Index: scheduler/job.c

--- scheduler/job.c (revision 12776)
+++ scheduler/job.c (working copy)
@@ -213,8 +213,6 @@
"Job canceled by user.");
}

}

  • cupsdCheckJobs();
    }

@@ -3526,13 +3524,6 @@

job->printer->job = NULL;

job->printer = NULL;

  • /*
  • * Try printing another job...

- */

  • if (printer_state != IPP_PRINTER_STOPPED)
  • cupsdCheckJobs();
    }

@@ -4849,6 +4840,8 @@
ptr; / Pointer update... /
int loglevel, /
Log level for message /
event = 0; /
Events? */

  • cupsd_printer_t *printer = job->printer;

  •               /* Printer */
    

    static const char * const levels[] = /* Log levels */
    {
    "NONE",
    @@ -5222,10 +5215,11 @@
    finalize_job(job, 1);

    /*

  • * Check for new jobs...

    • Try printing another job...
      */
  • cupsdCheckJobs();

  • if (printer->state != IPP_PRINTER_STOPPED)

  •  cupsdCheckJobs();
    

    }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant