/*****************************************************************************
 * stacktrace_dso.c
 *
 * This file implements stacktrace to be used with LD_PRELOAD.
 *
 * ---------------------------------------------------------------------------
 * stacktrace - Stacktrace printer.
 *   (C) 2008-2009 Gerardo García Peña <gerardo@kung-foo.net>
 *
 *   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.
 *
 *   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.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc., 51
 *   Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include <signal.h>

#define __STACKTRACE_MSG_MACROS__
#include "stacktrace.h"

/*****************************************************************************
 * PROTOTYPES
 *****************************************************************************/

/* Initialization and finalization */
static void stacktrace_init_dso(void) __attribute__ ((constructor));
static void stacktrace_fini_dso(void) __attribute__ ((destructor));

/*****************************************************************************
 * INITIALIZATION AND FINALIZATION
 *****************************************************************************/

static void stacktrace_init_internal_siglist(int signal_hook, ...)
{
  va_list siglist;

  va_start(siglist, signal_hook);
  stacktrace_init_internal(signal_hook, siglist);
  va_end(siglist);
}

static void stacktrace_init_dso(void)
{
  MSG(PACKAGE_NAME " version " PACKAGE_VERSION ", Copyright (C) 2008-2010 Gerardo García Peña");
  MSG(PACKAGE_NAME " is free software and comes with ABSOLUTELY NO WARRANTY;");
  MSG("you are welcome to redistribute it under certain conditions;");
  MSG("for details see the file `COPYING' that accompanies this software.");
  MSG("----------------------------------------------------------------------");

  stacktrace_init_internal_siglist(1,
                                   SIGHUP,  /* Term - Hangup detected or death of controlling process */
                                   SIGINT,  /* Term - Interrupt from keyboard                         */
                                   SIGQUIT, /* Core - Quit from keyboard                              */
                                   SIGILL,  /* Core - Illegal Instruction                             */
                                   SIGABRT, /* Core - Abort signal from abort(3)                      */
                                   SIGFPE,  /* Core - Floating point exception                        */
                                   SIGSEGV, /* Core - Invalid memory reference                        */
                                   SIGPIPE, /* Term - Broken pipe: write to pipe with no readers      */
                                   SIGALRM, /* Term - Timer signal from alarm(2)                      */
                                   SIGTERM, /* Term - Termination signal                              */
                                   SIGUSR1, /* Term - User-defined signal 1                           */
                                   SIGUSR2, /* Term - User-defined signal 2                           */
                                   SIGCHLD, /* Ign  - Child stopped or terminated                     */
                                   SIGCONT, /* Cont - Continue if stopped                             */
                                   SIGTSTP, /* Stop - Stop typed at tty                               */
                                   SIGTTIN, /* Stop - tty input for background process                */
                                   SIGTTOU, /* Stop - tty output for background process               */
                                   0);
}

static void stacktrace_fini_dso(void)
{
  stacktrace_fini_internal();
}

