[Uludag-commits] r17613 - in trunk/comar/comar: etc include src
uludag-commits at pardus.org.tr
uludag-commits at pardus.org.tr
10 Nis 2008 Per 13:32:38 EEST
Author: bahadir.kandemir
Date: Thu Apr 10 13:32:37 2008
New Revision: 17613
Modified:
trunk/comar/comar/etc/model.xml
trunk/comar/comar/include/log.h
trunk/comar/comar/include/process.h
trunk/comar/comar/src/dbus.c
trunk/comar/comar/src/process.c
Log:
cancel() method for tr.org.pardus.comar interface, kill all jobs of caller.
Optional jobNO argument will be added soon
Modified: trunk/comar/comar/etc/model.xml
=================================================================
--- trunk/comar/comar/etc/model.xml (original)
+++ trunk/comar/comar/etc/model.xml Thu Apr 10 13:32:37 2008
@@ -29,6 +29,9 @@
<arg name="application" type="s" direction="in"/>
<arg name="models" type="as" direction="out"/>
</method>
+ <method name="cancel">
+ <arg name="killed_jobs" type="i" direction="out"/>
+ </method>
</interface>
<interface name="Boot.Loader">
<method name="listSystems" access_label="get">
Modified: trunk/comar/comar/include/log.h
=================================================================
--- trunk/comar/comar/include/log.h (original)
+++ trunk/comar/comar/include/log.h Thu Apr 10 13:32:37 2008
@@ -11,6 +11,7 @@
#define LOG_PROC 2
#define LOG_PLCY 4
#define LOG_PERF 8
+#define LOG_ARGS 16
#define LOG_FULL 0xffffffff
int log_start(void);
Modified: trunk/comar/comar/include/process.h
=================================================================
--- trunk/comar/comar/include/process.h (original)
+++ trunk/comar/comar/include/process.h Thu Apr 10 13:32:37 2008
@@ -13,6 +13,7 @@
int from;
int to;
pid_t pid;
+ DBusMessage *bus_msg;
const char *desc;
};
Modified: trunk/comar/comar/src/dbus.c
=================================================================
--- trunk/comar/comar/src/dbus.c (original)
+++ trunk/comar/comar/src/dbus.c Thu Apr 10 13:32:37 2008
@@ -488,7 +488,9 @@
}
else {
args = PyList_AsTuple(dbus_py_import(my_proc.bus_msg));
+ log_debug(LOG_ARGS, "Arguments: %s\n", PyString_AsString(PyObject_Repr(args)));
ret = py_call_method(app, model, method, args, &result);
+ log_debug(LOG_ARGS, "Reply: %s\n", PyString_AsString(PyObject_Repr(result)));
if (ret == 1) {
log_error("Unable to find: %s (%s)\n", model, app);
@@ -509,6 +511,30 @@
free(model);
}
+//! Cancels all running jobs of sender
+static void
+dbus_cancel()
+{
+ int i, count = 0;
+ log_debug(LOG_DBUS, "Cancel requested.\n");
+ for (i = 0; i < my_proc.nr_children; i++) {
+ if (dbus_message_has_sender(my_proc.children[i].bus_msg, dbus_message_get_sender(my_proc.bus_msg))) {
+ kill(my_proc.children[i].pid, SIGKILL);
+ count++;
+ }
+ }
+ log_debug(LOG_PROC, "%d processes killed.\n", count);
+
+ if (dbus_message_get_no_reply(my_proc.bus_msg)) return;
+
+ DBusMessage *reply;
+ DBusMessageIter iter;
+ reply = dbus_message_new_method_return(my_proc.bus_msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &count);
+ dbus_send(reply);
+}
+
//! Checks if sender is allowed to call specified method
static int
dbus_policy_check(const char *sender, const char *interface, const char *method)
@@ -617,12 +643,27 @@
{
const char *sender = dbus_message_get_sender(msg);
const char *interface = dbus_message_get_interface(msg);
+ const char *path = dbus_message_get_path(msg);
const char *method = dbus_message_get_member(msg);
switch (dbus_message_get_type(msg)) {
case DBUS_MESSAGE_TYPE_METHOD_CALL:
log_debug(LOG_DBUS, "DBus method call [%s.%s] from [%s]\n", interface, method, sender);
- proc_fork(dbus_method_call, "ComarJob", conn, msg);
+
+ // Attach message to process header
+ my_proc.bus_msg = msg;
+
+ if (!interface || !path || !method) {
+ dbus_reply_error("dbus", "missing", "Missing interface, path or method.");
+ }
+ else if (strncmp(interface, cfg_bus_interface, strlen(cfg_bus_interface)) == 0 &&
+ strcmp(path, "/") == 0 && strcmp(interface, cfg_bus_interface) == 0 &&
+ strcmp(method, "cancel") == 0) {
+ dbus_cancel();
+ }
+ else {
+ proc_fork(dbus_method_call, "ComarJob", conn, msg);
+ }
break;
case DBUS_MESSAGE_TYPE_SIGNAL:
log_debug(LOG_DBUS, "DBus signal [%s.%s] from [%s]\n", interface, method, sender);
@@ -751,6 +792,9 @@
unique_name = dbus_bus_get_unique_name(conn);
log_info("Listening on %s (%s)...\n", cfg_bus_name, unique_name);
+ // Attach connection to process header
+ my_proc.bus_conn = conn;
+
while (1) {
struct pollfd fds[MAX_FDS];
DBusWatch *watch[MAX_WATCHES];
Modified: trunk/comar/comar/src/process.c
=================================================================
--- trunk/comar/comar/src/process.c (original)
+++ trunk/comar/comar/src/process.c Thu Apr 10 13:32:37 2008
@@ -131,7 +131,7 @@
//! Appends child process' information to parent's info table
static struct ProcChild *
-add_child(pid_t pid, int to, int from, const char *desc)
+add_child(pid_t pid, int to, int from, DBusMessage *bus_msg, const char *desc)
{
/*!
* Appends child process' information to parent's info table.
@@ -139,6 +139,7 @@
* @pid Process ID
* @to Input FD
* @from Output FD
+ * @bus_msg DBus message
* @desc Process description
* @return ProcChild node
*/
@@ -160,6 +161,7 @@
my_proc.children[i].from = from;
my_proc.children[i].to = to;
my_proc.children[i].pid = pid;
+ my_proc.children[i].bus_msg = bus_msg;
my_proc.children[i].desc = desc;
++my_proc.nr_children;
return &my_proc.children[i];
@@ -324,7 +326,7 @@
// parent process continues
close(fdw[0]);
close(fdr[1]);
- return add_child(pid, fdw[1], fdr[0], desc);
+ return add_child(pid, fdw[1], fdr[0], bus_msg, desc);
}
}
Uludag-commits mesaj listesiyle ilgili
daha fazla bilgi