gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated: prepare for #6133: extend report


From: gnunet
Subject: [taler-exchange] branch master updated: prepare for #6133: extend report-lib with API for signal handling
Date: Wed, 15 Jul 2020 14:07:36 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 5d4d5dca prepare for #6133: extend report-lib with API for signal 
handling
5d4d5dca is described below

commit 5d4d5dcaf42b23589bf2cffb5eb9702baef44b70
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Jul 15 14:07:32 2020 +0200

    prepare for #6133: extend report-lib with API for signal handling
---
 src/auditor/report-lib.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/auditor/report-lib.h | 11 ++++++++
 2 files changed, 80 insertions(+)

diff --git a/src/auditor/report-lib.c b/src/auditor/report-lib.c
index 3074b579..0956bcae 100644
--- a/src/auditor/report-lib.c
+++ b/src/auditor/report-lib.c
@@ -72,6 +72,36 @@ struct GNUNET_TIME_Absolute start_time;
  */
 static struct GNUNET_CONTAINER_MultiHashMap *denominations;
 
+/**
+ * Flag that is raised to 'true' if the user
+ * presses CTRL-C to abort the audit.
+ */
+static volatile bool abort_flag;
+
+/**
+ * Context for the SIG-INT (ctrl-C) handler.
+ */
+static struct GNUNET_SIGNAL_Context *sig_int;
+
+/**
+ * Context for the SIGTERM handler.
+ */
+static struct GNUNET_SIGNAL_Context *sig_term;
+
+
+/**
+ * Test if the audit should be aborted because the user
+ * pressed CTRL-C.
+ *
+ * @return false to continue the audit, true to terminate
+ *         cleanly as soon as possible
+ */
+bool
+TALER_ARL_do_abort (void)
+{
+  return abort_flag;
+}
+
 
 /**
  * Convert absolute time to human-readable JSON string.
@@ -605,6 +635,16 @@ TALER_ARL_amount_subtract_neg_ (struct TALER_Amount *diff,
 }
 
 
+/**
+ * Signal handler called for signals that should cause us to shutdown.
+ */
+static void
+handle_sigint (void)
+{
+  abort_flag = true;
+}
+
+
 /**
  * Setup global variables based on configuration.
  *
@@ -672,11 +712,30 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle 
*c)
       return GNUNET_SYSERR;
     }
   }
+  sig_int = GNUNET_SIGNAL_handler_install (SIGINT,
+                                           &handle_sigint);
+  if (NULL == sig_int)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+                         "signal");
+    TALER_ARL_done (NULL);
+    return GNUNET_SYSERR;
+  }
+  sig_term = GNUNET_SIGNAL_handler_install (SIGTERM,
+                                            &handle_sigint);
+  if (NULL == sig_term)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+                         "signal");
+    TALER_ARL_done (NULL);
+    return GNUNET_SYSERR;
+  }
   if (NULL ==
       (TALER_ARL_edb = TALER_EXCHANGEDB_plugin_load (TALER_ARL_cfg)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed to initialize exchange database plugin.\n");
+    TALER_ARL_done (NULL);
     return GNUNET_SYSERR;
   }
   if (NULL ==
@@ -727,6 +786,16 @@ TALER_ARL_done (json_t *report)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Audit complete\n");
+  if (NULL != sig_int)
+  {
+    GNUNET_SIGNAL_handler_uninstall (sig_int);
+    sig_int = NULL;
+  }
+  if (NULL != sig_term)
+  {
+    GNUNET_SIGNAL_handler_uninstall (sig_term);
+    sig_term = NULL;
+  }
   if (NULL != TALER_ARL_adb)
   {
     TALER_AUDITORDB_plugin_unload (TALER_ARL_adb);
diff --git a/src/auditor/report-lib.h b/src/auditor/report-lib.h
index eeb36f0a..7ae30825 100644
--- a/src/auditor/report-lib.h
+++ b/src/auditor/report-lib.h
@@ -301,6 +301,17 @@ TALER_ARL_setup_sessions_and_run (TALER_ARL_Analysis ana,
                                   void *ana_cls);
 
 
+/**
+ * Test if the audit should be aborted because the user
+ * pressed CTRL-C.
+ *
+ * @return false to continue the audit, true to terminate
+ *         cleanly as soon as possible
+ */
+bool
+TALER_ARL_do_abort (void);
+
+
 /**
  * Setup global variables based on configuration.
  *

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]