Apply patch for BSD support from Landry Breuil
(Old svn revision: 5178)
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
2008-07-31 Mike Massonnet <mmassonnet@xfce.org>
|
||||
|
||||
* Apply patch for BSD support from Landry Breuil
|
||||
|
||||
2008-05-11 Mike Massonnet <mmassonnet@xfce.org>
|
||||
|
||||
=== Release 0.4.0 ===
|
||||
|
||||
@@ -71,6 +71,20 @@ XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.4.0])
|
||||
XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.4.0])
|
||||
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.2.0])
|
||||
|
||||
dnl ***********************************
|
||||
dnl ******* Check for OS family *******
|
||||
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=linux
|
||||
esac
|
||||
AC_MSG_RESULT([$ac_taskmanager_os_family])
|
||||
AM_CONDITIONAL([OS_BSD_FAMILY], [test x"$ac_taskmanager_os_family" = x"bsd"])
|
||||
|
||||
dnl ***********************************
|
||||
dnl *** Check for debugging support ***
|
||||
dnl ***********************************
|
||||
@@ -82,3 +96,13 @@ src/Makefile
|
||||
po/Makefile.in
|
||||
])
|
||||
|
||||
dnl ***************************
|
||||
dnl *** Print configuration ***
|
||||
dnl ***************************
|
||||
echo
|
||||
echo "Build Configuration:"
|
||||
echo
|
||||
echo "* Target OS: $target_os"
|
||||
echo "* Debug Support: $enable_debug"
|
||||
echo
|
||||
|
||||
|
||||
@@ -18,10 +18,15 @@ xfce4_taskmanager_SOURCES = \
|
||||
functions.h \
|
||||
interface.c \
|
||||
interface.h \
|
||||
xfce-taskmanager-linux.c \
|
||||
xfce-taskmanager-linux.h \
|
||||
taskmanager.h \
|
||||
types.h
|
||||
|
||||
if OS_BSD_FAMILY
|
||||
xfce4_taskmanager_SOURCES += taskmanager-bsd.c
|
||||
else
|
||||
xfce4_taskmanager_SOURCES += taskmanager-linux.c
|
||||
endif
|
||||
|
||||
xfce4_taskmanager_CFLAGS = \
|
||||
$(LIBXFCEGUI4_CFLAGS) \
|
||||
$(LIBXFCE4UTIL_CFLAGS) \
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "interface.h"
|
||||
|
||||
|
||||
#include "xfce-taskmanager-linux.h"
|
||||
#include "taskmanager.h"
|
||||
|
||||
void on_preferences(GtkButton *button);
|
||||
void on_information(GtkButton *button);
|
||||
|
||||
@@ -51,18 +51,22 @@ gboolean refresh_task_list(void)
|
||||
|
||||
if(new_tmp->pid == tmp->pid)
|
||||
{
|
||||
/* FIXME refresh me? */
|
||||
#ifdef __linux
|
||||
tmp->old_time = tmp->time;
|
||||
tmp->time = new_tmp->time;
|
||||
|
||||
tmp->old_time_percentage = tmp->time_percentage;
|
||||
tmp->time_percentage = (gdouble)(tmp->time - tmp->old_time) * (gdouble)(1/num_cpus);
|
||||
|
||||
#endif
|
||||
if(
|
||||
tmp->ppid != new_tmp->ppid ||
|
||||
strcmp(tmp->state,new_tmp->state) ||
|
||||
tmp->vsize != new_tmp->vsize ||
|
||||
tmp->rss != new_tmp->rss ||
|
||||
#ifdef __linux
|
||||
tmp->time_percentage != tmp->old_time_percentage ||
|
||||
#endif
|
||||
tmp->prio != new_tmp->prio
|
||||
)
|
||||
{
|
||||
|
||||
@@ -35,14 +35,7 @@
|
||||
|
||||
#include "types.h"
|
||||
#include "interface.h"
|
||||
|
||||
#ifdef __LINUX__
|
||||
#include "xfce-taskmanager-linux.h"
|
||||
#endif
|
||||
|
||||
#define PROC_DIR_1 "/compat/linux/proc"
|
||||
#define PROC_DIR_2 "/emul/linux/proc"
|
||||
#define PROC_DIR_3 "/proc"
|
||||
#include "taskmanager.h"
|
||||
|
||||
gboolean refresh_task_list(void);
|
||||
gdouble get_cpu_usage(system_status *sys_stat);
|
||||
|
||||
169
src/taskmanager-bsd.c
Normal file
169
src/taskmanager-bsd.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/* $Id$
|
||||
*
|
||||
* Copyright (c) 2008 Landry Breuil <landry@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
|
||||
* 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"
|
||||
/* for getpwuid() */
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
/* for sysctl() */
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
/* for kill() */
|
||||
#include <signal.h>
|
||||
#include <err.h>
|
||||
|
||||
char *state_abbrev[] = {
|
||||
"", "start", "run", "sleep", "stop", "zomb", "dead", "onproc"
|
||||
};
|
||||
|
||||
GArray *get_task_list(void)
|
||||
{
|
||||
GArray *task_list;
|
||||
int mib[6];
|
||||
size_t size;
|
||||
struct kinfo_proc2 *kp;
|
||||
struct task t;
|
||||
struct passwd *passwdp;
|
||||
double d;
|
||||
char **args, **ptr;
|
||||
char buf[127];
|
||||
int nproc, i;
|
||||
fixpt_t ccpu; /* The scheduler exponential decay value. */
|
||||
int fscale; /* The kernel fixed-point scale factor. */
|
||||
|
||||
task_list = g_array_new (FALSE, FALSE, sizeof (struct task));
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC2;
|
||||
mib[2] = KERN_PROC_ALL;
|
||||
mib[3] = 0;
|
||||
mib[4] = sizeof(struct kinfo_proc2);
|
||||
mib[5] = 0;
|
||||
if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0)
|
||||
errx(1, "could not get kern.proc2 size");
|
||||
size = 5 * size / 4; /* extra slop */
|
||||
if ((kp = malloc(size)) == NULL)
|
||||
errx(1,"failed to allocate memory for proc structures");
|
||||
mib[5] = (int)(size / sizeof(struct kinfo_proc2));
|
||||
if (sysctl(mib, 6, kp, &size, NULL, 0) < 0)
|
||||
errx(1, "could not read kern.proc2");
|
||||
nproc = (int)(size / sizeof(struct kinfo_proc2));
|
||||
for (i=0 ; i < nproc ; i++)
|
||||
{
|
||||
struct kinfo_proc2 p = kp[i];
|
||||
t.checked = FALSE;
|
||||
t.pid = p.p_pid;
|
||||
t.ppid = p.p_ppid;
|
||||
t.uid = p.p_uid;
|
||||
t.prio = p.p_priority - 22;
|
||||
t.vsize = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize;
|
||||
t.vsize *= getpagesize();
|
||||
t.rss = p.p_vm_rssize;
|
||||
g_snprintf(t.state, sizeof t.state, "%s", state_abbrev[p.p_stat]);
|
||||
/* shamelessly stolen from top/machine.c */
|
||||
/* short version: g_strlcpy(t.name, p.p_comm, strlen(p.p_comm) + 1); */
|
||||
size = 128;
|
||||
if ((args = malloc(size)) == NULL)
|
||||
errx(1,"failed to allocate memory for argv structures");
|
||||
for (;; size *= 2) {
|
||||
if ((args = realloc(args, size)) == NULL)
|
||||
errx(1,"failed to allocate memory for argv structures");
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC_ARGS;
|
||||
mib[2] = t.pid;
|
||||
mib[3] = KERN_PROC_ARGV;
|
||||
if (sysctl(mib, 4, args, &size, NULL, 0) == 0)
|
||||
break;
|
||||
}
|
||||
buf[0] = '\0';
|
||||
for (ptr = args; *ptr != NULL; ptr++) {
|
||||
if (ptr != args)
|
||||
strlcat(buf, " ", sizeof(buf));
|
||||
strlcat(buf, *ptr, sizeof(buf));
|
||||
}
|
||||
g_snprintf(t.name, sizeof t.name, "%s", buf);
|
||||
|
||||
t.time_percentage = (100.0 * ((double) p.p_pctcpu / FSCALE));
|
||||
/* get username from uid */
|
||||
passwdp = getpwuid(t.uid);
|
||||
if(passwdp != NULL && passwdp->pw_name != NULL)
|
||||
g_strlcpy(t.uname, passwdp->pw_name, sizeof t.uname);
|
||||
g_array_append_val(task_list, t);
|
||||
}
|
||||
|
||||
return task_list;
|
||||
}
|
||||
|
||||
gboolean get_cpu_usage_from_proc(system_status *sys_stat)
|
||||
{
|
||||
/* tosee: remove this, get cpu perc from CPTIME */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* vmtotal values in #pg, mem wanted in kB */
|
||||
#define pagetok(nb) ((nb) * (getpagesize() / 1024))
|
||||
|
||||
gboolean get_system_status (system_status *sys_stat)
|
||||
{
|
||||
int mib[] = {CTL_VM, VM_METER};
|
||||
struct vmtotal vmtotal;
|
||||
size_t size;
|
||||
size = sizeof(vmtotal);
|
||||
if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0)
|
||||
errx(1,"failed to get vm.meter");
|
||||
/* cheat : rm = tot used, add free to get total */
|
||||
sys_stat->mem_total = pagetok(vmtotal.t_rm + vmtotal.t_free);
|
||||
sys_stat->mem_free = pagetok(vmtotal.t_free);
|
||||
sys_stat->mem_cached = 0;
|
||||
sys_stat->mem_buffers = pagetok(vmtotal.t_rm - vmtotal.t_arm);
|
||||
size = sizeof(sys_stat->cpu_count);
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_NCPU;
|
||||
if (sysctl(mib, 2, &sys_stat->cpu_count, &size, NULL, 0) == -1)
|
||||
errx(1,"failed to get cpu count");
|
||||
/* cpu_user/idle/system unused atm so we don't care */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "xfce-taskmanager-linux.h"
|
||||
#include "taskmanager.h"
|
||||
|
||||
struct task get_task_details(gint pid)
|
||||
{
|
||||
@@ -51,67 +51,68 @@ struct task get_task_details(gint pid)
|
||||
|
||||
if((task_file = fopen(filename,"r")) != NULL)
|
||||
{
|
||||
while(fgets(buffer_status, sizeof(buffer_status), task_file) != NULL)
|
||||
{
|
||||
gint utime = 0;
|
||||
gint stime = 0;
|
||||
gint utime = 0;
|
||||
gint stime = 0;
|
||||
|
||||
sscanf(buffer_status, "%i (%255s %1s %i %i %i %i %i %255s %255s %255s %255s %255s %i %i %i %i %i %i %i %i %i %i %i %255s %255s %255s %i %255s %255s %255s %255s %255s %255s %255s %255s %255s %255s %i %255s %255s",
|
||||
&task.pid, // processid
|
||||
task.name, // processname
|
||||
task.state, // processstate
|
||||
&task.ppid, // parentid
|
||||
&idummy, // processs groupid
|
||||
fgets(buffer_status, sizeof(buffer_status), task_file);
|
||||
|
||||
&idummy, // session id
|
||||
&idummy, // tty id
|
||||
&idummy, // tpgid: The process group ID of the process running on tty of the process
|
||||
dummy, // flags
|
||||
dummy, // minflt minor faults the process has maid
|
||||
sscanf(buffer_status, "%i (%255s %1s %i %i %i %i %i %255s %255s %255s %255s %255s %i %i %i %i %i %i %i %i %i %i %i %255s %255s %255s %i %255s %255s %255s %255s %255s %255s %255s %255s %255s %255s %i %255s %255s",
|
||||
&task.pid, // processid
|
||||
task.name, // processname
|
||||
task.state, // processstate
|
||||
&task.ppid, // parentid
|
||||
&idummy, // processs groupid
|
||||
|
||||
dummy, // cminflt
|
||||
dummy, // majflt
|
||||
dummy, // cmajflt
|
||||
&utime, // utime the number of jiffies that this process has scheduled in user mode
|
||||
&stime, // stime " kernel mode
|
||||
&idummy, // session id
|
||||
&idummy, // tty id
|
||||
&idummy, // tpgid: The process group ID of the process running on tty of the process
|
||||
dummy, // flags
|
||||
dummy, // minflt minor faults the process has maid
|
||||
|
||||
&idummy, // cutime " waited for children in user
|
||||
&idummy, // cstime " kernel mode
|
||||
&idummy, // priority (nice value + fifteen)
|
||||
&task.prio, // nice range from 19 to -19 /* my change */
|
||||
&idummy, // hardcoded 0
|
||||
dummy, // cminflt
|
||||
dummy, // majflt
|
||||
dummy, // cmajflt
|
||||
&utime, // utime the number of jiffies that this process has scheduled in user mode
|
||||
&stime, // stime " kernel mode
|
||||
|
||||
&idummy, // itrealvalue time in jiffies to next SIGALRM send to this process
|
||||
&idummy, // starttime jiffies the process startet after system boot
|
||||
&task.vsize, // vsize in bytes
|
||||
&task.rss, // rss (number of pages in real memory)
|
||||
dummy, // rlim limit in bytes for rss
|
||||
&idummy, // cutime " waited for children in user
|
||||
&idummy, // cstime " kernel mode
|
||||
&idummy, // priority (nice value + fifteen)
|
||||
&task.prio, // nice range from 19 to -19 /* my change */
|
||||
&idummy, // hardcoded 0
|
||||
|
||||
dummy, // startcode
|
||||
dummy, // endcode
|
||||
&idummy, // startstack
|
||||
dummy, // kstkesp value of esp (stack pointer)
|
||||
dummy, // kstkeip value of EIP (instruction pointer)
|
||||
&idummy, // itrealvalue time in jiffies to next SIGALRM send to this process
|
||||
&idummy, // starttime jiffies the process startet after system boot
|
||||
&task.vsize, // vsize in bytes
|
||||
&task.rss, // rss (number of pages in real memory)
|
||||
dummy, // rlim limit in bytes for rss
|
||||
|
||||
dummy, // signal. bitmap of pending signals
|
||||
dummy, // blocked: bitmap of blocked signals
|
||||
dummy, // sigignore: bitmap of ignored signals
|
||||
dummy, // sigcatch: bitmap of catched signals
|
||||
dummy, // wchan
|
||||
dummy, // startcode
|
||||
dummy, // endcode
|
||||
&idummy, // startstack
|
||||
dummy, // kstkesp value of esp (stack pointer)
|
||||
dummy, // kstkeip value of EIP (instruction pointer)
|
||||
|
||||
dummy, // nswap
|
||||
dummy, // cnswap
|
||||
dummy, // exit_signal
|
||||
&idummy, // CPU number last executed on
|
||||
dummy,
|
||||
dummy, // signal. bitmap of pending signals
|
||||
dummy, // blocked: bitmap of blocked signals
|
||||
dummy, // sigignore: bitmap of ignored signals
|
||||
dummy, // sigcatch: bitmap of catched signals
|
||||
dummy, // wchan
|
||||
|
||||
dummy, // nswap
|
||||
dummy, // cnswap
|
||||
dummy, // exit_signal
|
||||
&idummy, // CPU number last executed on
|
||||
dummy,
|
||||
|
||||
dummy
|
||||
);
|
||||
|
||||
task.old_time = task.time;
|
||||
task.time = stime + utime;
|
||||
task.time_percentage = 0;
|
||||
task.rss *= pagesize;
|
||||
|
||||
dummy
|
||||
);
|
||||
task.old_time = task.time;
|
||||
task.time = stime + utime;
|
||||
task.time_percentage = 0;
|
||||
task.rss *= pagesize;
|
||||
}
|
||||
task.uid = status.st_uid;
|
||||
passwdp = getpwuid(task.uid);
|
||||
if(passwdp != NULL && passwdp->pw_name != NULL)
|
||||
@@ -22,14 +22,16 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <libxfcegui4/libxfcegui4.h>
|
||||
|
||||
#ifdef __linux
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
|
||||
Reference in New Issue
Block a user