summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2013-04-16 01:23:39 -0700
committerPatrick Ohly <patrick.ohly@intel.com>2013-05-13 17:49:49 +0200
commit8db33a4ba5177f1856bc76a30e216d92335a6239 (patch)
treea85231b5f15e1a3a202bdb3988471db09be6da4a
parenta21dc9a029f89d37f2e0c913e9fc0efadeba6620 (diff)
D-Bus: add helper's stdout to parent's stdout
During normal operation, the helper's messages were never printed to any output stream. They only went out via D-Bus. This was surprising when debugging syncevo-dbus-server and it's interaction with syncevo-dbus-helper. It's better to let the parent print the helper's output if the helper doesn't do it itself, so that console output is the same with and without SYNCEVOLUTION_DEBUG.
-rw-r--r--src/dbus/server/session-helper.cpp11
-rw-r--r--src/dbus/server/session.cpp34
2 files changed, 39 insertions, 6 deletions
diff --git a/src/dbus/server/session-helper.cpp b/src/dbus/server/session-helper.cpp
index 0ae993d9..4507576f 100644
--- a/src/dbus/server/session-helper.cpp
+++ b/src/dbus/server/session-helper.cpp
@@ -67,8 +67,15 @@ public:
static bool dbg = getenv("SYNCEVOLUTION_DEBUG");
if (dbg) {
- // let parent LogRedirect or utility function handle the output *in addition* to
- // logging via D-Bus
+ // Let parent LogRedirect or utility function handle the
+ // output *in addition* to logging via D-Bus. That way
+ // it'll be visible via our stdout/stderr (= console)
+ // right away.
+ //
+ // In non-debug mode, nothing should get written to
+ // stdout/stder, which got redirected into a pipe
+ // read by our parend. In that mode, the parent will include
+ // our output in its own output streams.
va_list argsCopy;
va_copy(argsCopy, args);
if (m_parentLogger) {
diff --git a/src/dbus/server/session.cpp b/src/dbus/server/session.cpp
index e5513372..8b2394c7 100644
--- a/src/dbus/server/session.cpp
+++ b/src/dbus/server/session.cpp
@@ -819,16 +819,42 @@ void Session::messagev(const MessageOptions &options,
getPath(), "");
}
+static void Logging2ServerAndStdout(Server &server,
+ const GDBusCXX::DBusObject_t &path,
+ const Logger::MessageOptions &options,
+ const char *format,
+ ...)
+{
+ va_list args;
+ va_start(args, format);
+ server.message2DBus(options, format, args, path, options.m_processName ? *options.m_processName : "");
+ va_end(args);
+}
+
static void Logging2Server(Server &server,
const GDBusCXX::DBusObject_t &path,
const std::string &strLevel,
const std::string &explanation,
const std::string &procname)
{
- server.logOutput(path,
- Logger::strToLevel(strLevel.c_str()),
- explanation,
- procname);
+ static bool dbg = getenv("SYNCEVOLUTION_DEBUG");
+
+ if (dbg) {
+ // Print to D-Bus directly. The helper handles its own
+ // printing to the console.
+ server.logOutput(path,
+ Logger::strToLevel(strLevel.c_str()),
+ explanation,
+ procname);
+ } else {
+ // Print to D-Bus and console, because the helper
+ // relies on us to do that. Its own stdout/stderr
+ // was redirected into our pipe and any output
+ // there is considered an error.
+ Logger::MessageOptions options(Logger::strToLevel(strLevel.c_str()));
+ options.m_processName = &procname;
+ Logging2ServerAndStdout(server, path, options, "%s", explanation.c_str());
+ }
}
void Session::useHelper2(const SimpleResult &result, const boost::signals2::connection &c)