Skip to content

Commit

Permalink
Only log if LIBUDEV_STUB_LOGGING environment variable is set
Browse files Browse the repository at this point in the history
  • Loading branch information
ken committed Dec 30, 2018
1 parent 293f50d commit 2f591e4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
cmake_minimum_required (VERSION 3.5)
project(libudev_stub)

# libudev-stub requires a C++11 compiler
include(CMakeForceCompiler)
cmake_force_c_compiler(gcc-6 GCC)
cmake_force_cxx_compiler(g++-6 GCC)

set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 9)
set(CPACK_PACKAGE_VERSION_PATCH 0)
set(CPACK_PACKAGE_VERSION_PATCH 1)
set(LIBUDEV_STUB_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(LIBUDEV_SOVERSION_MAJOR "1")
set(LIBUDEV_SOVERSION "1.6.4")
Expand Down
1 change: 1 addition & 0 deletions libudev/libudev-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ _public_ int udev_monitor_filter_remove(struct udev_monitor* udev_monitor) {
ret = loader->udev_monitor_filter_remove(udev_monitor->proxy);
}
}
return ret;
}

} // extern "C"
10 changes: 10 additions & 0 deletions libudev/libudev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@
#include "libudev-internal.h"
#include "libudev1.h"

bool g_logging = false;

using namespace libudev_stub;

#if 0
// This was included to fire when the stub is loaded
// Becomes verbose if one is loading libudev a lot,
// so forget it; the logging was for debug purposes anyway
class StubEntry {
public:
StubEntry() {
LOG() << "Using libudev-stub " << STR(LIBUDEV_STUB_VERSION);
}
};
static StubEntry entry;
#endif

extern "C" {

Expand Down Expand Up @@ -69,6 +76,9 @@ _public_ struct udev* udev_new(void) {
struct udev* new_udev = new udev;
new_udev->loader = NULL;
new_udev->loader_udev = NULL;
char* logenv = secure_getenv("LIBUDEV_STUB_LOGGING");
g_logging = (logenv) ? false : true;

char* library = secure_getenv("LIBUDEV_STUB_PASSTHROUGH");
if (library) {
LOG() << "found LIBUDEV_STUB_PASSTHROUGH = " << library;
Expand Down
6 changes: 5 additions & 1 deletion libudev/logging.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <iostream>
#include <sstream>

extern bool g_logging;

namespace libudev_stub {

#define LOG() LogMessage().get()
Expand All @@ -9,7 +11,9 @@ class LogMessage {
public:
LogMessage() {}
virtual ~LogMessage() {
std::cout << "UDEV STUB: " << msg_.str().c_str() << std::endl;
if (g_logging) {
std::cout << "UDEV STUB: " << msg_.str().c_str() << std::endl;
}
}

std::ostringstream& get(void) {
Expand Down

0 comments on commit 2f591e4

Please sign in to comment.