## program built. We also don't bother trying to assemble code, or
## anything like that.
-noinst_HEADERS = rpc_com.h
+noinst_HEADERS = rpc_com.h debug.h
AM_CPPFLAGS = -I$(top_srcdir)/tirpc -DPORTMAP -DINET6 \
-D_GNU_SOURCE -Wall -pipe
rpc_callmsg.c rpc_generic.c rpc_soc.c rpcb_clnt.c rpcb_prot.c \
rpcb_st_xdr.c svc.c svc_auth.c svc_dg.c svc_auth_unix.c svc_auth_none.c \
svc_generic.c svc_raw.c svc_run.c svc_simple.c svc_vc.c getpeereid.c \
- auth_time.c auth_des.c authdes_prot.c
+ auth_time.c auth_des.c authdes_prot.c debug.c
## XDR
libtirpc_la_SOURCES += xdr.c xdr_rec.c xdr_array.c xdr_float.c xdr_mem.c xdr_reference.c xdr_stdio.c
--- /dev/null
+/*
+ * debug.c -- debugging routines for libtirpc
+ *
+ * Copyright (C) 2014 Red Hat, Steve Dickson <steved@redhat.com>
+ *
+ * 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 <sys/types.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <string.h>
+
+#include "debug.h"
+
+/* library global debug level */
+int libtirpc_debug_level = 3;
+int log_stderr = 1; /* log to stderr instead of systlog */
+
+/*
+ * Set the debug level for the entire library.
+ * Different area will used the value to determin
+ * the verbosity of the debugging output.
+ */
+void
+libtirpc_set_debug(char *name, int level, int use_stderr)
+{
+ if (level < 0)
+ level = 0;
+
+ log_stderr = use_stderr;
+ if (!use_stderr)
+ openlog(name, LOG_PID, LOG_DAEMON);
+
+ LIBTIRPC_DEBUG(1, ("libtirpc: debug level %d", level));
+}
+
+void
+libtirpc_log_dbg(char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ if (log_stderr) {
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+ } else
+ vsyslog(LOG_NOTICE, fmt, args);
+ va_end(args);
+}
--- /dev/null
+/*
+ * debug.h -- debugging routines for libtirpc
+ *
+ * Copyright (C) 2014 Red Hat, Steve Dickson <steved@redhat.com>
+ *
+ * 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.
+ */
+
+#ifndef _DEBUG_H
+#define _DEBUG_H
+#include <syslog.h>
+
+extern int libtirpc_debug_level;
+extern int log_stderr;
+
+void libtirpc_log_dbg(char *format, ...);
+void libtirpc_set_debug(char *name, int level, int use_stderr);
+
+#define LIBTIRPC_DEBUG(level, msg) \
+ do { \
+ if (level <= libtirpc_debug_level) \
+ libtirpc_log_dbg msg; \
+ } while (0)
+
+static inline void
+vlibtirpc_log_dbg(int level, const char *fmt, va_list args)
+{
+ if (level <= libtirpc_debug_level) {
+ if (log_stderr) {
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+ } else
+ vsyslog(LOG_NOTICE, fmt, args);
+ }
+}
+#endif /* _DEBUG_H */