Author: mattm
Date: 2017-08-10 14:12:47 +0200 (Thu, 10 Aug 2017)
New Revision: 29335

Modified:
   trunk/gvm/ChangeLog
   trunk/gvm/src/gvmd.c
   trunk/gvm/src/manage.c
   trunk/gvm/src/manage.h
Log:
        * src/gvmd.c (serve_and_schedule): Separate the sync calls out from
        manage_schedule, with a separate "last time" counter.  This prevents
        the sync checks from happening repeatedly when other parts of
        manage_schedule fail to get a lock on the db.

        * src/manage.c (manage_sync): New function.
        (manage_schedule): Remove sync calls.

        * src/manage.h: Add header accordingly.

Modified: trunk/gvm/ChangeLog
===================================================================
--- trunk/gvm/ChangeLog 2017-08-10 09:19:16 UTC (rev 29334)
+++ trunk/gvm/ChangeLog 2017-08-10 12:12:47 UTC (rev 29335)
@@ -1,5 +1,17 @@
 2017-08-10  Matthew Mundell <matthew.mund...@greenbone.net>
 
+       * src/gvmd.c (serve_and_schedule): Separate the sync calls out from
+       manage_schedule, with a separate "last time" counter.  This prevents
+       the sync checks from happening repeatedly when other parts of
+       manage_schedule fail to get a lock on the db.
+
+       * src/manage.c (manage_sync): New function.
+       (manage_schedule): Remove sync calls.
+
+       * src/manage.h: Add header accordingly.
+
+2017-08-10  Matthew Mundell <matthew.mund...@greenbone.net>
+
        * src/gmpd.c (serve_gmp): Remove update log, now done in otp.c but only 
if
        an update is going to happen.
 

Modified: trunk/gvm/src/gvmd.c
===================================================================
--- trunk/gvm/src/gvmd.c        2017-08-10 09:19:16 UTC (rev 29334)
+++ trunk/gvm/src/gvmd.c        2017-08-10 12:12:47 UTC (rev 29335)
@@ -1204,10 +1204,13 @@
 static void
 serve_and_schedule ()
 {
-  time_t last_schedule_time = 0;
+  time_t last_schedule_time, last_sync_time;
   sigset_t sigmask_all;
   static sigset_t sigmask_current;
 
+  last_schedule_time = 0;
+  last_sync_time = 0;
+
   if (sigfillset (&sigmask_all))
     {
       g_critical ("%s: Error filling signal set\n", __FUNCTION__);
@@ -1273,6 +1276,12 @@
               exit (EXIT_FAILURE);
           }
 
+      if ((time (NULL) - last_sync_time) >= SCHEDULE_PERIOD)
+        {
+          manage_sync (sigmask_normal, fork_update_nvt_cache);
+          last_sync_time = time (NULL);
+        }
+
       timeout.tv_sec = SCHEDULE_PERIOD;
       timeout.tv_nsec = 0;
       ret = pselect (nfds, &readfds, NULL, &exceptfds, &timeout,
@@ -1324,6 +1333,12 @@
               exit (EXIT_FAILURE);
           }
 
+      if ((time (NULL) - last_sync_time) >= SCHEDULE_PERIOD)
+        {
+          manage_sync (sigmask_normal, fork_update_nvt_cache);
+          last_sync_time = time (NULL);
+        }
+
       if (termination_signal)
         {
           g_debug ("Received %s signal.\n",

Modified: trunk/gvm/src/manage.c
===================================================================
--- trunk/gvm/src/manage.c      2017-08-10 09:19:16 UTC (rev 29334)
+++ trunk/gvm/src/manage.c      2017-08-10 12:12:47 UTC (rev 29335)
@@ -6682,6 +6682,25 @@
 }
 
 /**
+ * @brief Perform any syncing that is due.
+ *
+ * In gvmd, periodically called from the main daemon loop.
+ *
+ * @param[in]  fork_connection  Function that forks a child which is connected
+ *                              to the Manager.  Must return PID in parent, 0
+ *                              in child, or -1 on error.
+ * @param[in]  sigmask_current  Sigmask to restore in child.
+ */
+void
+manage_sync (sigset_t *sigmask_current,
+             int (*fork_update_nvt_cache) ())
+{
+  manage_sync_nvts (fork_update_nvt_cache);
+  manage_sync_scap (sigmask_current);
+  manage_sync_cert (sigmask_current);
+}
+
+/**
  * @brief Schedule any actions that are due.
  *
  * In gvmd, periodically called from the main daemon loop.
@@ -6710,10 +6729,6 @@
   previous_start_task = 0;
   previous_stop_task = 0;
 
-  manage_sync_nvts (fork_update_nvt_cache);
-  manage_sync_scap (sigmask_current);
-  manage_sync_cert (sigmask_current);
-
   ret = manage_update_nvti_cache ();
   if (ret)
     {

Modified: trunk/gvm/src/manage.h
===================================================================
--- trunk/gvm/src/manage.h      2017-08-10 09:19:16 UTC (rev 29334)
+++ trunk/gvm/src/manage.h      2017-08-10 12:12:47 UTC (rev 29335)
@@ -2828,6 +2828,9 @@
 void
 set_scheduled_user_uuid (gchar* uuid);
 
+void
+manage_sync (sigset_t *, int (*fork_update_nvt_cache) ());
+
 int
 manage_schedule (int (*) (gvm_connection_t *, gchar *),
                  gboolean,

_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
https://lists.wald.intevation.org/cgi-bin/mailman/listinfo/openvas-commits

Reply via email to