From a02a1627a954432cc65ec981cada8ba420d7ad2f Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 28 Aug 2018 17:15:12 +0200 Subject: Allow choice to trap or not program faults MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The binder traps faults by default to recover as much as possible from unexpected errors. Developers may need to remove that behaviour to get core file. This introduces 2 ways to set or remove the trapping of faults: - the environment variable AFB_TRAP_FAULTS - the command line option --trap-faults Both take a boolean value set using on of the following words: 1 yes true on -- enable trapping of faults (the default) 0 no false off -- disable trapping of faults Bug-AGL: SPEC-1702 Change-Id: I6c6a3b933dbda9922a6079c390a601c533d49e55 Signed-off-by: José Bollo --- src/main-afb-daemon.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/main-afb-daemon.c') diff --git a/src/main-afb-daemon.c b/src/main-afb-daemon.c index 0db84bc1..06aeb58d 100644 --- a/src/main-afb-daemon.c +++ b/src/main-afb-daemon.c @@ -50,7 +50,6 @@ #include "afb-hsrv.h" #include "afb-hreq.h" #include "afb-xreq.h" -#include "jobs.h" #include "afb-session.h" #include "verbose.h" #include "afb-common.h" @@ -59,12 +58,15 @@ #include "afb-hook.h" #include "afb-hook-flags.h" #include "afb-debug.h" -#include "process-name.h" -#include "wrap-json.h" #if defined(WITH_SUPERVISION) # include "afb-supervision.h" #endif +#include "process-name.h" +#include "wrap-json.h" +#include "jobs.h" +#include "sig-monitor.h" + /* if SELF_PGROUP == 0 the launched command is the group leader if SELF_PGROUP != 0 afb-daemon is the group leader @@ -823,15 +825,23 @@ error: int main(int argc, char *argv[]) { - struct json_object *name; + struct json_object *obj; afb_debug("main-entry"); // ------------- Build session handler & init config ------- main_config = afb_config_parse_arguments(argc, argv); - if (json_object_object_get_ex(main_config, "name", &name)) { - verbose_set_name(json_object_get_string(name), 0); - process_name_set_name(json_object_get_string(name)); - process_name_replace_cmdline(argv, json_object_get_string(name)); + if (sig_monitor_init( + !json_object_object_get_ex(main_config, "trap-faults", &obj) + || json_object_get_boolean(obj)) < 0) { + ERROR("failed to initialise signal handlers"); + return 1; + } + + + if (json_object_object_get_ex(main_config, "name", &obj)) { + verbose_set_name(json_object_get_string(obj), 0); + process_name_set_name(json_object_get_string(obj)); + process_name_replace_cmdline(argv, json_object_get_string(obj)); } afb_debug("main-args"); -- cgit 1.2.3-korg