]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/main.c
Remove svn:keywords since they cause svn_load_dirs.pl to complain about every file.
[thirdparty/cups.git] / scheduler / main.c
index f244526e5796f0e888042cf77010edf46ba0ea59..0b8e34c9b201e04cb9ccc0d7c18df7fc58eff2a3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: main.c 5305 2006-03-18 03:05:12Z mike $"
+ * "$Id: main.c 177 2006-06-21 00:20:03Z jlovell $"
  *
  *   Scheduler main loop for the Common UNIX Printing System (CUPS).
  *
@@ -219,6 +219,12 @@ main(int  argc,                            /* I - Number of command-line args */
 #endif /* HAVE_LAUNCHD */
              break;
 
+          case 'p' : /* Stop immediately for profiling */
+              puts("Warning: -p option is for internal testing use only!");
+             stop_scheduler = 1;
+             fg             = 1;
+             break;
+
          default : /* Unknown option */
               _cupsLangPrintf(stderr, _("cupsd: Unknown option \"%c\" - "
                                        "aborting!\n"), *opt);
@@ -703,7 +709,7 @@ main(int  argc,                             /* I - Number of command-line args */
          sptr += strlen(sptr);
        }
 
-      cupsdLogMessage(CUPSD_LOG_EMERG, s);
+      cupsdLogMessage(CUPSD_LOG_EMERG, "%s", s);
 
       strcpy(s, "OutputSet =");
       slen = 11;
@@ -717,7 +723,7 @@ main(int  argc,                             /* I - Number of command-line args */
          sptr += strlen(sptr);
        }
 
-      cupsdLogMessage(CUPSD_LOG_EMERG, s);
+      cupsdLogMessage(CUPSD_LOG_EMERG, "%s", s);
 
       for (i = 0, con = (cupsd_client_t *)cupsArrayFirst(Clients);
           con;
@@ -993,11 +999,12 @@ main(int  argc,                           /* I - Number of command-line args */
     }
 
    /*
-    * Update the root certificate once every 5 minutes...
+    * Update the root certificate once every 5 minutes if we have client
+    * connections...
     */
 
     if ((current_time - RootCertTime) >= RootCertDuration && RootCertDuration &&
-        !RunUser)
+        !RunUser && cupsArrayCount(Clients))
     {
      /*
       * Update the root certificate...
@@ -1012,7 +1019,7 @@ main(int  argc,                           /* I - Number of command-line args */
     * accumulated.  Don't send these more than once a second...
     */
 
-    if (LastEvent && (time(NULL) - LastEventTime) > 1)
+    if (LastEvent)
     {
 #ifdef HAVE_NOTIFY_POST
       if (LastEvent & CUPSD_EVENT_PRINTER_CHANGED)
@@ -1040,10 +1047,9 @@ main(int  argc,                          /* I - Number of command-line args */
 #endif /* HAVE_NOTIFY_POST */
 
      /*
-      * Reset the accumulated events and notification time...
+      * Reset the accumulated events...
       */
 
-      LastEventTime = time(NULL);
       LastEvent     = CUPSD_EVENT_NONE;
     }
   }
@@ -1190,7 +1196,7 @@ cupsdClearString(char **s)                /* O - String value */
 {
   if (s && *s)
   {
-    free(*s);
+    _cupsStrFree(*s);
     *s = NULL;
   }
 }
@@ -1256,10 +1262,10 @@ cupsdSetString(char       **s,          /* O - New string */
     return;
 
   if (*s)
-    free(*s);
+    _cupsStrFree(*s);
 
   if (v)
-    *s = strdup(v);
+    *s = _cupsStrAlloc(v);
   else
     *s = NULL;
 }
@@ -1290,13 +1296,13 @@ cupsdSetStringf(char       **s,         /* O - New string */
     vsnprintf(v, sizeof(v), f, ap);
     va_end(ap);
 
-    *s = strdup(v);
+    *s = _cupsStrAlloc(v);
   }
   else
     *s = NULL;
 
   if (olds)
-    free(olds);
+    _cupsStrFree(olds);
 }
 
 
@@ -1315,12 +1321,10 @@ launchd_checkin(void)
                        ld_resp,        /* Launch data response */
                        ld_array,       /* Launch data array */
                        ld_sockets,     /* Launch data sockets dictionary */
-                       ld_runatload,   /* Run-at-load setting */
                        tmp;            /* Launch data */
   cupsd_listener_t     *lis;           /* Listeners array */
   http_addr_t          addr;           /* Address variable */
   socklen_t            addrlen;        /* Length of address */
-  bool                 runatload;      /* Run-at-load setting value */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG, "launchd_checkin: pid=%d", (int)getpid());
@@ -1346,26 +1350,6 @@ launchd_checkin(void)
     exit(EXIT_FAILURE);
   }
 
- /*
-  * Get the "run-at-load" setting...
-  */
-
-  if ((ld_runatload =
-           launch_data_dict_lookup(ld_resp, LAUNCH_JOBKEY_RUNATLOAD)) != NULL &&
-      launch_data_get_type(ld_runatload) == LAUNCH_DATA_BOOL)
-    runatload = launch_data_get_bool(ld_runatload);
-  else
-  {
-    errno = launch_data_get_errno(ld_resp);
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "launchd_checkin: Unable to find Run-at-load setting: %s",
-                    strerror(errno));
-    exit(EXIT_FAILURE);
-  }
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "launchd_checkin: Run-at-load=%s",
-                  runatload ? "true" : "false");
-
  /*
   * Get the sockets dictionary...
   */
@@ -1459,18 +1443,22 @@ launchd_checkin(void)
   {
     if (launch_data_get_type(ld_array) == LAUNCH_DATA_ARRAY)
     {
-      tmp = launch_data_array_get_index(ld_array, 0);
-
-      if (launch_data_get_type(tmp) == LAUNCH_DATA_FD)
+      if ((tmp = launch_data_array_get_index(ld_array, 0)))
       {
-        if (BrowseSocket != -1)
-         close(BrowseSocket);
-
-       BrowseSocket = launch_data_get_fd(tmp);
-      }
-      else
-       cupsdLogMessage(CUPSD_LOG_WARN,
-                       "launchd_checkin: BrowseSocket not a fd!");
+       if (launch_data_get_type(tmp) == LAUNCH_DATA_FD)
+       {
+         if (BrowseSocket != -1)
+           close(BrowseSocket);
+  
+         BrowseSocket = launch_data_get_fd(tmp);
+       }
+       else
+         cupsdLogMessage(CUPSD_LOG_WARN,
+                         "launchd_checkin: BrowseSocket not a fd!");
+     }
+     else
+       cupsdLogMessage(CUPSD_LOG_WARN,
+                      "launchd_checkin: BrowseSockets is an empty array!");
    }
    else
      cupsdLogMessage(CUPSD_LOG_WARN,
@@ -2107,13 +2095,6 @@ select_timeout(int fds)                  /* I - Number of descriptors returned */
   if (fds || cupsArrayCount(Clients) > 50)
     return (1);
 
- /*
-  * If we had a recent event notification, timeout in 1 second...
-  */
-
-  if (LastEvent)
-    return (1);
-
  /*
   * Otherwise, check all of the possible events that we need to wake for...
   */
@@ -2272,5 +2253,5 @@ usage(int status)                 /* O - Exit status */
 
 
 /*
- * End of "$Id: main.c 5305 2006-03-18 03:05:12Z mike $".
+ * End of "$Id: main.c 177 2006-06-21 00:20:03Z jlovell $".
  */