/*
- * Copyright (c) Zmanda, Inc. All Rights Reserved.
+ * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
*
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
+ * 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 library is distributed in the hope that it will be useful, but
+ * 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 Lesser General Public
- * License for more details.
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
*
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ * 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120
+ * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
* Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
*/
%include "amglue/amglue.swg"
%include "exception.i"
+%include "Amanda/Debug.pod"
+
%{
#include <glib.h>
#include "debug.h"
%}
-%perlcode %{
-=head1 NAME
-
-Amanda::Debug - support for debugging Amanda applications
-
-=head1 SYNOPSIS
-
- use Amanda::Debug qw( :init :logging );
-
- # (note: dbopen and such are usually handled by
- # Amanda::Util::setup_applicaton)
- dbopen("server");
-
- debug("this is a debug message");
-
-See C<debug.h> for a more in-depth description of the functionality of
-this module.
-
-=head1 API STATUS
-
-Stable
-
-=head1 DEBUG LOGGING
-
-Several debug logging messages, each taking a single string, are
-available:
-
-=over
-
-=item C<error> - also aborts the program to produce a core dump
-
-=item C<critical> - exits the program with C<$error_exit_status>
-
-=item C<warning>
-
-=item C<message>
-
-=item C<info>
-
-=item C<debug>
-
-=back
-
-ALl of the debug logging functions are available via the export tag
-C<:logging>.
-
-=head1 ADVANCED USAGE
-
-Most applications should use L<Amanda::Util>'s C<setup_application>
-to initialize the debug libraries. The initialization functions
-available from this module are thus considered "advanced", and the
-reader is advised to consult the C header, C<debug.h>, for details.
-
-Briefly, the functions C<dbopen> and C<dbrename> are used to
-open a debug file whose pathname includes all of the relevant
-information. C<dbclose> and C<dbreopen> are used to close that debug
-file before transferring control to another process.
-
-The variable C<$erroutput_type> can take on any combination
-of the flags C<$ERROUTPUT_INTERACTIVE>, C<$ERROUTPUT_SYSLOG>
-and C<$ERROUTPUT_AMANDALOG>. C<$ERROUTPUT_INTERACTIVE>
-causes messages from C<error> and C<critical> to be sent
-to stderr. C<$ERROUTPUT_SYSLOG> sends it to syslog, and
-C<$ERROUTPUT_AMANDALOG> sends it to the current trace log (see
-L<Amanda::Logfile>).
-
-C<$error_exit_status> is the exit status with which C<critical>
-will exit.
-
-All of the initialization functions and variables are available via
-the export tag C<:init>.
-
-The current debug file's integer file descriptor (I<not> a Perl
-filehandle) is available from C<dbfd()>. Likewise, C<dbfn()> returns
-the filename of the current debug file.
-
-C<debug_dup_stderr_to_debug()> redirects, at the file-descriptor level,
-C<STDERR> into the debug file. This is useful when running external
-applications which may produce error output.
-
-=cut
-%}
-
/*
* Initialization
*/
amglue_export_tag(init,
- dbopen dbreopen dbrename dbclose
- $erroutput_type $error_exit_status
+ debug_init dbopen dbreopen dbrename dbclose
+ $error_exit_status
);
+void debug_init(void);
void dbopen(char *subdir);
void dbreopen(char *file, char *notation);
void dbrename(char *config, char *subdir);
void dbclose(void);
-amglue_add_flag_tag_fns(erroutput_type_t);
-amglue_add_constant_short(ERR_INTERACTIVE, INTERACTIVE, erroutput_type_t);
-amglue_add_constant_short(ERR_SYSLOG, SYSLOG, erroutput_type_t);
-amglue_add_constant_short(ERR_AMANDALOG, AMANDALOG, erroutput_type_t);
-amglue_copy_tag_to(erroutput_type_t, init);
-
-erroutput_type_t erroutput_type;
int error_exit_status;
/*
- * Logging
+ * Override die() and warn()
*/
+%perlcode %{
+sub _my_die {
+ # $^S: (from perlvar)
+ # undef -> parsing module/eval
+ # 1 -> executing an eval
+ # 0 -> otherwise
+ # we *only* want to call critical() in the "otherwise" case
+ if (!defined($^S) or $^S == 1) {
+ die(@_);
+ } else {
+ my ($msg) = @_;
+ chomp $msg;
+ suppress_error_traceback();
+ critical(@_);
+ }
+};
+$SIG{__DIE__} = \&_my_die;
+
+sub _my_warn {
+ my ($msg) = @_;
+ chomp $msg;
+ warning(@_);
+};
+$SIG{__WARN__} = \&_my_warn;
+
+# utility function for test scripts, which want to use the regular
+# perl mechanisms
+sub disable_die_override {
+ delete $SIG{__DIE__};
+ delete $SIG{__WARN__};
+}
+%}
-amglue_export_tag(logging,
- error critical warning message info debug
-);
+/*
+ * Logging
+ */
%rename(error) error__; /* error() is a macro defined in debug.h .. just avoid that */
%inline %{
void debug(char *msg) { g_debug("%s", msg); }
%}
+amglue_export_tag(logging,
+ error critical warning message info debug
+);
+
+void add_amanda_log_handler(amanda_log_handler_t *handler);
+/* these functions are written as simple global variables, since they are just
+ * function pointers used in add_amanda_log_handler. Note that the functions
+ * then appear as e.g., $amanda_log_null. */
+%immutable;
+amanda_log_handler_t *amanda_log_stderr, *amanda_log_syslog, *amanda_log_null;
+%mutable;
+
+amglue_export_tag(logging,
+ add_amanda_log_handler
+ $amanda_log_stderr $amanda_log_syslog $amanda_log_null
+);
+
+/* used to suppress the traceback when calling from perl */
+void suppress_error_traceback(void);
+
/*
* Advanced
*/