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

In auto-shutdown mode ("-l") scheduler keeps running on subscriptions for push notifications #4754

Closed
michaelrsweet opened this issue Jan 10, 2016 · 5 comments

Comments

@michaelrsweet
Copy link
Collaborator

Version: 2.1-current
CUPS.org User: till.kamppeter

I use CUPS to implement printing functionality on mobile devices. To save resources I start CUPS on-demand and let CUPS shut down automatically when it gets idle ("-l" command line option).

Problem is that if there is an application's subscription for push notifications (like D-Bus) CUPS keeps running as long as the subscription is there. It should shut down when running out of jobs, ignoring the presence of the subscription.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Fixed in Subversion repository.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: till.kamppeter

Are you sure that the attached patch is fixing this bug?

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Yes, the issue was that select_timeout() (in main.c) was lowering the timeout when subscriptions were present, preventing idle exit. I removed that code and added code in ipp.c to auto-expire subscriptions as needed (before similar code is used in the main loop - an IPP Get-Subscriptions or Get-Subscription-Attributes request could come in before the main loop expiration code was executed...)

@michaelrsweet
Copy link
Collaborator Author

"str4754.patch":

Index: scheduler/ipp.c
===================================================================
--- scheduler/ipp.c (revision 13037)
+++ scheduler/ipp.c (working copy)
@@ -3,7 +3,7 @@
  *
  * IPP routines for the CUPS scheduler.
  *
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  * This file contains Kerberos support code, copyright 2006 by
@@ -7255,6 +7255,12 @@
                   con, con->number, sub_id);

  /*
+  * Expire subscriptions as needed...
+  */
+
+  cupsdExpireSubscriptions(NULL, NULL);
+
+ /*
   * Is the subscription ID valid?
   */

@@ -7404,6 +7410,12 @@
   }

  /*
+  * Expire subscriptions as needed...
+  */
+
+  cupsdExpireSubscriptions(NULL, NULL);
+
+ /*
   * Copy the subscription attributes to the response using the
   * requested-attributes attribute that may be provided by the client.
   */
Index: scheduler/main.c
===================================================================
--- scheduler/main.c    (revision 13037)
+++ scheduler/main.c    (working copy)
@@ -3,7 +3,7 @@
  *
  * Main loop for the CUPS scheduler.
  *
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  * These coded instructions, statements, and computer programs are the
@@ -1573,7 +1573,6 @@
   time_t       now;        /* Current time */
   cupsd_client_t   *con;       /* Client information */
   cupsd_job_t      *job;       /* Job information */
-  cupsd_subscription_t *sub;       /* Subscription information */
   const char       *why;       /* Debugging aid */


@@ -1711,19 +1710,6 @@
 #endif /* HAVE_MALLINFO */

  /*
-  * Expire subscriptions as needed...
-  */
-
-  for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
-       sub;
-       sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
-    if (!sub->job && sub->expire && sub->expire < timeout)
-    {
-      timeout = sub->expire;
-      why     = "expire subscription";
-    }
-
- /*
   * Adjust from absolute to relative time.  We add 1 second to the timeout since
   * events occur after the timeout expires, and limit the timeout to 86400
   * seconds (1 day) to avoid select() timeout limits present on some operating
Index: scheduler/subscriptions.c
===================================================================
--- scheduler/subscriptions.c   (revision 13037)
+++ scheduler/subscriptions.c   (working copy)
@@ -657,6 +657,8 @@
   curtime = time(NULL);
   update  = 0;

+  cupsdLogMessage(CUPSD_LOG_INFO, "Expiring subscriptions...");
+
   for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
        sub;
        sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: till.kamppeter

Tested your patch on CUPS 2.1.x of Ubuntu Xenial and it works. Thank you very much.

@michaelrsweet michaelrsweet added this to the Stable milestone Mar 17, 2016
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