Write printcap every 30s; prevents disk spin-down #2512

Closed
michaelrsweet opened this Issue Sep 14, 2007 · 3 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Sep 14, 2007

Version: 1.3.0
CUPS.org User: twaugh.redhat

In process_browse_data(), cupsdWritePrintcap() is called without checking whether it is necessary. In the common case, there is no need to call that function.

The reason it is important is that the disk activity of updating the file prevents any power saving from spinning down idle disks.

Collaborator

michaelrsweet commented Sep 14, 2007

CUPS.org User: mike

Hmm, will fix this for 1.3.2.

More than likely we'll just change the code to flag that something has changed, and then call cupsdWritePrintcap() in the parent function(s) so that we aren't writing the printcap more often than needed.

Collaborator

michaelrsweet commented Sep 17, 2007

CUPS.org User: mike

Fixed in Subversion repository.

Collaborator

michaelrsweet commented Sep 17, 2007

"str2512.patch":

Index: dirsvc.c

--- dirsvc.c (revision 6965)
+++ dirsvc.c (working copy)
@@ -91,7 +91,7 @@
ipp_pstate_t state, const char *location,
const char *info, const char *make_model,
int num_attrs, cups_option_t *attrs);
-static void process_implicit_classes(void);
+static void process_implicit_classes(int *write_printcap);
static void send_cups_browse(cupsd_printer_t *p);
#ifdef HAVE_LDAP
static void send_ldap_browse(cupsd_printer_t *p);
@@ -609,7 +609,7 @@

  • Do auto-classing if needed...
    */
  • process_implicit_classes();
  • process_implicit_classes(NULL);
    }

@@ -1685,7 +1685,8 @@
cups_option_t attrs) / I - Attributes /
{
int i; /
Looping var */

  • int update; /* Update printer attributes? */

  • int update, /* Update printer attributes? */

  •   write_printcap;     /* Write the printcap file? */
    

    char finaluri[HTTP_MAX_URI], /* Final URI for printer /
    name[IPP_MAX_NAME], /
    Name of printer /
    newname[IPP_MAX_NAME], /
    New name of printer */
    @@ -1772,11 +1773,12 @@

    • See if we already have it listed in the Printers list, and add it if not...
      */
  • type |= CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED;

  • type &= ~CUPS_PRINTER_IMPLICIT;

  • update = 0;

  • hptr = strchr(host, '.');

  • sptr = strchr(ServerName, '.');

  • type |= CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED;

  • type &= ~CUPS_PRINTER_IMPLICIT;

  • update = 0;

  • write_printcap = 0;

  • hptr = strchr(host, '.');

  • sptr = strchr(ServerName, '.');

if (!ServerNameIsIP && sptr != NULL && hptr != NULL)
{
@@ -1899,7 +1901,8 @@
cupsdSetString(&p->device_uri, uri);
cupsdSetString(&p->hostname, host);

  •  update = 1;
    
  •  update         = 1;
    
  •  write_printcap = 1;
    

    }
    }
    else
    @@ -2005,7 +2008,8 @@
    cupsdSetString(&p->uri, uri);
    cupsdSetString(&p->device_uri, uri);

  •  update = 1;
    
  •  write_printcap = 1;
    
  •  update         = 1;
    

    }
    }

@@ -2064,7 +2068,8 @@
if (info && (!p->info || strcmp(p->info, info)))
{
cupsdSetString(&p->info, info);

  • update = 1;
  • update = 1;
  • write_printcap = 1;
    }

if (!make_model || !make_model[0])
@@ -2153,6 +2158,7 @@
if (p->type & CUPS_PRINTER_DEFAULT)
{
DefaultPrinter = p;

  • write_printcap = 1;
    break;
    }
    }
    @@ -2161,13 +2167,14 @@
  • Do auto-classing if needed...
    */
  • process_implicit_classes();
  • process_implicit_classes(&write_printcap);

/*

  • Update the printcap file...
    */
  • cupsdWritePrintcap();
  • if (write_printcap)
  • cupsdWritePrintcap();
    }

@@ -2657,7 +2664,8 @@
*/

static void
-process_implicit_classes(void)
+process_implicit_classes(

  • int write_printcap) / O - Write printcap file? /
    {
    int i; /
    Looping var /
    int update; /
    Update printer attributes? */
    @@ -2738,6 +2746,9 @@
 update = 1;
  • if (write_printcap)

  • *write_printcap = 1;
    
    • cupsdLogMessage(CUPSD_LOG_DEBUG, "Added implicit class "%s"...",
      name);
      cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,

    Index: printers.c

    --- printers.c (revision 6965)
    +++ printers.c (working copy)
    @@ -2984,7 +2984,8 @@

    • data has come from...
      */
  • cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n");

  • cupsFilePuts(fp,

  •           "# This file was automatically generated by cupsd(8) from the\n");
    

    cupsFilePrintf(fp, "# %s/printers.conf file. All changes to this file\n",
    ServerRoot);
    cupsFilePuts(fp, "# will be lost.\n");
    @@ -3010,14 +3011,15 @@

       if (DefaultPrinter)
    cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
    
  •           DefaultPrinter->info, ServerName, DefaultPrinter->name);
    
  •                  DefaultPrinter->info, ServerName,
    
  •          DefaultPrinter->name);
    

    for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
    p;
    p = (cupsd_printer_t *)cupsArrayNext(Printers))
    if (p != DefaultPrinter)
    cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,

  •             ServerName, p->name);
    
  •                    ServerName, p->name);
       break;
    

    case PRINTCAP_SOLARIS:
    @@ -3055,9 +3057,10 @@
    p;
    p = (cupsd_printer_t *)cupsArrayNext(Printers))
    cupsFilePrintf(fp, "%s:\n"

  •           "\t:bsdaddr=%s,%s:\\n"
    
  •       "\t:description=%s:\n",
    
  •       p->name, ServerName, p->name, p->info ? p->info : "");
    
  •                  "\t:bsdaddr=%s,%s:\\n"
    
  •              "\t:description=%s:\n",
    
  •              p->name, ServerName, p->name,
    
  •          p->info ? p->info : "");
       break;
    

    }
    }

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