Kaydet (Commit) 392d13cd authored tarafından Bahadır Kandemir's avatar Bahadır Kandemir

cancel() method for tr.org.pardus.comar interface, kill all jobs of caller.

Optional jobNO argument will be added soon
üst 6bb1a473
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
<arg name="application" type="s" direction="in"/> <arg name="application" type="s" direction="in"/>
<arg name="models" type="as" direction="out"/> <arg name="models" type="as" direction="out"/>
</method> </method>
<method name="cancel">
<arg name="killed_jobs" type="i" direction="out"/>
</method>
</interface> </interface>
<interface name="Boot.Loader"> <interface name="Boot.Loader">
<method name="listSystems" access_label="get"> <method name="listSystems" access_label="get">
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LOG_PROC 2 #define LOG_PROC 2
#define LOG_PLCY 4 #define LOG_PLCY 4
#define LOG_PERF 8 #define LOG_PERF 8
#define LOG_ARGS 16
#define LOG_FULL 0xffffffff #define LOG_FULL 0xffffffff
int log_start(void); int log_start(void);
......
...@@ -13,6 +13,7 @@ struct ProcChild { ...@@ -13,6 +13,7 @@ struct ProcChild {
int from; int from;
int to; int to;
pid_t pid; pid_t pid;
DBusMessage *bus_msg;
const char *desc; const char *desc;
}; };
......
...@@ -488,7 +488,9 @@ dbus_app_methods(const char *interface, const char *path, const char *method) ...@@ -488,7 +488,9 @@ dbus_app_methods(const char *interface, const char *path, const char *method)
} }
else { else {
args = PyList_AsTuple(dbus_py_import(my_proc.bus_msg)); 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); ret = py_call_method(app, model, method, args, &result);
log_debug(LOG_ARGS, "Reply: %s\n", PyString_AsString(PyObject_Repr(result)));
if (ret == 1) { if (ret == 1) {
log_error("Unable to find: %s (%s)\n", model, app); log_error("Unable to find: %s (%s)\n", model, app);
...@@ -509,6 +511,30 @@ dbus_app_methods(const char *interface, const char *path, const char *method) ...@@ -509,6 +511,30 @@ dbus_app_methods(const char *interface, const char *path, const char *method)
free(model); 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 //! Checks if sender is allowed to call specified method
static int static int
dbus_policy_check(const char *sender, const char *interface, const char *method) dbus_policy_check(const char *sender, const char *interface, const char *method)
...@@ -617,12 +643,27 @@ filter_func(DBusConnection *conn, DBusMessage *msg, void *data) ...@@ -617,12 +643,27 @@ filter_func(DBusConnection *conn, DBusMessage *msg, void *data)
{ {
const char *sender = dbus_message_get_sender(msg); const char *sender = dbus_message_get_sender(msg);
const char *interface = dbus_message_get_interface(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); const char *method = dbus_message_get_member(msg);
switch (dbus_message_get_type(msg)) { switch (dbus_message_get_type(msg)) {
case DBUS_MESSAGE_TYPE_METHOD_CALL: case DBUS_MESSAGE_TYPE_METHOD_CALL:
log_debug(LOG_DBUS, "DBus method call [%s.%s] from [%s]\n", interface, method, sender); 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; break;
case DBUS_MESSAGE_TYPE_SIGNAL: case DBUS_MESSAGE_TYPE_SIGNAL:
log_debug(LOG_DBUS, "DBus signal [%s.%s] from [%s]\n", interface, method, sender); log_debug(LOG_DBUS, "DBus signal [%s.%s] from [%s]\n", interface, method, sender);
...@@ -751,6 +792,9 @@ dbus_listen() ...@@ -751,6 +792,9 @@ dbus_listen()
unique_name = dbus_bus_get_unique_name(conn); unique_name = dbus_bus_get_unique_name(conn);
log_info("Listening on %s (%s)...\n", cfg_bus_name, unique_name); log_info("Listening on %s (%s)...\n", cfg_bus_name, unique_name);
// Attach connection to process header
my_proc.bus_conn = conn;
while (1) { while (1) {
struct pollfd fds[MAX_FDS]; struct pollfd fds[MAX_FDS];
DBusWatch *watch[MAX_WATCHES]; DBusWatch *watch[MAX_WATCHES];
......
...@@ -131,7 +131,7 @@ proc_init(int argc, char *argv[], const char *name) ...@@ -131,7 +131,7 @@ proc_init(int argc, char *argv[], const char *name)
//! Appends child process' information to parent's info table //! Appends child process' information to parent's info table
static struct ProcChild * 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. * Appends child process' information to parent's info table.
...@@ -139,6 +139,7 @@ add_child(pid_t pid, int to, int from, const char *desc) ...@@ -139,6 +139,7 @@ add_child(pid_t pid, int to, int from, const char *desc)
* @pid Process ID * @pid Process ID
* @to Input FD * @to Input FD
* @from Output FD * @from Output FD
* @bus_msg DBus message
* @desc Process description * @desc Process description
* @return ProcChild node * @return ProcChild node
*/ */
...@@ -160,6 +161,7 @@ add_child(pid_t pid, int to, int from, const char *desc) ...@@ -160,6 +161,7 @@ add_child(pid_t pid, int to, int from, const char *desc)
my_proc.children[i].from = from; my_proc.children[i].from = from;
my_proc.children[i].to = to; my_proc.children[i].to = to;
my_proc.children[i].pid = pid; my_proc.children[i].pid = pid;
my_proc.children[i].bus_msg = bus_msg;
my_proc.children[i].desc = desc; my_proc.children[i].desc = desc;
++my_proc.nr_children; ++my_proc.nr_children;
return &my_proc.children[i]; return &my_proc.children[i];
...@@ -324,7 +326,7 @@ proc_fork(void (*child_func)(void), const char *desc, DBusConnection *bus_conn, ...@@ -324,7 +326,7 @@ proc_fork(void (*child_func)(void), const char *desc, DBusConnection *bus_conn,
// parent process continues // parent process continues
close(fdw[0]); close(fdw[0]);
close(fdr[1]); close(fdr[1]);
return add_child(pid, fdw[1], fdr[0], desc); return add_child(pid, fdw[1], fdr[0], bus_msg, desc);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment