diff options
author | Martin Baulig <martin@home-of-linux.org> | 1998-08-06 21:57:45 +0000 |
---|---|---|
committer | Martin Baulig <martin@src.gnome.org> | 1998-08-06 21:57:45 +0000 |
commit | 0a7bd78704a521b2ce575723b05ee379f75ba9ee (patch) | |
tree | 0b6ada18885c85c1fd50e171c0fb0dab8df6d485 /sysdeps | |
parent | 2e454140f124d41aa08081c09ea0efcb0e6293e5 (diff) | |
download | libgtop-0a7bd78704a521b2ce575723b05ee379f75ba9ee.tar.gz |
Using `GLIBTOP_GUILE' instead of `HAVE_GUILE' so one should be able to use
1998-08-06 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/*.h: Using `GLIBTOP_GUILE' instead of `HAVE_GUILE'
so one should be able to use libgtop without guile in an application
even if guile is installed.
* sysdeps/common/mountlist.c: Fixed some `xstrdup' problems.
* lib/open.c: Now correctly reading server features for
`GLIBTOP_METHOD_PIPE'.
* sysdeps/freebsd: New directory.
Diffstat (limited to 'sysdeps')
26 files changed, 989 insertions, 5 deletions
diff --git a/sysdeps/Makefile.am b/sysdeps/Makefile.am index 20e6c7c2..29e6fffe 100644 --- a/sysdeps/Makefile.am +++ b/sysdeps/Makefile.am @@ -6,4 +6,5 @@ endif SUBDIRS = @sysdeps_dir@ common names $(guile_SUBDIRS) -DIST_SUBDIRS = common guile linux kernel names osf1 stub sun4 +DIST_SUBDIRS = common guile linux kernel names osf1 stub sun4 \ + freebsd diff --git a/sysdeps/common/mountlist.c b/sysdeps/common/mountlist.c index 8545e097..77f9755a 100644 --- a/sysdeps/common/mountlist.c +++ b/sysdeps/common/mountlist.c @@ -360,7 +360,7 @@ read_filesystem_list (need_fs_type, all_fs) #ifdef __NetBSD__ me->me_type = xstrdup (fsp->f_fstypename); #else - me->me_type = fstype_to_string (fsp->f_type); + me->me_type = xstrdup (fstype_to_string (fsp->f_type)); #endif me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ me->me_next = NULL; @@ -385,7 +385,7 @@ read_filesystem_list (need_fs_type, all_fs) me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); me->me_devname = xstrdup (fsd.fd_req.devname); me->me_mountdir = xstrdup (fsd.fd_req.path); - me->me_type = gt_names[fsd.fd_req.fstype]; + me->me_type = xstrdup (gt_names[fsd.fd_req.fstype]); me->me_dev = fsd.fd_req.dev; me->me_next = NULL; @@ -422,7 +422,7 @@ read_filesystem_list (need_fs_type, all_fs) me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); me->me_devname = xstrdup (stats[counter].f_mntfromname); me->me_mountdir = xstrdup (stats[counter].f_mntonname); - me->me_type = mnt_names[stats[counter].f_type]; + me->me_type = xstrdup (mnt_names[stats[counter].f_type]); me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ me->me_next = NULL; @@ -457,7 +457,7 @@ read_filesystem_list (need_fs_type, all_fs) #endif me->me_mountdir = xstrdup (mnt.mt_filsys); me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ - me->me_type = ""; + me->me_type = xstrdup (""); #ifdef GETFSTYP /* SVR3. */ if (need_fs_type) { diff --git a/sysdeps/freebsd/.cvsignore b/sysdeps/freebsd/.cvsignore new file mode 100644 index 00000000..259351e1 --- /dev/null +++ b/sysdeps/freebsd/.cvsignore @@ -0,0 +1,25 @@ +.deps +.libs +Makefile +Makefile.in +close.lo +cpu.lo +init.lo +libgtop_sysdeps.la +loadavg.lo +mem.lo +msg_limits.lo +open.lo +prockernel.lo +proclist.lo +procmem.lo +procsegment.lo +procsignal.lo +procstate.lo +proctime.lo +procuid.lo +sem_limits.lo +shm_limits.lo +swap.lo +sysdeps.lo +uptime.lo diff --git a/sysdeps/freebsd/Makefile.am b/sysdeps/freebsd/Makefile.am new file mode 100644 index 00000000..046ec1bd --- /dev/null +++ b/sysdeps/freebsd/Makefile.am @@ -0,0 +1,15 @@ +LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@ + +CFLAGS = -Wall -W @CFLAGS@ + +lib_LTLIBRARIES = libgtop_sysdeps.la libgtop_sysdeps_suid.la + +libgtop_sysdeps_la_SOURCES = nosuid.c siglist.c + +libgtop_sysdeps_suid_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \ + uptime.c loadavg.c shm_limits.c msg_limits.c \ + sem_limits.c proclist.c procstate.c procuid.c \ + proctime.c procmem.c procsignal.c prockernel.c \ + procsegment.c + +include_HEADERS = glibtop_server.h glibtop_machine.h diff --git a/sysdeps/freebsd/close.c b/sysdeps/freebsd/close.c new file mode 100644 index 00000000..9506f275 --- /dev/null +++ b/sysdeps/freebsd/close.c @@ -0,0 +1,28 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <glibtop/close.h> + +/* Closes pipe to gtop server. */ + +void +glibtop_close_s (glibtop *server) +{ } diff --git a/sysdeps/freebsd/cpu.c b/sysdeps/freebsd/cpu.c new file mode 100644 index 00000000..8affc0e6 --- /dev/null +++ b/sysdeps/freebsd/cpu.c @@ -0,0 +1,70 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/cpu.h> + +static const unsigned long _glibtop_sysdeps_cpu = +(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) + +(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) + +(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY); + +/* Provides information about cpu usage. */ + +void +glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf) +{ + long cp_time [CPUSTATES]; + int i; + + glibtop_init_p (&server, 0, 0); + + memset (buf, 0, sizeof (glibtop_cpu)); + + /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */ + + setregid (server->machine.gid, server->machine.egid); + + /* get the cp_time array */ + + (void) _glibtop_getkval (server, _glibtop_nlist [X_CP_TIME].n_value, + (int *) cp_time, sizeof (cp_time), + _glibtop_nlist [X_CP_TIME].n_name); + + if (setregid (server->machine.egid, server->machine.gid)) + _exit (1); + + /* !!! END OF SUID ROOT PART !!! */ + + buf->user = cp_time [CP_USER]; + buf->nice = cp_time [CP_NICE]; + buf->sys = cp_time [CP_SYS]; + buf->idle = cp_time [CP_IDLE]; + buf->frequency = server->machine.hz; + + /* Calculate total time. */ + + buf->total = buf->user + buf->nice + buf->sys + buf->idle; + + /* Now we can set the flags. */ + + buf->flags = _glibtop_sysdeps_cpu; +} diff --git a/sysdeps/freebsd/glibtop_machine.h b/sysdeps/freebsd/glibtop_machine.h new file mode 100644 index 00000000..5f404a5f --- /dev/null +++ b/sysdeps/freebsd/glibtop_machine.h @@ -0,0 +1,85 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef __GLIBTOP_MACHINE_H__ +#define __GLIBTOP_MACHINE_H__ + +#include <sys/types.h> +#include <sys/signal.h> +#include <sys/param.h> + +#include <stdio.h> +#include <nlist.h> +#include <math.h> +#include <kvm.h> +#include <sys/errno.h> +#include <sys/sysctl.h> +#include <sys/dir.h> +#include <sys/dkstat.h> +#include <sys/file.h> +#include <sys/time.h> + +#include <stdlib.h> +#include <sys/rlist.h> +#include <sys/conf.h> + +__BEGIN_DECLS + +#define X_CCPU 0 +#define X_CP_TIME 1 +#define X_HZ 2 +#define X_STATHZ 3 +#define X_AVENRUN 4 +#define VM_SWAPLIST 5 /* list of free swap areas */ +#define VM_SWDEVT 6 /* list of swap devices and sizes */ +#define VM_NSWAP 7 /* size of largest swap device */ +#define VM_NSWDEV 8 /* number of swap devices */ +#define VM_DMMAX 9 /* maximum size of a swap block */ +#define X_CNT 10 /* struct vmmeter cnt */ +#define X_LASTPID 11 + +typedef struct _glibtop_machine glibtop_machine; + +struct _glibtop_machine +{ + uid_t uid, euid; /* Real and effective user id */ + gid_t gid, egid; /* Real and effective group id */ + int nlist_count; /* Number of symbols in the nlist */ + u_int64_t hz; /* Tick frequency */ + int ncpu; /* Number of CPUs we have */ + kvm_t *kd; +}; + +/* Those functions are used internally in libgtop */ + +#ifdef _IN_LIBGTOP + +extern struct nlist _glibtop_nlist[]; + +extern int _glibtop_check_nlist __P((void *, register struct nlist *)); + +extern int _glibtop_getkval __P((void *, unsigned long, int *, int, char *)); + +#endif + +__END_DECLS + +#endif diff --git a/sysdeps/freebsd/glibtop_server.h b/sysdeps/freebsd/glibtop_server.h new file mode 100644 index 00000000..4b37edfc --- /dev/null +++ b/sysdeps/freebsd/glibtop_server.h @@ -0,0 +1,46 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef __GLIBTOP_SERVER_H__ +#define __GLIBTOP_SERVER_H__ + +__BEGIN_DECLS + +#define GLIBTOP_SUID_CPU (1 << GLIBTOP_SYSDEPS_CPU) +#define GLIBTOP_SUID_MEM (1 << GLIBTOP_SYSDEPS_MEM) +#define GLIBTOP_SUID_SWAP (1 << GLIBTOP_SYSDEPS_SWAP) +#define GLIBTOP_SUID_UPTIME (1 << GLIBTOP_SYSDEPS_UPTIME) +#define GLIBTOP_SUID_LOADAVG (1 << GLIBTOP_SYSDEPS_LOADAVG) +#define GLIBTOP_SUID_SHM_LIMITS (1 << GLIBTOP_SYSDEPS_SHM_LIMITS) +#define GLIBTOP_SUID_MSG_LIMITS (1 << GLIBTOP_SYSDEPS_MSG_LIMITS) +#define GLIBTOP_SUID_SEM_LIMITS (1 << GLIBTOP_SYSDEPS_SEM_LIMITS) +#define GLIBTOP_SUID_PROCLIST (1 << GLIBTOP_SYSDEPS_PROCLIST) +#define GLIBTOP_SUID_PROC_STATE (1 << GLIBTOP_SYSDEPS_PROC_STATE) +#define GLIBTOP_SUID_PROC_UID (1 << GLIBTOP_SYSDEPS_PROC_UID) +#define GLIBTOP_SUID_PROC_MEM (1 << GLIBTOP_SYSDEPS_PROC_MEM) +#define GLIBTOP_SUID_PROC_TIME (1 << GLIBTOP_SYSDEPS_PROC_TIME) +#define GLIBTOP_SUID_PROC_SIGNAL (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL) +#define GLIBTOP_SUID_PROC_KERNEL (1 << GLIBTOP_SYSDEPS_PROC_KERNEL) +#define GLIBTOP_SUID_PROC_SEGMENT (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT) + +__END_DECLS + +#endif diff --git a/sysdeps/freebsd/loadavg.c b/sysdeps/freebsd/loadavg.c new file mode 100644 index 00000000..714485e9 --- /dev/null +++ b/sysdeps/freebsd/loadavg.c @@ -0,0 +1,31 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/loadavg.h> + +/* Provides load averange. */ + +void +glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf) +{ + memset (buf, 0, sizeof (glibtop_loadavg)); +} diff --git a/sysdeps/freebsd/mem.c b/sysdeps/freebsd/mem.c new file mode 100644 index 00000000..9618a575 --- /dev/null +++ b/sysdeps/freebsd/mem.c @@ -0,0 +1,31 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/mem.h> + +/* Provides information about memory usage. */ + +void +glibtop_get_mem_p (glibtop *server, glibtop_mem *buf) +{ + memset (buf, 0, sizeof (glibtop_mem)); +} diff --git a/sysdeps/freebsd/msg_limits.c b/sysdeps/freebsd/msg_limits.c new file mode 100644 index 00000000..fbe5b3a5 --- /dev/null +++ b/sysdeps/freebsd/msg_limits.c @@ -0,0 +1,30 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <glibtop/msg_limits.h> + +/* Provides information about sysv ipc limits. */ + +void +glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf) +{ + memset (buf, 0, sizeof (glibtop_msg_limits)); +} diff --git a/sysdeps/freebsd/nosuid.c b/sysdeps/freebsd/nosuid.c new file mode 100644 index 00000000..e43e5c9f --- /dev/null +++ b/sysdeps/freebsd/nosuid.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <glibtop.h> +#include <glibtop/open.h> + +void +glibtop_open_s (glibtop *server, const char *program_name, + const unsigned long features, const unsigned flags) +{ } + +void +glibtop_close_s (glibtop *server) +{ } diff --git a/sysdeps/freebsd/open.c b/sysdeps/freebsd/open.c new file mode 100644 index 00000000..edc6abaa --- /dev/null +++ b/sysdeps/freebsd/open.c @@ -0,0 +1,179 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <glibtop.h> +#include <glibtop/open.h> +#include <glibtop/xmalloc.h> + +struct nlist _glibtop_nlist[] = { + { "_ccpu" }, /* 0 */ + { "_cp_time" }, /* 1 */ + { "_hz" }, /* 2 */ + { "_stathz" }, /* 3 */ + { "_averunnable" }, /* 4 */ + { "_swaplist" }, /* 5 */ + { "_swdevt" }, /* 6 */ + { "_nswap" }, /* 7 */ + { "_nswdev" }, /* 8 */ + { "_dmmax" }, /* 9 */ + { "_cnt" }, /* 10 */ + { "_nextpid" }, /* 11 */ + { 0 } +}; + +/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */ + +/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ + +void +glibtop_init_p (glibtop *server, const unsigned long features, + const unsigned flags) +{ + if (server == NULL) + glibtop_error_r (NULL, "glibtop_init_p (server == NULL)"); + + glibtop_open_p (server, "glibtop", features, flags); +} + +void +glibtop_open_p (glibtop *server, const char *program_name, + const unsigned long features, const unsigned flags) +{ + /* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */ + + server->name = program_name; + + server->machine.uid = getuid (); + server->machine.euid = geteuid (); + server->machine.gid = getgid (); + server->machine.egid = getegid (); + + /* initialize the kernel interface */ + + server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "libgtop"); + + if (server->machine.kd == NULL) + glibtop_error_io_r (server, "kvm_open"); + + /* get the list of symbols we want to access in the kernel */ + + server->machine.nlist_count = kvm_nlist + (server->machine.kd, _glibtop_nlist); + + if (server->machine.nlist_count < 0) + glibtop_error_io_r (server, "nlist"); + + /* Make sure all of the symbols were found. */ + + if ((server->machine.nlist_count > 0) && + (_glibtop_check_nlist (server, _glibtop_nlist) > 0)) + _exit (1); + + /* Get tick frequency. */ + + (void) _glibtop_getkval (server, _glibtop_nlist [X_STATHZ].n_value, + (int *) &server->machine.hz, + sizeof (server->machine.hz), + _glibtop_nlist [X_STATHZ].n_name); + + if (!server->machine.hz) + (void) _glibtop_getkval + (server, _glibtop_nlist [X_HZ].n_value, + (int *) &server->machine.hz, + sizeof (server->machine.hz), + _glibtop_nlist [X_STATHZ].n_name); + + /* Drop priviledges. */ + + if (setreuid (server->machine.euid, server->machine.uid)) + _exit (1); + + if (setregid (server->machine.egid, server->machine.gid)) + _exit (1); + + /* !!! END OF SUID ROOT PART !!! */ + + /* Our effective uid is now those of the user invoking the server, + * so we do no longer have any priviledges. */ + + /* NOTE: On SunOS, we do not need to be suid root, we just need to + * be sgid kmem. + * + * The server will only use setegid() to get back it's priviledges, + * so it will fail if it is suid root and not sgid kmem. */ +} + +/* Used internally. Returns number of symbols that cannot be found in + * the nlist. */ + +int +_glibtop_check_nlist (void *server, register struct nlist *nlst) +{ + register int not_found; + + /* check to see if we got ALL the symbols we requested */ + /* this will write one line to stderr for every symbol not found */ + + not_found = 0; + + while (nlst->n_name != NULL) { + +#ifdef i386 + if (nlst->n_value == 0) { + glibtop_error_r (server, + "kernel: no symbol named `%s'", + nlst->n_name); + not_found++; + } +#else + if (nlst->n_type == 0) { + glibtop_error_r (server, + "kernel: no symbol named `%s'", + nlst->n_name); + not_found++; + } +#endif + + nlst++; + } + + return not_found; +} + +/* Used internally. Fetches value from kernel. */ + +int +_glibtop_getkval (void *void_server, unsigned long offset, int *ptr, + int size, char *refstr) +{ + glibtop *server = (glibtop *) void_server; + + if (kvm_read (server->machine.kd, offset, ptr, size) != size) + { + if (*refstr == '!') return 0; + + glibtop_error_r (server, "kvm_read(%s): %s", + refstr, strerror (errno)); + } + + return 1; +} + diff --git a/sysdeps/freebsd/prockernel.c b/sysdeps/freebsd/prockernel.c new file mode 100644 index 00000000..9312f924 --- /dev/null +++ b/sysdeps/freebsd/prockernel.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/prockernel.h> + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_kernel)); +} diff --git a/sysdeps/freebsd/proclist.c b/sysdeps/freebsd/proclist.c new file mode 100644 index 00000000..916d73ab --- /dev/null +++ b/sysdeps/freebsd/proclist.c @@ -0,0 +1,39 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/proclist.h> + +#define GLIBTOP_PROCLIST_FLAGS 3 + +/* Fetch list of currently running processes. + * + * IMPORTANT NOTE: + * On error, this function MUST return NULL and set buf->flags to zero ! + * On success, it returnes a pointer to a list of buf->number elements + * each buf->size big. The total size is stored in buf->total. */ + +unsigned * +glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf) +{ + memset (buf, 0, sizeof (glibtop_proclist)); + return NULL; +} diff --git a/sysdeps/freebsd/procmem.c b/sysdeps/freebsd/procmem.c new file mode 100644 index 00000000..70eadd88 --- /dev/null +++ b/sysdeps/freebsd/procmem.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/procmem.h> + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_mem)); +} diff --git a/sysdeps/freebsd/procsegment.c b/sysdeps/freebsd/procsegment.c new file mode 100644 index 00000000..6bc504d1 --- /dev/null +++ b/sysdeps/freebsd/procsegment.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/procsegment.h> + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_segment)); +} diff --git a/sysdeps/freebsd/procsignal.c b/sysdeps/freebsd/procsignal.c new file mode 100644 index 00000000..09f4c7d0 --- /dev/null +++ b/sysdeps/freebsd/procsignal.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/procsignal.h> + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_signal)); +} diff --git a/sysdeps/freebsd/procstate.c b/sysdeps/freebsd/procstate.c new file mode 100644 index 00000000..4a3bd963 --- /dev/null +++ b/sysdeps/freebsd/procstate.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/procstate.h> + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_state)); +} diff --git a/sysdeps/freebsd/proctime.c b/sysdeps/freebsd/proctime.c new file mode 100644 index 00000000..c0e6fddc --- /dev/null +++ b/sysdeps/freebsd/proctime.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/proctime.h> + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_time)); +} diff --git a/sysdeps/freebsd/procuid.c b/sysdeps/freebsd/procuid.c new file mode 100644 index 00000000..759652f6 --- /dev/null +++ b/sysdeps/freebsd/procuid.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/procuid.h> + +/* Provides detailed information about a process. */ + +void +glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf, + pid_t pid) +{ + memset (buf, 0, sizeof (glibtop_proc_uid)); +} diff --git a/sysdeps/freebsd/sem_limits.c b/sysdeps/freebsd/sem_limits.c new file mode 100644 index 00000000..35790c04 --- /dev/null +++ b/sysdeps/freebsd/sem_limits.c @@ -0,0 +1,30 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <glibtop/sem_limits.h> + +/* Provides information about sysv sem limits. */ + +void +glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf) +{ + memset (buf, 0, sizeof (glibtop_sem_limits)); +} diff --git a/sysdeps/freebsd/shm_limits.c b/sysdeps/freebsd/shm_limits.c new file mode 100644 index 00000000..b7695150 --- /dev/null +++ b/sysdeps/freebsd/shm_limits.c @@ -0,0 +1,30 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <glibtop/shm_limits.h> + +/* Provides information about sysv ipc limits. */ + +void +glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf) +{ + memset (buf, 0, sizeof (glibtop_shm_limits)); +} diff --git a/sysdeps/freebsd/siglist.c b/sysdeps/freebsd/siglist.c new file mode 100644 index 00000000..a4afb9bb --- /dev/null +++ b/sysdeps/freebsd/siglist.c @@ -0,0 +1,26 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <glibtop.h> +#include <glibtop/signal.h> + +const glibtop_signame glibtop_sys_siglist [] = +{ { 0, NULL, NULL } }; diff --git a/sysdeps/freebsd/swap.c b/sysdeps/freebsd/swap.c new file mode 100644 index 00000000..1a5a7476 --- /dev/null +++ b/sysdeps/freebsd/swap.c @@ -0,0 +1,31 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/swap.h> + +/* Provides information about swap usage. */ + +void +glibtop_get_swap_p (glibtop *server, glibtop_swap *buf) +{ + memset (buf, 0, sizeof (glibtop_swap)); +} diff --git a/sysdeps/freebsd/uptime.c b/sysdeps/freebsd/uptime.c new file mode 100644 index 00000000..0bda199a --- /dev/null +++ b/sysdeps/freebsd/uptime.c @@ -0,0 +1,31 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. + + The Gnome Top Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Top Library 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 Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <config.h> +#include <glibtop/uptime.h> + +/* Provides uptime and idle time. */ + +void +glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf) +{ + memset (buf, 0, sizeof (glibtop_uptime)); +} |