Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hanzz/libtransport
Browse files Browse the repository at this point in the history
  • Loading branch information
jankaluza committed Mar 30, 2012
2 parents afe5ac5 + 42a3b6c commit 407e09e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
20 changes: 14 additions & 6 deletions backends/skype/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -454,9 +455,16 @@ 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=" << login_data);
LOG4CXX_INFO(logger, m_username << ": Login data=" << m_username);
write(fd, login_data.c_str(), login_data.size());
close(fd);

Expand All @@ -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 error: " << error->message);
g_error_free(error);
return;
}
Expand Down
30 changes: 26 additions & 4 deletions src/networkpluginserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 407e09e

Please sign in to comment.