]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Implement Ada exception processing
authorReto Buerki <reet@codelabs.ch>
Tue, 2 Oct 2012 15:03:39 +0000 (17:03 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 19 Mar 2013 14:23:48 +0000 (15:23 +0100)
Register a global exception action with the Ada runtime to log uncaught
exceptions to the daemon log and terminate.

src/charon-tkm/build_charon.gpr
src/charon-tkm/build_common.gpr
src/charon-tkm/build_tests.gpr
src/charon-tkm/src/ehandler/eh_callbacks.c [new file with mode: 0644]
src/charon-tkm/src/ehandler/eh_callbacks.h [new file with mode: 0644]
src/charon-tkm/src/ehandler/exception_handler.adb [new file with mode: 0644]
src/charon-tkm/src/ehandler/exception_handler.ads [new file with mode: 0644]
src/charon-tkm/src/tkm/tkm.c

index bf6880668065e2fc63d11c75de6fb6a14a75da31..b208667a3de554b9cba927d09811c76fe69d689d 100644 (file)
@@ -13,4 +13,8 @@ project Build_Charon is
         & "-Werror";
    end Compiler;
 
+   package Binder is
+      for Default_Switches ("ada") use Build_Common.Ada_Binder_Switches;
+   end Binder;
+
 end Build_Charon;
index e32832a2893e37f0788dc1770e5c43e3942cc09c..ac322d7133f809ec51714a41097c701fd9c4e854 100644 (file)
@@ -19,4 +19,7 @@ project Build_Common is
                              "-fstack-check",
                              "-gnato",
                              "-g");
+
+   Ada_Binder_Switches   := ("-E");
+
 end Build_Common;
index 7aa07003a122a418a5b44d3f486e44d2d9bb9e0e..032c7969e56f14e53da0d5ee88dbcca6315309b0 100644 (file)
@@ -3,7 +3,7 @@ with "build_common";
 project Build_Tests is
 
    for Languages use ("Ada", "C");
-   for Source_Dirs use ("src/tkm", "src/ees", "tests");
+   for Source_Dirs use ("src/ees", "src/ehandler", "src/tkm", "tests");
    for Main use ("test_runner");
    for Object_Dir use Build_Common.Obj_Dir;
 
diff --git a/src/charon-tkm/src/ehandler/eh_callbacks.c b/src/charon-tkm/src/ehandler/eh_callbacks.c
new file mode 100644 (file)
index 0000000..7dca97c
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 Reto Buerki
+ * Copyright (C) 2012 Adrian-Ken Rueegsegger
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include <sys/types.h>
+#include <signal.h>
+#include <utils/debug.h>
+
+#include "eh_callbacks.h"
+
+void charon_terminate(char *msg)
+{
+       DBG1(DBG_DMN, "critical TKM error, terminating!");
+       DBG1(DBG_DMN, msg);
+       kill(0, SIGTERM);
+}
diff --git a/src/charon-tkm/src/ehandler/eh_callbacks.h b/src/charon-tkm/src/ehandler/eh_callbacks.h
new file mode 100644 (file)
index 0000000..1be9249
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Reto Buerki
+ * Copyright (C) 2012 Adrian-Ken Rueegsegger
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef EH_CALLBACKS_H_
+#define EH_CALLBACKS_H_
+
+/**
+ * Log given message and terminate charon.
+ */
+void charon_terminate(char *msg);
+
+#endif /** EH_CALLBACKS_H_ */
diff --git a/src/charon-tkm/src/ehandler/exception_handler.adb b/src/charon-tkm/src/ehandler/exception_handler.adb
new file mode 100644 (file)
index 0000000..3f165e1
--- /dev/null
@@ -0,0 +1,57 @@
+--
+--  Copyright (C) 2012 Reto Buerki
+--  Copyright (C) 2012 Adrian-Ken Rueegsegger
+--  Hochschule fuer Technik Rapperswil
+--
+--  This program is free software; you can redistribute it and/or modify it
+--  under the terms of the GNU General Public License as published by the
+--  Free Software Foundation; either version 2 of the License, or (at your
+--  option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+--
+--  This program is distributed in the hope that it will be useful, but
+--  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+--  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+--  for more details.
+--
+
+with Ada.Exceptions;
+
+with GNAT.Exception_Actions;
+
+with Interfaces.C.Strings;
+
+package body Exception_Handler
+is
+
+   procedure Charon_Terminate (Message : Interfaces.C.Strings.chars_ptr);
+   pragma Import (C, Charon_Terminate, "charon_terminate");
+
+   procedure Bailout (Ex : Ada.Exceptions.Exception_Occurrence);
+   --  Signal critical condition to charon daemon.
+
+   -------------------------------------------------------------------------
+
+   procedure Bailout (Ex : Ada.Exceptions.Exception_Occurrence)
+   is
+   begin
+      if Ada.Exceptions.Exception_Name (Ex) = "_ABORT_SIGNAL" then
+
+         --  Ignore runtime-internal abort signal exception.
+
+         return;
+      end if;
+
+      Charon_Terminate (Message => Interfaces.C.Strings.New_String
+                        (Ada.Exceptions.Exception_Information (Ex)));
+   end Bailout;
+
+   -------------------------------------------------------------------------
+
+   procedure Init
+   is
+   begin
+      GNAT.Exception_Actions.Register_Global_Action
+        (Action => Bailout'Access);
+   end Init;
+
+end Exception_Handler;
diff --git a/src/charon-tkm/src/ehandler/exception_handler.ads b/src/charon-tkm/src/ehandler/exception_handler.ads
new file mode 100644 (file)
index 0000000..29dd3d8
--- /dev/null
@@ -0,0 +1,24 @@
+--
+--  Copyright (C) 2012 Reto Buerki
+--  Copyright (C) 2012 Adrian-Ken Rueegsegger
+--  Hochschule fuer Technik Rapperswil
+--
+--  This program is free software; you can redistribute it and/or modify it
+--  under the terms of the GNU General Public License as published by the
+--  Free Software Foundation; either version 2 of the License, or (at your
+--  option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+--
+--  This program is distributed in the hope that it will be useful, but
+--  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+--  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+--  for more details.
+--
+
+package Exception_Handler
+is
+
+   procedure Init;
+   pragma Export (C, Init, "ehandler_init");
+   --  Register last-chance exception handler.
+
+end Exception_Handler;
index cdd4f4ad7c1fd0616453821c03e42a98e06335df..6e27586ed00da9a205157889c0e51e942dc0321f 100644 (file)
@@ -26,6 +26,7 @@ typedef struct private_tkm_t private_tkm_t;
 
 extern result_type ees_server_init(const char * const address);
 extern void ees_server_finalize(void);
+extern void ehandler_init(void);
 
 /*
  * Private additions to tkm_t.
@@ -60,6 +61,9 @@ bool tkm_init()
 
        /* initialize TKM client library */
        tkmlib_init();
+
+       ehandler_init();
+
        if (ike_init(IKE_SOCKET) != TKM_OK)
        {
                tkmlib_final();