[Xfce4-commits] <xfce4-taskmanager:master> Move POSIX code to task-manager.c
Mike Massonnet
noreply at xfce.org
Sun May 16 12:30:01 CEST 2010
Updating branch refs/heads/master
to b961822ba4ee1962d23622ea8ace0639f5377397 (commit)
from 8a56b552b5086ce1471de092be78abf7bf8e4aa2 (commit)
commit b961822ba4ee1962d23622ea8ace0639f5377397
Author: Mike Massonnet <mmassonnet at xfce.org>
Date: Sun May 16 12:07:17 2010 +0200
Move POSIX code to task-manager.c
The functions send_signal_to_pid() and set_priority_to_pid() are using
POSIX functions and “should” be safe in task-manager.c. Still keep the
enumeration as a bridge between virtual values and real values, there is
no benefit removing them (wasting minutes) and it won't make the code
look better (or worse).
The functions have been removed from the Linux and BSD implementations.
src/task-manager-bsd.c | 40 +----------------
src/task-manager-linux.c | 57 -----------------------
src/task-manager.c | 115 ++++++++++++++++++++++++++++++++++-----------
src/task-manager.h | 4 +-
4 files changed, 90 insertions(+), 126 deletions(-)
diff --git a/src/task-manager-bsd.c b/src/task-manager-bsd.c
index 12114a1..2d9a8a5 100644
--- a/src/task-manager-bsd.c
+++ b/src/task-manager-bsd.c
@@ -17,6 +17,7 @@
*/
#include <stdlib.h>
+#include <err.h>
/* for getpwuid() */
#include <sys/types.h>
#include <pwd.h>
@@ -26,9 +27,6 @@
#include <sys/sysctl.h>
/* for swapctl() */
#include <sys/swap.h>
-/* for kill() */
-#include <signal.h>
-#include <err.h>
/* for strlcpy() */
#include <string.h>
/* for getpagesize() */
@@ -195,39 +193,3 @@ gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64
return TRUE;
}
-gboolean send_signal_to_pid (guint task_id, gint signal)
-{
- gint ret = 0;
- if(task_id > 0 && signal != 0)
- ret = kill(task_id, signal);
- return (ret == 0) ? TRUE : FALSE;
-}
-
-
-gboolean set_priority_to_pid (guint task_id, gint prio)
-{
- gint res;
- switch (prio)
- {
- case XTM_PRIORITY_VERY_LOW:
- prio = 15;
- break;
- case XTM_PRIORITY_LOW:
- prio = 5;
- break;
- case XTM_PRIORITY_NORMAL:
- prio = 0;
- break;
- case XTM_PRIORITY_HIGH:
- prio = -5;
- break;
- case XTM_PRIORITY_VERY_HIGH:
- prio = -15;
- break;
- default:
- return TRUE;
- }
- res = setpriority (PRIO_PROCESS, task_id, prio);
- return (res == 0) ? TRUE : FALSE;
-}
-
diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c
index ece59d5..d16ba36 100644
--- a/src/task-manager-linux.c
+++ b/src/task-manager-linux.c
@@ -14,8 +14,6 @@
#include <pwd.h>
#include <unistd.h>
#include <string.h>
-#include <signal.h>
-#include <sys/resource.h>
#include <glib.h>
@@ -329,58 +327,3 @@ pid_is_sleeping (guint pid)
return (state[0] == 'T') ? TRUE : FALSE;
}
-gboolean
-send_signal_to_pid (guint pid, gint signal)
-{
- gint sig;
- gint res;
- switch (signal)
- {
- case XTM_SIGNAL_TERMINATE:
- sig = SIGTERM;
- break;
- case XTM_SIGNAL_STOP:
- sig = SIGSTOP;
- break;
- case XTM_SIGNAL_CONTINUE:
- sig = SIGCONT;
- break;
- case XTM_SIGNAL_KILL:
- sig = SIGKILL;
- break;
- default:
- return TRUE;
- }
- res = kill (pid, sig);
- return (res == 0) ? TRUE : FALSE;
-}
-
-gboolean
-set_priority_to_pid (guint pid, gint priority)
-{
- gint prio;
- gint res;
- switch (priority)
- {
- case XTM_PRIORITY_VERY_LOW:
- prio = 15;
- break;
- case XTM_PRIORITY_LOW:
- prio = 5;
- break;
- case XTM_PRIORITY_NORMAL:
- prio = 0;
- break;
- case XTM_PRIORITY_HIGH:
- prio = -5;
- break;
- case XTM_PRIORITY_VERY_HIGH:
- prio = -15;
- break;
- default:
- return TRUE;
- }
- res = setpriority (PRIO_PROCESS, pid, prio);
- return (res == 0) ? TRUE : FALSE;
-}
-
diff --git a/src/task-manager.c b/src/task-manager.c
index d878eb2..c1cd55c 100644
--- a/src/task-manager.c
+++ b/src/task-manager.c
@@ -14,6 +14,8 @@
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
+#include <signal.h>
+#include <sys/resource.h>
#include <glib-object.h>
#include <glib/gi18n.h>
@@ -92,34 +94,6 @@ _xtm_task_manager_set_model (XtmTaskManager *manager, GtkTreeModel *model)
manager->model = model;
}
-void
-get_owner_uid (guint *owner_uid, gchar **owner_uid_name)
-{
- uid_t uid;
- struct passwd *pw;
- gchar *username = NULL;
-
- uid = getuid ();
- pw = getpwuid (uid);
-
- username = g_strdup ((pw != NULL) ? pw->pw_name : "nobody");
-
- *owner_uid = (guint) uid;
- *owner_uid_name = username;
-}
-
-gchar *
-get_hostname ()
-{
-#ifndef HOST_NAME_MAX
-#define HOST_NAME_MAX 255
-#endif
- char hostname[HOST_NAME_MAX];
- if (gethostname (hostname, HOST_NAME_MAX))
- return g_strdup ("(unknown)");
- return g_strdup_printf ("%s", hostname);
-}
-
static void
model_add_task (GtkTreeModel *model, Task *task)
{
@@ -372,3 +346,88 @@ xtm_task_manager_update_model (XtmTaskManager *manager)
return;
}
+
+
+void
+get_owner_uid (guint *owner_uid, gchar **owner_uid_name)
+{
+ uid_t uid;
+ struct passwd *pw;
+ gchar *username = NULL;
+
+ uid = getuid ();
+ pw = getpwuid (uid);
+
+ username = g_strdup ((pw != NULL) ? pw->pw_name : "nobody");
+
+ *owner_uid = (guint) uid;
+ *owner_uid_name = username;
+}
+
+gchar *
+get_hostname ()
+{
+#ifndef HOST_NAME_MAX
+#define HOST_NAME_MAX 255
+#endif
+ char hostname[HOST_NAME_MAX];
+ if (gethostname (hostname, HOST_NAME_MAX))
+ return g_strdup ("(unknown)");
+ return g_strdup_printf ("%s", hostname);
+}
+
+gboolean
+send_signal_to_pid (guint pid, gint signal)
+{
+ gint sig;
+ gint res;
+ switch (signal)
+ {
+ case XTM_SIGNAL_TERMINATE:
+ sig = SIGTERM;
+ break;
+ case XTM_SIGNAL_STOP:
+ sig = SIGSTOP;
+ break;
+ case XTM_SIGNAL_CONTINUE:
+ sig = SIGCONT;
+ break;
+ case XTM_SIGNAL_KILL:
+ sig = SIGKILL;
+ break;
+ default:
+ return TRUE;
+ }
+ res = kill (pid, sig);
+ return (res == 0) ? TRUE : FALSE;
+}
+
+gboolean
+set_priority_to_pid (guint pid, gint priority)
+{
+ gint prio;
+ gint res;
+ switch (priority)
+ {
+ case XTM_PRIORITY_VERY_LOW:
+ prio = 15;
+ break;
+ case XTM_PRIORITY_LOW:
+ prio = 5;
+ break;
+ case XTM_PRIORITY_NORMAL:
+ prio = 0;
+ break;
+ case XTM_PRIORITY_HIGH:
+ prio = -5;
+ break;
+ case XTM_PRIORITY_VERY_HIGH:
+ prio = -15;
+ break;
+ default:
+ return TRUE;
+ }
+ res = setpriority (PRIO_PROCESS, pid, prio);
+ return (res == 0) ? TRUE : FALSE;
+}
+
diff --git a/src/task-manager.h b/src/task-manager.h
index cfefe64..c8fc891 100644
--- a/src/task-manager.h
+++ b/src/task-manager.h
@@ -67,8 +67,6 @@ gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64
gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system);
gboolean get_task_list (GArray *task_list);
gboolean pid_is_sleeping (guint pid);
-gboolean send_signal_to_pid (guint pid, gint signal);
-gboolean set_priority_to_pid (guint pid, gint priority);
/**
* GObject class used to update the graphical widgets.
@@ -97,5 +95,7 @@ void xtm_task_manager_update_model (XtmTaskManager *manager);
void get_owner_uid (guint *owner_uid, gchar **owner_uid_name);
gchar * get_hostname ();
+gboolean send_signal_to_pid (guint pid, gint signal);
+gboolean set_priority_to_pid (guint pid, gint priority);
#endif /* !TASK_MANAGER_H */
More information about the Xfce4-commits
mailing list