[Xfce4-commits] <xfce4-taskmanager:master> Add support for Solaris from Peter Tribble

Mike Massonnet mmassonnet at xfce.org
Thu Sep 3 19:42:01 CEST 2009


Updating branch refs/heads/master
         to 9e43755ce3643ed0b0be8e4da50cbcc2b948a566 (commit)
       from cf4f5162dff3533cc8d4bade06aa7bc9a4e70bad (commit)

commit 9e43755ce3643ed0b0be8e4da50cbcc2b948a566
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Thu Sep 3 19:39:33 2009 +0200

    Add support for Solaris from Peter Tribble

 ChangeLog                 |    4 +
 configure.in.in           |   12 ++-
 src/Makefile.am           |    6 +-
 src/taskmanager-bsd.c     |    3 +-
 src/taskmanager-linux.c   |    5 +-
 src/taskmanager-solaris.c |  207 +++++++++++++++++++++++++++++++++++++++++++++
 src/taskmanager.h         |    6 +-
 7 files changed, 231 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ae43b01..aee2187 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-09-03	Mike Massonnet <mmassonnet at xfce.org>
+
+	* Add support for Solaris from Peter Tribble
+
 2008-09-21	Mike Massonnet <mmassonnet at xfce.org>
 
 	* Fix build for libtool 2.2 (or at least for ArchLinux)
diff --git a/configure.in.in b/configure.in.in
index d22a2d6..279ec05 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -9,7 +9,7 @@ dnl ***************************
 m4_define([taskmanager_version_major], [0])
 m4_define([taskmanager_version_minor], [4])
 m4_define([taskmanager_version_micro], [1])
-m4_define([taskmanager_version_build], [r at REVISION@])
+m4_define([taskmanager_version_build], [@REVISION@])
 m4_define([taskmanager_version_tag], [git])
 m4_define([taskmanager_version], [taskmanager_version_major().taskmanager_version_minor().taskmanager_version_micro()ifelse(taskmanager_version_tag(), [git], [taskmanager_version_tag()-taskmanager_version_build()], [taskmanager_version_tag()])])
 
@@ -78,13 +78,19 @@ dnl ***********************************
 AC_MSG_CHECKING([for operating system family])
 case "$target_os" in
   dragonfly*|freebsd*|netbsd*|openbsd*|darwin*)
-    ac_taskmanager_os_family=bsd
+    ac_taskmanager_os_family="bsd"
+    ;;
+  solaris*)
+    ac_taskmanager_os_family="solaris"
     ;;
   *)
-    ac_taskmanager_os_family=linux
+    ac_taskmanager_os_family="linux"
+    ;;
   esac
 AC_MSG_RESULT([$ac_taskmanager_os_family])
 AM_CONDITIONAL([OS_BSD_FAMILY], [test x"$ac_taskmanager_os_family" = x"bsd"])
+AM_CONDITIONAL([OS_SOLARIS], [test x"$ac_taskmanager_os_family" = x"solaris"])
+AM_CONDITIONAL([OS_LINUX], [test x"$ac_taskmanager_os_family" = x"linux"])
 
 dnl ***********************************
 dnl *** Check for debugging support ***
diff --git a/src/Makefile.am b/src/Makefile.am
index 8de8449..8ecfa1f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,7 +23,11 @@ xfce4_taskmanager_SOURCES =						\
 
 if OS_BSD_FAMILY
 xfce4_taskmanager_SOURCES += taskmanager-bsd.c
-else
+endif
+if OS_SOLARIS
+xfce4_taskmanager_SOURCES += taskmanager-linux.c
+endif
+if OS_LINUX
 xfce4_taskmanager_SOURCES += taskmanager-linux.c
 endif
 
diff --git a/src/taskmanager-bsd.c b/src/taskmanager-bsd.c
index 4d1a98d..3e4dc05 100644
--- a/src/taskmanager-bsd.c
+++ b/src/taskmanager-bsd.c
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (c) 2008 Landry Breuil <landry at xfce.org>
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/src/taskmanager-linux.c b/src/taskmanager-linux.c
index cfe10fe..817361f 100644
--- a/src/taskmanager-linux.c
+++ b/src/taskmanager-linux.c
@@ -1,7 +1,6 @@
-/* $Id$
- *
+/*
  * Copyright (c) 2006  Johannes Zellner <webmaster at nebulon.de>
- *               2008  Mike Massonnet <mmassonnet at xfce.org>
+ * Copyright (c) 2008  Mike Massonnet <mmassonnet at xfce.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/src/taskmanager-solaris.c b/src/taskmanager-solaris.c
new file mode 100644
index 0000000..c4ad724
--- /dev/null
+++ b/src/taskmanager-solaris.c
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2009  Peter Tribble <peter.tribble at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "taskmanager.h"
+
+static void init_stats()
+{
+	kc = kstat_open();
+}
+
+struct task get_task_details(gint pid)
+{
+	struct task task;
+	gchar filename[255];
+	gchar pstate[2];
+	int fd;
+	struct passwd *passwdp;
+	struct psinfo thisproc;
+
+	sprintf(filename, "/proc/%i/psinfo", pid);
+
+	task.pid = pid;
+	task.checked = FALSE;
+
+	if ((fd = open(filename, O_RDONLY)) > 0)
+	{
+	if (read(fd, &thisproc, sizeof(psinfo_t)) == sizeof(psinfo_t))
+	{
+	g_strlcpy(task.name,thisproc.pr_fname,64);
+	sprintf(pstate, "%c", thisproc.pr_lwp.pr_sname);
+	g_strlcpy(task.state, pstate, 16);
+	task.ppid = (gint) thisproc.pr_ppid;
+	task.size = (gint) thisproc.pr_size;
+	task.rss = (gint) thisproc.pr_rssize;
+	task.uid = (gint) thisproc.pr_uid;
+		passwdp = getpwuid(thisproc.pr_uid);
+		if(passwdp != NULL && passwdp->pw_name != NULL)
+			g_strlcpy(task.uname, passwdp->pw_name, sizeof task.uname);
+	/*
+	 * To get the appropriate precision we need to multiply up by 10000
+	 * so that when we convert to a percentage we can represent 0.01%.
+	 */
+	task.time = 10000*thisproc.pr_time.tv_sec + thisproc.pr_time.tv_nsec/100000;
+	task.old_time = task.time;
+	task.time_percentage = 0;
+	}
+	close(fd);
+	}
+
+	return task;
+}
+
+GArray *get_task_list(void)
+{
+	DIR *dir;
+	struct dirent *dir_entry;
+	GArray *task_list;
+
+	task_list = g_array_new (FALSE, FALSE, sizeof (struct task));
+	
+	if((dir = opendir("/proc/")) == NULL)
+	{
+		fprintf(stderr, "Error: couldn't load the /proc directory\n");
+		return NULL;
+	}
+
+	gint count = 0;
+	
+	while((dir_entry = readdir(dir)) != NULL)
+	{
+		if(atoi(dir_entry->d_name) != 0)
+		{
+			struct task task = get_task_details(atoi(dir_entry->d_name));
+			if(task.pid != -1)
+				g_array_append_val(task_list, task);
+		}
+		count++;
+	}
+
+	closedir(dir);
+
+	return task_list;
+}
+
+gboolean get_cpu_usage_from_proc(system_status *sys_stat)
+{
+	gboolean retval = FALSE;
+	kstat_t *ksp;
+	kstat_named_t *knp;
+
+	if (!kc)
+	{
+		init_stats();
+	}
+
+	if ( sys_stat->valid_proc_reading == TRUE ) {
+		sys_stat->cpu_old_jiffies =
+			sys_stat->cpu_user +
+			sys_stat->cpu_nice +
+			sys_stat->cpu_system+
+			sys_stat->cpu_idle;
+		sys_stat->cpu_old_used =
+			sys_stat->cpu_user +
+			sys_stat->cpu_nice +
+			sys_stat->cpu_system;
+	} else {
+		sys_stat->cpu_old_jiffies = 0;
+	}
+
+	sys_stat->valid_proc_reading = FALSE;
+
+	kstat_chain_update(kc);
+
+	for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next)
+	{
+		if (!strcmp(ksp->ks_module, "cpu") && !strcmp(ksp->ks_name, "sys"))
+		{
+			kstat_read(kc, ksp, NULL);
+			knp = kstat_data_lookup(ksp, "cpu_ticks_user");
+			sys_stat->cpu_user = knp->value.ui64;
+			knp = kstat_data_lookup(ksp, "cpu_ticks_kernel");
+			sys_stat->cpu_system = knp->value.ui64;
+			knp = kstat_data_lookup(ksp, "cpu_ticks_idle");
+			sys_stat->cpu_idle = knp->value.ui64;
+			sys_stat->cpu_nice = 0L;
+			sys_stat->valid_proc_reading = TRUE;
+			retval = TRUE;
+		}
+	}
+        return retval;
+}
+
+gboolean get_system_status (system_status *sys_stat)
+{
+	kstat_t *ksp;
+	kstat_named_t *knp;
+
+	if (!kc)
+	{
+		init_stats();
+	}
+
+	if (ksp = kstat_lookup(kc, "unix", 0, "system_pages"))
+	{
+		kstat_read(kc, ksp, NULL);
+		knp = kstat_data_lookup(ksp, "physmem");
+		sys_stat->mem_total = (getpagesize()*knp->value.ui64)/1024;
+		knp = kstat_data_lookup(ksp, "freemem");
+		sys_stat->mem_free = (getpagesize()*knp->value.ui64)/1024;
+		sys_stat->mem_cached = 0;
+	}
+	
+	sys_stat->cpu_count = 0;
+	kstat_chain_update(kc);
+
+	for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next)
+	{
+		if (!strcmp(ksp->ks_module, "cpu_info"))
+		{
+			sys_stat->cpu_count++;
+		}
+	}
+	
+	return TRUE;
+}
+
+void send_signal_to_task(gint task_id, gint signal)
+{
+	if(task_id > 0 && signal != 0)
+	{
+		gint ret = 0;
+		
+		ret = kill(task_id, signal);
+
+		if(ret != 0)
+			xfce_err(_("Couldn't send signal to the task with ID %d"), signal, task_id);
+	}
+}
+
+
+void set_priority_to_task(gint task_id, gint prio)
+{
+	if(task_id > 0)
+	{
+		gchar command[128] = "";
+		g_sprintf(command, "renice %d %d > /dev/null", prio, task_id);
+		
+		if(system(command) != 0)
+			xfce_err(_("Couldn't set priority %d to the task with ID %d"), prio, task_id);
+	}
+}
+
diff --git a/src/taskmanager.h b/src/taskmanager.h
index f47fced..79cdc0e 100644
--- a/src/taskmanager.h
+++ b/src/taskmanager.h
@@ -1,6 +1,6 @@
-/* $Id$
- *
- * Copyright (c) 2006 Johannes Zellner, <webmaster at nebulon.de>
+/*
+ * Copyright (c) 2006 Johannes Zellner <webmaster at nebulon.de>
+ * Copyright (c) 2008 Mike Massonnet <mmassonnet at xfce.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by



More information about the Xfce4-commits mailing list