Mailinglist Archive: yast-commit (693 mails)
| < Previous | Next > |
[yast-commit] r56014 - in /branches/tmp/lslezak/core/liby2dbus/src: DBusServerBase.cc PolKit.cc PolKit.h
- From: lslezak@xxxxxxxxxxxxxxxx
- Date: Mon, 09 Mar 2009 13:18:01 -0000
- Message-id: <E1LgfMn-0001u9-7C@xxxxxxxxxxxxxxxx>
Author: lslezak
Date: Mon Mar 9 14:18:00 2009
New Revision: 56014
URL: http://svn.opensuse.org/viewcvs/yast?rev=56014&view=rev
Log:
- dbus service - check for PolicyKit config changes at runtime
Modified:
branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc
branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc
branches/tmp/lslezak/core/liby2dbus/src/PolKit.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=56014&r1=56013&r2=56014&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc Mon Mar 9
14:18:00 2009
@@ -244,6 +244,11 @@
DBusError dbus_error;
dbus_error_init(&dbus_error);
+#ifdef HAVE_POLKIT
+ // check for changes in policykit config
+ policykit.checkPolkitChanges();
+#endif
+
// check the policy using PolicyKit
if (isActionAllowed(request, &dbus_error))
{
Modified: branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc
URL:
http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc?rev=56014&r1=56013&r2=56014&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc Mon Mar 9 14:18:00 2009
@@ -9,6 +9,14 @@
#include<map>
+extern "C"
+{
+#include <sys/select.h>
+#include <errno.h>
+}
+
+#include <cstring>
+
typedef std::map<PolKitContext *, PolKit*> PolKitMapping;
// PolKitContext * -> PolKit * mapping
@@ -96,6 +104,9 @@
polkit_error_free(polkit_error);
}
+
+ select_timeout.tv_sec = 0;
+ select_timeout.tv_usec = 0;
}
PolKit::~PolKit()
@@ -237,13 +248,68 @@
return polkit_action_validate_id(action.c_str());
}
+
+// check the registered file descriptors here,
+// if there is something to read then call
+// polkit_context_io_func(context, ready_fd)
+// to process the changes by PolicyKit
+//
+// this method must be called from the main loop
+
void PolKit::checkPolkitChanges()
{
-#warning TODO: polkit_context_io_func() is not called
+ y2debug("Checking changes in PolicyKit config...");
- // TODO: check the registered file descriptors here,
- // if there is something to read then call
- // polkit_context_io_func(context, ready_fd)
+ // filedescriptor set
+ fd_set rfds;
+
+ // init to empty set
+ FD_ZERO(&rfds);
+
+ int max_fd = -1;
+
+ for(WatchListType::const_iterator it = fd_watch_list.begin();
+ it != fd_watch_list.end();
+ ++it)
+ {
+ // add the FD to the watch set
+ FD_SET(*it, &rfds);
+
+ if (max_fd < *it)
+ {
+ max_fd = *it;
+ }
+ }
+
+ // check whether there is something to read, timeout is 0 (return
immediately)
+ int retval = ::select(max_fd + 1, &rfds, NULL, NULL, &select_timeout);
+
+ y2debug("select() result: %d", retval);
+
+ // error?
+ if (retval == -1)
+ {
+ y2error("Error in select() call: %s", ::strerror(errno));
+ }
+ // data available?
+ else if (retval > 0)
+ {
+ for(WatchListType::const_iterator it = fd_watch_list.begin();
+ it != fd_watch_list.end();
+ ++it)
+ {
+ // check the FD in the result
+ if (FD_ISSET(*it, &rfds))
+ {
+ y2debug("File descriptor %d has data available", *it);
+
+ // call the PolicyKit IO handler
+ // (the config changed callbacked will be called
+ // if the config has been changed)
+ polkit_context_io_func(context, *it);
+ }
+ }
+ }
}
void PolKit::addWatch(int fd)
Modified: branches/tmp/lslezak/core/liby2dbus/src/PolKit.h
URL:
http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/PolKit.h?rev=56014&r1=56013&r2=56014&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/PolKit.h (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/PolKit.h Mon Mar 9 14:18:00 2009
@@ -13,6 +13,11 @@
#include <dbus/dbus.h>
#include <polkit-dbus/polkit-dbus.h>
+extern "C"
+{
+#include <sys/time.h>
+}
+
class PolKit
{
public:
@@ -41,7 +46,13 @@
PolKitContext *context;
- std::list<int> fd_watch_list;
+ typedef std::list<int> WatchListType;
+
+ WatchListType fd_watch_list;
+
+ // select() timeout (set to 0 to return immediately)
+ struct timeval select_timeout;
+
};
#endif
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx
Date: Mon Mar 9 14:18:00 2009
New Revision: 56014
URL: http://svn.opensuse.org/viewcvs/yast?rev=56014&view=rev
Log:
- dbus service - check for PolicyKit config changes at runtime
Modified:
branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc
branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc
branches/tmp/lslezak/core/liby2dbus/src/PolKit.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=56014&r1=56013&r2=56014&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc Mon Mar 9
14:18:00 2009
@@ -244,6 +244,11 @@
DBusError dbus_error;
dbus_error_init(&dbus_error);
+#ifdef HAVE_POLKIT
+ // check for changes in policykit config
+ policykit.checkPolkitChanges();
+#endif
+
// check the policy using PolicyKit
if (isActionAllowed(request, &dbus_error))
{
Modified: branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc
URL:
http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc?rev=56014&r1=56013&r2=56014&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/PolKit.cc Mon Mar 9 14:18:00 2009
@@ -9,6 +9,14 @@
#include<map>
+extern "C"
+{
+#include <sys/select.h>
+#include <errno.h>
+}
+
+#include <cstring>
+
typedef std::map<PolKitContext *, PolKit*> PolKitMapping;
// PolKitContext * -> PolKit * mapping
@@ -96,6 +104,9 @@
polkit_error_free(polkit_error);
}
+
+ select_timeout.tv_sec = 0;
+ select_timeout.tv_usec = 0;
}
PolKit::~PolKit()
@@ -237,13 +248,68 @@
return polkit_action_validate_id(action.c_str());
}
+
+// check the registered file descriptors here,
+// if there is something to read then call
+// polkit_context_io_func(context, ready_fd)
+// to process the changes by PolicyKit
+//
+// this method must be called from the main loop
+
void PolKit::checkPolkitChanges()
{
-#warning TODO: polkit_context_io_func() is not called
+ y2debug("Checking changes in PolicyKit config...");
- // TODO: check the registered file descriptors here,
- // if there is something to read then call
- // polkit_context_io_func(context, ready_fd)
+ // filedescriptor set
+ fd_set rfds;
+
+ // init to empty set
+ FD_ZERO(&rfds);
+
+ int max_fd = -1;
+
+ for(WatchListType::const_iterator it = fd_watch_list.begin();
+ it != fd_watch_list.end();
+ ++it)
+ {
+ // add the FD to the watch set
+ FD_SET(*it, &rfds);
+
+ if (max_fd < *it)
+ {
+ max_fd = *it;
+ }
+ }
+
+ // check whether there is something to read, timeout is 0 (return
immediately)
+ int retval = ::select(max_fd + 1, &rfds, NULL, NULL, &select_timeout);
+
+ y2debug("select() result: %d", retval);
+
+ // error?
+ if (retval == -1)
+ {
+ y2error("Error in select() call: %s", ::strerror(errno));
+ }
+ // data available?
+ else if (retval > 0)
+ {
+ for(WatchListType::const_iterator it = fd_watch_list.begin();
+ it != fd_watch_list.end();
+ ++it)
+ {
+ // check the FD in the result
+ if (FD_ISSET(*it, &rfds))
+ {
+ y2debug("File descriptor %d has data available", *it);
+
+ // call the PolicyKit IO handler
+ // (the config changed callbacked will be called
+ // if the config has been changed)
+ polkit_context_io_func(context, *it);
+ }
+ }
+ }
}
void PolKit::addWatch(int fd)
Modified: branches/tmp/lslezak/core/liby2dbus/src/PolKit.h
URL:
http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/PolKit.h?rev=56014&r1=56013&r2=56014&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/PolKit.h (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/PolKit.h Mon Mar 9 14:18:00 2009
@@ -13,6 +13,11 @@
#include <dbus/dbus.h>
#include <polkit-dbus/polkit-dbus.h>
+extern "C"
+{
+#include <sys/time.h>
+}
+
class PolKit
{
public:
@@ -41,7 +46,13 @@
PolKitContext *context;
- std::list<int> fd_watch_list;
+ typedef std::list<int> WatchListType;
+
+ WatchListType fd_watch_list;
+
+ // select() timeout (set to 0 to return immediately)
+ struct timeval select_timeout;
+
};
#endif
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx
| < Previous | Next > |