[yast-commit] r55363 - in /branches/tmp/lslezak/core/liby2dbus/src: DBusServerBase.cc DBusServerBase.h
Author: lslezak Date: Mon Feb 9 16:22:02 2009 New Revision: 55363 URL: http://svn.opensuse.org/viewcvs/yast?rev=55363&view=rev Log: - do not use SIGALARM for exiting, count the read timeouts instead Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc?rev=55363&r1=55362&r2=55363&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc Mon Feb 9 16:22:02 2009 @@ -12,24 +12,12 @@ #include <ycp/y2log.h> -extern "C" -{ -// nanosleep() -#include <time.h> -// stat() -#include <sys/stat.h> -#include <unistd.h> -#include <signal.h> -} - -// ostringstream -#include <sstream> - -// std::pair -#include <utility> +// timeout for reading a DBus message (in miliseconds) +#define DBUS_TIMEOUT_VALUE 15000 +// the count of timeout events before exiting +#define DBUS_TIMEOUT_COUNT 2 -// use atomic type in signal handler -static sig_atomic_t finish = 0; +int timeout_counter = DBUS_TIMEOUT_COUNT; DBusServerBase::DBusServerBase() { @@ -51,38 +39,6 @@ return connection.connect(bt, service_name.c_str()); } -// set 30 second timer -void DBusServerBase::resetTimer() -{ - ::alarm(30); -} - -// NOTE: this is a signal handler, do only really necessary tasks here! -// be aware of non-reentrant functions! -void sig_timer(int signal, siginfo_t *info, void *data) -{ - if (signal == SIGALRM) - { - // set the finish flag for the main loop - finish = 1; - } -} - -void DBusServerBase::registerSignalHandler() -{ - struct sigaction new_action, old_action; - - // use sa_sigaction parameter - new_action.sa_flags = SA_SIGINFO; - new_action.sa_sigaction = &sig_timer; - ::sigemptyset(&new_action.sa_mask); - - if (::sigaction(SIGALRM, &new_action, &old_action)) - { - y2error("Cannot register SIGALRM handler!"); - } -} - bool DBusServerBase::canFinish() { // check if clients are still running, @@ -125,17 +81,15 @@ y2milestone("Listening for incoming DBus messages..."); if (forever) - y2milestone("Timer disabled"); - else - registerSignalHandler(); + y2milestone("Shutdown timer disabled"); // mainloop while (true) { // the time is over - if (finish) + if (!timeout_counter) { - y2milestone("Timout signal received"); + y2milestone("Timout reached"); if (canFinish()) { @@ -144,28 +98,26 @@ else { // reset the flag - finish = 0; - - // set a new timer - resetTimer(); + timeout_counter = DBUS_TIMEOUT_COUNT; } } - // set 1 second timeout - connection.setTimeout(1000); // try reading a message from DBus DBusMsg request(connection.receive()); // check if a message was received if (request.empty()) - { + { + // wait for a DBus message + connection.setTimeout(DBUS_TIMEOUT_VALUE); + + // decrease the timeout counter + if (! forever) + timeout_counter--; + continue; } - // reset the timer when a message is received - if (! forever) - resetTimer(); - // create a reply to the message DBusMsg reply; Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h?rev=55363&r1=55362&r2=55363&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h Mon Feb 9 16:22:02 2009 @@ -8,12 +8,6 @@ #include "config.h" -extern "C" -{ -#include <unistd.h> -#include <signal.h> -} - #include "DBusConn.h" #include "DBusCaller.h" #include "DBusSignature.h" @@ -23,7 +17,6 @@ #endif #include <functional> - #include <map> class DBusServerBase @@ -67,8 +60,6 @@ DBusServerBase(const DBusServerBase&); DBusServerBase& operator=(const DBusServerBase&); - void resetTimer(); - void registerSignalHandler(); bool canFinish(); bool isActionAllowed(const DBusMsg &msg); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
lslezak@svn.opensuse.org