From 9d81165a53c931d95ec560bf13d9ee6d575a064c Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Thu, 29 Mar 2012 08:59:04 +0200 Subject: [PATCH 1/3] login tweak --- backends/skype/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/skype/main.cpp b/backends/skype/main.cpp index aa237178..7571fedc 100644 --- a/backends/skype/main.cpp +++ b/backends/skype/main.cpp @@ -456,7 +456,7 @@ void Skype::login() { &fd_output, NULL /*error*/); std::string login_data = std::string(m_username + " " + m_password + "\n"); - LOG4CXX_INFO(logger, m_username << ": Login data=" << login_data); + LOG4CXX_INFO(logger, m_username << ": Login data=" << m_username); write(fd, login_data.c_str(), login_data.size()); close(fd); From ee06ad97fd21c5bec3eb7a5a61d3acd7dff96f4b Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Thu, 29 Mar 2012 09:21:33 +0200 Subject: [PATCH 2/3] More logging --- backends/skype/main.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/backends/skype/main.cpp b/backends/skype/main.cpp index 7571fedc..ae0bbab3 100644 --- a/backends/skype/main.cpp +++ b/backends/skype/main.cpp @@ -366,7 +366,7 @@ bool Skype::createDBusProxy() { LOG4CXX_INFO(logger, m_username << ":" << error->message); if (m_counter == 15) { - LOG4CXX_ERROR(logger, "Logging out, proxy couldn't be created"); + LOG4CXX_ERROR(logger, "Logging out, proxy couldn't be created: " << error->message); np->handleDisconnected(m_user, pbnetwork::CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, error->message); logout(); g_error_free(error); @@ -444,7 +444,8 @@ void Skype::login() { gchar* argv[6] = {"skype", "--disable-cleanlooks", "--pipelogin", "--dbpath", db, 0}; int fd; - g_spawn_async_with_pipes(NULL, + GError *error = NULL; + bool spawned = g_spawn_async_with_pipes(NULL, argv, NULL /*envp*/, G_SPAWN_SEARCH_PATH, @@ -454,7 +455,14 @@ void Skype::login() { &fd, NULL, &fd_output, - NULL /*error*/); + &error); + + if (!spawned) { + LOG4CXX_ERROR(logger, "Error spawning the Skype instance: " << error->message) + np->handleDisconnected(m_user, pbnetwork::CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, "Error spawning the Skype instance."); + return; + } + std::string login_data = std::string(m_username + " " + m_password + "\n"); LOG4CXX_INFO(logger, m_username << ": Login data=" << m_username); write(fd, login_data.c_str(), login_data.size()); @@ -469,12 +477,12 @@ void Skype::login() { if (m_connection == NULL) { - LOG4CXX_INFO(logger, "Creating DBus connection."); + LOG4CXX_INFO(logger, "Creating DBUS connection."); GError *error = NULL; m_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (m_connection == NULL && error != NULL) { - LOG4CXX_INFO(logger, m_username << ": DBUS Error: " << error->message); + LOG4CXX_INFO(logger, m_username << ": Creating DBUS Connection rrror: " << error->message); g_error_free(error); return; } From 42a3b6c1d5008343da25e0b5023ea8745eaef7fb Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Thu, 29 Mar 2012 09:58:19 +0200 Subject: [PATCH 3/3] More backend spawning logging --- backends/skype/main.cpp | 2 +- src/networkpluginserver.cpp | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/backends/skype/main.cpp b/backends/skype/main.cpp index ae0bbab3..1ccd81e4 100644 --- a/backends/skype/main.cpp +++ b/backends/skype/main.cpp @@ -482,7 +482,7 @@ void Skype::login() { m_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (m_connection == NULL && error != NULL) { - LOG4CXX_INFO(logger, m_username << ": Creating DBUS Connection rrror: " << error->message); + LOG4CXX_INFO(logger, m_username << ": Creating DBUS Connection error: " << error->message); g_error_free(error); return; } diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 90d66759..fdd68e68 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -163,9 +163,14 @@ static unsigned long exec_(std::string path, const char *host, const char *port, if ( pid == 0 ) { setsid(); // child process - exit(execv(argv[0], argv)); + errno = 0; + int ret = execv(argv[0], argv); + if (ret == -1) { + exit(errno); + } + exit(0); } else if ( pid < 0 ) { - // fork failed + LOG4CXX_ERROR(logger, "Fork failed"); } free(p); @@ -258,12 +263,29 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U LOG4CXX_INFO(logger, "Listening on host " << CONFIG_STRING(m_config, "service.backend_host") << " port " << CONFIG_STRING(m_config, "service.backend_port")); + unsigned long pid = exec_(CONFIG_STRING(m_config, "service.backend"), CONFIG_STRING(m_config, "service.backend_host").c_str(), CONFIG_STRING(m_config, "service.backend_port").c_str(), m_config->getConfigFile().c_str()); + LOG4CXX_INFO(logger, "Backend should now connect to Spectrum2 instance. Spectrum2 won't accept any connection before backend connects"); + #ifndef _WIN32 + // wait if the backend process will still be alive after 1 second + sleep(1); + pid_t result; + int status; + result = waitpid(-1, &status, WNOHANG); + if (result != 0) { + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) != 0) { + LOG4CXX_ERROR(logger, "Backend can not be started, exit_code=" << WEXITSTATUS(status) << ", possible error: " << strerror(WEXITSTATUS(status))); + } + } + else { + LOG4CXX_ERROR(logger, "Backend can not be started"); + } + } + signal(SIGCHLD, SigCatcher); #endif - exec_(CONFIG_STRING(m_config, "service.backend"), CONFIG_STRING(m_config, "service.backend_host").c_str(), CONFIG_STRING(m_config, "service.backend_port").c_str(), m_config->getConfigFile().c_str()); - LOG4CXX_INFO(logger, "Backend should now connect to Spectrum2 instance. Spectrum2 won't accept any connection before backend connects"); } NetworkPluginServer::~NetworkPluginServer() {