|
|
da2fd33 |
From cf86dbaf75f4c81e406036b6695c717cf4fd1331 Mon Sep 17 00:00:00 2001
|
|
|
da2fd33 |
From: Brian Bockelman <bbockelm@cse.unl.edu>
|
|
|
da2fd33 |
Date: Wed, 24 Oct 2012 20:28:09 -0500
|
|
|
da2fd33 |
Subject: [PATCH 1/3] First attempt at syslog code for dprintf.
|
|
|
da2fd33 |
|
|
|
da2fd33 |
---
|
|
|
da2fd33 |
src/condor_includes/dprintf_internal.h | 11 ++++-
|
|
|
da2fd33 |
src/condor_utils/dprintf_setup.cpp | 16 ++++++
|
|
|
da2fd33 |
src/condor_utils/dprintf_syslog.cpp | 19 +++++++
|
|
|
da2fd33 |
src/condor_utils/dprintf_syslog.h | 82 ++++++++++++++++++++++++++++++++
|
|
|
da2fd33 |
4 files changed, 127 insertions(+), 1 deletions(-)
|
|
|
da2fd33 |
create mode 100644 src/condor_utils/dprintf_syslog.cpp
|
|
|
da2fd33 |
create mode 100644 src/condor_utils/dprintf_syslog.h
|
|
|
da2fd33 |
|
|
|
da2fd33 |
diff --git a/src/condor_includes/dprintf_internal.h b/src/condor_includes/dprintf_internal.h
|
|
|
da2fd33 |
index c26a886..b0ecf48 100644
|
|
|
da2fd33 |
--- a/src/condor_includes/dprintf_internal.h
|
|
|
da2fd33 |
+++ b/src/condor_includes/dprintf_internal.h
|
|
|
da2fd33 |
@@ -17,6 +17,9 @@
|
|
|
da2fd33 |
*
|
|
|
da2fd33 |
***************************************************************/
|
|
|
da2fd33 |
|
|
|
da2fd33 |
+#ifndef __dprintf_internal_h_
|
|
|
da2fd33 |
+#define __dprintf_internal_h_
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
// This #define doesn't actually do anything. This value needs to be
|
|
|
da2fd33 |
// defined before any system header files are included in the source file
|
|
|
da2fd33 |
// to have any effect.
|
|
|
da2fd33 |
@@ -27,6 +30,7 @@ typedef _Longlong int64_t;
|
|
|
da2fd33 |
#else
|
|
|
da2fd33 |
#include <stdint.h>
|
|
|
da2fd33 |
#endif
|
|
|
da2fd33 |
+#include <ctime>
|
|
|
da2fd33 |
|
|
|
da2fd33 |
struct DebugFileInfo;
|
|
|
da2fd33 |
|
|
|
da2fd33 |
@@ -37,7 +41,8 @@ enum DebugOutput
|
|
|
da2fd33 |
FILE_OUT,
|
|
|
da2fd33 |
STD_OUT,
|
|
|
da2fd33 |
STD_ERR,
|
|
|
da2fd33 |
- OUTPUT_DEBUG_STR
|
|
|
da2fd33 |
+ OUTPUT_DEBUG_STR,
|
|
|
da2fd33 |
+ SYSLOG
|
|
|
da2fd33 |
};
|
|
|
da2fd33 |
|
|
|
da2fd33 |
/* future
|
|
|
da2fd33 |
@@ -70,6 +75,7 @@ struct DebugFileInfo
|
|
|
da2fd33 |
bool want_truncate;
|
|
|
da2fd33 |
bool accepts_all;
|
|
|
da2fd33 |
bool dont_panic;
|
|
|
da2fd33 |
+ void *userData;
|
|
|
da2fd33 |
DebugFileInfo() :
|
|
|
da2fd33 |
outputTarget(FILE_OUT),
|
|
|
da2fd33 |
debugFP(0),
|
|
|
da2fd33 |
@@ -79,6 +85,7 @@ struct DebugFileInfo
|
|
|
da2fd33 |
want_truncate(false),
|
|
|
da2fd33 |
accepts_all(false),
|
|
|
da2fd33 |
dont_panic(false),
|
|
|
da2fd33 |
+ userData(NULL),
|
|
|
da2fd33 |
dprintfFunc(NULL)
|
|
|
da2fd33 |
{}
|
|
|
da2fd33 |
DebugFileInfo(const DebugFileInfo &dfi) : outputTarget(dfi.outputTarget), debugFP(NULL), choice(dfi.choice),
|
|
|
da2fd33 |
@@ -115,3 +122,5 @@ void _dprintf_global_func(int cat_and_flags, int hdr_flags, time_t clock_now, st
|
|
|
da2fd33 |
void dprintf_to_outdbgstr(int cat_and_flags, int hdr_flags, time_t clock_now, struct tm *tm, const char* message, DebugFileInfo* dbgInfo);
|
|
|
da2fd33 |
#endif
|
|
|
da2fd33 |
|
|
|
da2fd33 |
+#endif
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
diff --git a/src/condor_utils/dprintf_setup.cpp b/src/condor_utils/dprintf_setup.cpp
|
|
|
da2fd33 |
index 440ef98..b1ccd3a 100644
|
|
|
da2fd33 |
--- a/src/condor_utils/dprintf_setup.cpp
|
|
|
da2fd33 |
+++ b/src/condor_utils/dprintf_setup.cpp
|
|
|
da2fd33 |
@@ -24,6 +24,7 @@
|
|
|
da2fd33 |
#include "condor_sys_types.h"
|
|
|
da2fd33 |
#include "condor_debug.h"
|
|
|
da2fd33 |
#include "dprintf_internal.h"
|
|
|
da2fd33 |
+#include "dprintf_syslog.h"
|
|
|
da2fd33 |
#include "condor_constants.h"
|
|
|
da2fd33 |
|
|
|
da2fd33 |
#if HAVE_BACKTRACE
|
|
|
da2fd33 |
@@ -134,6 +135,13 @@ void dprintf_set_outputs(const struct dprintf_output_settings *p_info, int c_inf
|
|
|
da2fd33 |
it->dprintfFunc = dprintf_to_outdbgstr;
|
|
|
da2fd33 |
}
|
|
|
da2fd33 |
#endif
|
|
|
da2fd33 |
+ else if (logPath == "SYSLOG")
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ // Intention is to eventually user-selected
|
|
|
da2fd33 |
+ it->dprintfFunc = DprintfSyslog::Log;
|
|
|
da2fd33 |
+ it->outputTarget = SYSLOG;
|
|
|
da2fd33 |
+ it->userData = static_cast<void*>(DprintfSyslogFactory::NewLog(LOG_DAEMON));
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
else
|
|
|
da2fd33 |
{
|
|
|
da2fd33 |
it->outputTarget = FILE_OUT;
|
|
|
da2fd33 |
@@ -211,6 +219,14 @@ void dprintf_set_outputs(const struct dprintf_output_settings *p_info, int c_inf
|
|
|
da2fd33 |
|
|
|
da2fd33 |
if(debugLogsOld)
|
|
|
da2fd33 |
{
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+ for (it = debugLogsOld->begin(); it != debugLogsOld->end(); it++)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ if ((it->outputTarget == SYSLOG) && (it->userData))
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ delete static_cast<DprintfSyslog*>(it->userData);
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
delete debugLogsOld;
|
|
|
da2fd33 |
}
|
|
|
da2fd33 |
|
|
|
da2fd33 |
diff --git a/src/condor_utils/dprintf_syslog.cpp b/src/condor_utils/dprintf_syslog.cpp
|
|
|
da2fd33 |
new file mode 100644
|
|
|
da2fd33 |
index 0000000..d0189f8
|
|
|
da2fd33 |
--- /dev/null
|
|
|
da2fd33 |
+++ b/src/condor_utils/dprintf_syslog.cpp
|
|
|
da2fd33 |
@@ -0,0 +1,19 @@
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+#include "condor_common.h"
|
|
|
da2fd33 |
+#include "condor_debug.h"
|
|
|
da2fd33 |
+#include "dprintf_syslog.h"
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+DprintfSyslogFactory * DprintfSyslogFactory::m_singleton = NULL;
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+void
|
|
|
da2fd33 |
+DprintfSyslog::Log(const char * message)
|
|
|
da2fd33 |
+{
|
|
|
da2fd33 |
+ syslog(LOG_INFO, "%s", message);
|
|
|
da2fd33 |
+}
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+DprintfSyslog::~DprintfSyslog()
|
|
|
da2fd33 |
+{
|
|
|
da2fd33 |
+ DprintfSyslogFactory &factory = DprintfSyslogFactory::getInstance();
|
|
|
da2fd33 |
+ factory.DecCount();
|
|
|
da2fd33 |
+}
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
diff --git a/src/condor_utils/dprintf_syslog.h b/src/condor_utils/dprintf_syslog.h
|
|
|
da2fd33 |
new file mode 100644
|
|
|
da2fd33 |
index 0000000..a10d42d
|
|
|
da2fd33 |
--- /dev/null
|
|
|
da2fd33 |
+++ b/src/condor_utils/dprintf_syslog.h
|
|
|
da2fd33 |
@@ -0,0 +1,82 @@
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+#include "dprintf_internal.h"
|
|
|
da2fd33 |
+#include <syslog.h>
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+class DprintfSyslogFactory;
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+class DprintfSyslog
|
|
|
da2fd33 |
+{
|
|
|
da2fd33 |
+ friend class DprintfSyslogFactory;
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+public:
|
|
|
da2fd33 |
+ static void Log(int, int, time_t, struct tm*, const char * message, DebugFileInfo* info)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ if (!info || !info->userData)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ return;
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+ DprintfSyslog * logger = static_cast<DprintfSyslog*>(info->userData);
|
|
|
da2fd33 |
+ logger->Log(message);
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+ ~DprintfSyslog();
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+protected:
|
|
|
da2fd33 |
+ DprintfSyslog() {}
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+private:
|
|
|
da2fd33 |
+ void Log(const char *);
|
|
|
da2fd33 |
+};
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+class DprintfSyslogFactory
|
|
|
da2fd33 |
+{
|
|
|
da2fd33 |
+ friend class DprintfSyslog;
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+public:
|
|
|
da2fd33 |
+ static DprintfSyslog *NewLog(int facility)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ DprintfSyslogFactory & factory = getInstance();
|
|
|
da2fd33 |
+ return factory.NewDprintfSyslog(facility);
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+protected:
|
|
|
da2fd33 |
+ void DecCount()
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ m_count--;
|
|
|
da2fd33 |
+ if (m_count == 0)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ closelog();
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+ static DprintfSyslogFactory & getInstance()
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ if (!m_singleton)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ m_singleton = new DprintfSyslogFactory();
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+ return *m_singleton;
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+private:
|
|
|
da2fd33 |
+ DprintfSyslog * NewDprintfSyslog(int facility)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ DprintfSyslog * logger = new DprintfSyslog();
|
|
|
da2fd33 |
+ if (!logger) return NULL;
|
|
|
da2fd33 |
+ if (m_count == 0)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ openlog("condor", LOG_PID|LOG_NDELAY, facility);
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+ m_count++;
|
|
|
da2fd33 |
+ return logger;
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+ DprintfSyslogFactory() :
|
|
|
da2fd33 |
+ m_count(0)
|
|
|
da2fd33 |
+ {
|
|
|
da2fd33 |
+ }
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+ static DprintfSyslogFactory *m_singleton;
|
|
|
da2fd33 |
+
|
|
|
da2fd33 |
+ unsigned int m_count;
|
|
|
da2fd33 |
+};
|
|
|
da2fd33 |
--
|
|
|
da2fd33 |
1.7.4.1
|
|
|
da2fd33 |
|
|
|
da2fd33 |
|
|
|
da2fd33 |
From 5b17f58b41722735bf1a7da34c728bfe3114479b Mon Sep 17 00:00:00 2001
|
|
|
da2fd33 |
From: Brian Bockelman <bbockelm@cse.unl.edu>
|
|
|
da2fd33 |
Date: Wed, 24 Oct 2012 20:46:52 -0500
|
|
|
da2fd33 |
Subject: [PATCH 2/3] Don't provide an ident - it defaults to the binary name, which is more useful anyway.
|
|
|
da2fd33 |
|
|
|
da2fd33 |
---
|
|
|
da2fd33 |
src/condor_utils/dprintf_syslog.h | 2 +-
|
|
|
da2fd33 |
1 files changed, 1 insertions(+), 1 deletions(-)
|
|
|
da2fd33 |
|
|
|
da2fd33 |
diff --git a/src/condor_utils/dprintf_syslog.h b/src/condor_utils/dprintf_syslog.h
|
|
|
da2fd33 |
index a10d42d..364a228 100644
|
|
|
da2fd33 |
--- a/src/condor_utils/dprintf_syslog.h
|
|
|
da2fd33 |
+++ b/src/condor_utils/dprintf_syslog.h
|
|
|
da2fd33 |
@@ -65,7 +65,7 @@ private:
|
|
|
da2fd33 |
if (!logger) return NULL;
|
|
|
da2fd33 |
if (m_count == 0)
|
|
|
da2fd33 |
{
|
|
|
da2fd33 |
- openlog("condor", LOG_PID|LOG_NDELAY, facility);
|
|
|
da2fd33 |
+ openlog(NULL, LOG_PID|LOG_NDELAY, facility);
|
|
|
da2fd33 |
}
|
|
|
da2fd33 |
m_count++;
|
|
|
da2fd33 |
return logger;
|
|
|
da2fd33 |
--
|
|
|
da2fd33 |
1.7.4.1
|
|
|
da2fd33 |
|
|
|
da2fd33 |
|
|
|
da2fd33 |
From d082fcc410b3729241dbe82912f526d51a96a2f5 Mon Sep 17 00:00:00 2001
|
|
|
da2fd33 |
From: Brian Bockelman <bbockelm@cse.unl.edu>
|
|
|
da2fd33 |
Date: Tue, 30 Oct 2012 18:15:21 -0500
|
|
|
da2fd33 |
Subject: [PATCH 3/3] Prevent dprintf_syslog from compiling on Windows.
|
|
|
da2fd33 |
|
|
|
da2fd33 |
---
|
|
|
da2fd33 |
src/condor_utils/CMakeLists.txt | 4 +++-
|
|
|
da2fd33 |
src/condor_utils/dprintf_setup.cpp | 7 ++++++-
|
|
|
da2fd33 |
2 files changed, 9 insertions(+), 2 deletions(-)
|
|
|
da2fd33 |
|
|
|
da2fd33 |
diff --git a/src/condor_utils/CMakeLists.txt b/src/condor_utils/CMakeLists.txt
|
|
|
da2fd33 |
index 7ce1fd6..7de76fb 100644
|
|
|
da2fd33 |
--- a/src/condor_utils/CMakeLists.txt
|
|
|
da2fd33 |
+++ b/src/condor_utils/CMakeLists.txt
|
|
|
da2fd33 |
@@ -84,10 +84,12 @@ endif()
|
|
|
da2fd33 |
##################################################
|
|
|
da2fd33 |
# condorapi & tests
|
|
|
da2fd33 |
|
|
|
da2fd33 |
-condor_selective_glob("my_username.*;condor_event.*;file_sql.*;misc_utils.*;user_log_header.*;write_user_log*;read_user_log*;iso_dates.*;file_lock.*;format_time.*;utc_time.*;stat_wrapper*;log_rotate.*;dprintf*;sig_install.*;basename.*;mkargv.*;except.*;strupr.*;lock_file.*;rotate_file.*;strcasestr.*;strnewp.*;condor_environ.*;setsyscalls.*;passwd_cache.*;uids.c*;chomp.*;subsystem_info.*;my_subsystem.*;distribution.*;my_distribution.*;get_random_num.*;libcondorapi_stubs.*;seteuid.*;setegid.*;condor_open.*;classad_merge.*;condor_attributes.*;simple_arg.*;compat_classad.*;compat_classad_util.*;classad_oldnew.*;condor_snutils.*;stringSpace.*;string_list.*;stl_string_utils.*;MyString.*;condor_xml_classads.*;directory*;param_functions.*;filename_tools_cpp.*;filename_tools.*;stat_info.*;${SAFE_OPEN_SRC}" ApiSrcs)
|
|
|
da2fd33 |
+condor_selective_glob("my_username.*;condor_event.*;file_sql.*;misc_utils.*;user_log_header.*;write_user_log*;read_user_log*;iso_dates.*;file_lock.*;format_time.*;utc_time.*;stat_wrapper*;log_rotate.*;dprintf.cpp;dprintf_c*;dprintf_setup.cpp;sig_install.*;basename.*;mkargv.*;except.*;strupr.*;lock_file.*;rotate_file.*;strcasestr.*;strnewp.*;condor_environ.*;setsyscalls.*;passwd_cache.*;uids.c*;chomp.*;subsystem_info.*;my_subsystem.*;distribution.*;my_distribution.*;get_random_num.*;libcondorapi_stubs.*;seteuid.*;setegid.*;condor_open.*;classad_merge.*;condor_attributes.*;simple_arg.*;compat_classad.*;compat_classad_util.*;classad_oldnew.*;condor_snutils.*;stringSpace.*;string_list.*;stl_string_utils.*;MyString.*;condor_xml_classads.*;directory*;param_functions.*;filename_tools_cpp.*;filename_tools.*;stat_info.*;${SAFE_OPEN_SRC}" ApiSrcs)
|
|
|
da2fd33 |
if(WINDOWS)
|
|
|
da2fd33 |
condor_selective_glob("directory.WINDOWS.*;directory_util.*;dynuser.WINDOWS.*;lock_file.WINDOWS.*;lsa_mgr.*;my_dynuser.*;ntsysinfo.WINDOWS.*;posix.WINDOWS.*;stat.WINDOWS.*;store_cred.*;token_cache.WINDOWS.*;truncate.WINDOWS.*" ApiSrcs)
|
|
|
da2fd33 |
set_property( TARGET utils_genparams PROPERTY FOLDER "libraries" )
|
|
|
da2fd33 |
+else()
|
|
|
da2fd33 |
+ condor_selective_glob("dprintf_syslog*" ApiSrcs)
|
|
|
da2fd33 |
endif()
|
|
|
da2fd33 |
|
|
|
da2fd33 |
condor_static_lib( condorapi "${ApiSrcs}" )
|
|
|
da2fd33 |
diff --git a/src/condor_utils/dprintf_setup.cpp b/src/condor_utils/dprintf_setup.cpp
|
|
|
da2fd33 |
index b1ccd3a..b5938e2 100644
|
|
|
da2fd33 |
--- a/src/condor_utils/dprintf_setup.cpp
|
|
|
da2fd33 |
+++ b/src/condor_utils/dprintf_setup.cpp
|
|
|
da2fd33 |
@@ -24,7 +24,9 @@
|
|
|
da2fd33 |
#include "condor_sys_types.h"
|
|
|
da2fd33 |
#include "condor_debug.h"
|
|
|
da2fd33 |
#include "dprintf_internal.h"
|
|
|
da2fd33 |
+#if !defined(WIN32)
|
|
|
da2fd33 |
#include "dprintf_syslog.h"
|
|
|
da2fd33 |
+#endif
|
|
|
da2fd33 |
#include "condor_constants.h"
|
|
|
da2fd33 |
|
|
|
da2fd33 |
#if HAVE_BACKTRACE
|
|
|
da2fd33 |
@@ -134,7 +136,7 @@ void dprintf_set_outputs(const struct dprintf_output_settings *p_info, int c_inf
|
|
|
da2fd33 |
it->outputTarget = OUTPUT_DEBUG_STR;
|
|
|
da2fd33 |
it->dprintfFunc = dprintf_to_outdbgstr;
|
|
|
da2fd33 |
}
|
|
|
da2fd33 |
-#endif
|
|
|
da2fd33 |
+#else
|
|
|
da2fd33 |
else if (logPath == "SYSLOG")
|
|
|
da2fd33 |
{
|
|
|
da2fd33 |
// Intention is to eventually user-selected
|
|
|
da2fd33 |
@@ -142,6 +144,7 @@ void dprintf_set_outputs(const struct dprintf_output_settings *p_info, int c_inf
|
|
|
da2fd33 |
it->outputTarget = SYSLOG;
|
|
|
da2fd33 |
it->userData = static_cast<void*>(DprintfSyslogFactory::NewLog(LOG_DAEMON));
|
|
|
da2fd33 |
}
|
|
|
da2fd33 |
+#endif
|
|
|
da2fd33 |
else
|
|
|
da2fd33 |
{
|
|
|
da2fd33 |
it->outputTarget = FILE_OUT;
|
|
|
da2fd33 |
@@ -224,7 +227,9 @@ void dprintf_set_outputs(const struct dprintf_output_settings *p_info, int c_inf
|
|
|
da2fd33 |
{
|
|
|
da2fd33 |
if ((it->outputTarget == SYSLOG) && (it->userData))
|
|
|
da2fd33 |
{
|
|
|
da2fd33 |
+#if !defined(WIN32)
|
|
|
da2fd33 |
delete static_cast<DprintfSyslog*>(it->userData);
|
|
|
da2fd33 |
+#endif
|
|
|
da2fd33 |
}
|
|
|
da2fd33 |
}
|
|
|
da2fd33 |
delete debugLogsOld;
|
|
|
da2fd33 |
--
|
|
|
da2fd33 |
1.7.4.1
|
|
|
da2fd33 |
|