Replaced glibtop_init_r' with glibtop_init_s'.

1998-07-24  Martin Baulig  <martin@home-of-linux.org>

	* sysdeps/{kernel, linux}/*.c: Replaced `glibtop_init_r' with
	`glibtop_init_s'.

	* sysdeps/sun4/open.c (glibtop_init_p): Removed `program_name'
	parameter.

	* sysdeps/osf1/glibtop_suid.h: New file.

	* sysdeps/osf1/glibtop_server.h: Now correctly using
	`(1 << GLIBTOP_SYSDEPS_*)' instead of `GLIBTOP_SYSDEPS_*'.

	* sysdeps/osf1/open_suid.c (glibtop_init_p): New function.

	* sysdeps/osf1/proc*.c: Done some more work here.
This commit is contained in:
Martin Baulig
1998-07-24 10:26:42 +00:00
committed by Martin Baulig
parent 51c5c3ac22
commit f3f051ecba
46 changed files with 380 additions and 96 deletions

View File

@@ -1,3 +1,20 @@
1998-07-24 Martin Baulig <martin@home-of-linux.org>
* sysdeps/{kernel, linux}/*.c: Replaced `glibtop_init_r' with
`glibtop_init_s'.
* sysdeps/sun4/open.c (glibtop_init_p): Removed `program_name'
parameter.
* sysdeps/osf1/glibtop_suid.h: New file.
* sysdeps/osf1/glibtop_server.h: Now correctly using
`(1 << GLIBTOP_SYSDEPS_*)' instead of `GLIBTOP_SYSDEPS_*'.
* sysdeps/osf1/open_suid.c (glibtop_init_p): New function.
* sysdeps/osf1/proc*.c: Done some more work here.
1998-07-23 Martin Baulig <martin@home-of-linux.org> 1998-07-23 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/procsignal.h (glibtop_proc_signal): * include/glibtop/procsignal.h (glibtop_proc_signal):

View File

@@ -37,7 +37,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_cpu)); memset (buf, 0, sizeof (glibtop_cpu));

View File

@@ -35,7 +35,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_loadavg)); memset (buf, 0, sizeof (glibtop_loadavg));

View File

@@ -38,7 +38,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_mem)); memset (buf, 0, sizeof (glibtop_mem));

View File

@@ -37,7 +37,7 @@ glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{ {
struct msginfo msginfo; struct msginfo msginfo;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_msg_limits)); memset (buf, 0, sizeof (glibtop_msg_limits));

View File

@@ -85,7 +85,7 @@ glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_procdata)); memset (buf, 0, sizeof (glibtop_procdata));

View File

@@ -39,7 +39,7 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_kernel)); memset (buf, 0, sizeof (glibtop_proc_kernel));

View File

@@ -51,7 +51,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
union table tbl; union table tbl;
unsigned *pids_chain; unsigned *pids_chain;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proclist)); memset (buf, 0, sizeof (glibtop_proclist));

View File

@@ -38,7 +38,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_mem)); memset (buf, 0, sizeof (glibtop_proc_mem));

View File

@@ -39,7 +39,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_segment)); memset (buf, 0, sizeof (glibtop_proc_segment));

View File

@@ -37,7 +37,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_signal)); memset (buf, 0, sizeof (glibtop_proc_signal));

View File

@@ -41,7 +41,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf,
{ 'R', 'S', 'D', 'Z', 'T', 'W', '.' }; { 'R', 'S', 'D', 'Z', 'T', 'W', '.' };
unsigned state; unsigned state;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_state)); memset (buf, 0, sizeof (glibtop_proc_state));

View File

@@ -39,7 +39,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_time)); memset (buf, 0, sizeof (glibtop_proc_time));

View File

@@ -44,7 +44,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf,
union table tbl; union table tbl;
long def_priority, priority, nice; long def_priority, priority, nice;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_uid)); memset (buf, 0, sizeof (glibtop_proc_uid));

View File

@@ -39,7 +39,7 @@ glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
struct seminfo seminfo; struct seminfo seminfo;
union semun arg; union semun arg;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_sem_limits)); memset (buf, 0, sizeof (glibtop_sem_limits));

View File

@@ -36,7 +36,7 @@ glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{ {
struct shminfo shminfo; struct shminfo shminfo;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_shm_limits)); memset (buf, 0, sizeof (glibtop_shm_limits));

View File

@@ -36,7 +36,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_swap)); memset (buf, 0, sizeof (glibtop_swap));

View File

@@ -35,7 +35,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{ {
union table tbl; union table tbl;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_uptime)); memset (buf, 0, sizeof (glibtop_uptime));

View File

@@ -37,7 +37,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{ {
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_cpu)); memset (buf, 0, sizeof (glibtop_cpu));

View File

@@ -35,7 +35,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{ {
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_loadavg)); memset (buf, 0, sizeof (glibtop_loadavg));

View File

@@ -38,7 +38,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{ {
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_mem)); memset (buf, 0, sizeof (glibtop_mem));

View File

@@ -37,7 +37,7 @@ glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{ {
struct msginfo msginfo; struct msginfo msginfo;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_msg_limits)); memset (buf, 0, sizeof (glibtop_msg_limits));

View File

@@ -85,7 +85,7 @@ glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_procdata)); memset (buf, 0, sizeof (glibtop_procdata));

View File

@@ -38,7 +38,7 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_kernel)); memset (buf, 0, sizeof (glibtop_proc_kernel));

View File

@@ -60,7 +60,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
struct stat statb; struct stat statb;
int len, i, ok; int len, i, ok;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proclist)); memset (buf, 0, sizeof (glibtop_proclist));

View File

@@ -37,7 +37,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_mem)); memset (buf, 0, sizeof (glibtop_proc_mem));

View File

@@ -39,7 +39,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_segment)); memset (buf, 0, sizeof (glibtop_proc_segment));

View File

@@ -36,7 +36,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_signal)); memset (buf, 0, sizeof (glibtop_proc_signal));

View File

@@ -39,7 +39,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_state)); memset (buf, 0, sizeof (glibtop_proc_state));

View File

@@ -38,7 +38,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_time)); memset (buf, 0, sizeof (glibtop_proc_time));

View File

@@ -42,7 +42,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_uid)); memset (buf, 0, sizeof (glibtop_proc_uid));

View File

@@ -49,7 +49,7 @@ glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
struct seminfo seminfo; struct seminfo seminfo;
union semun arg; union semun arg;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_sem_limits)); memset (buf, 0, sizeof (glibtop_sem_limits));

View File

@@ -36,7 +36,7 @@ glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{ {
struct shminfo shminfo; struct shminfo shminfo;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_shm_limits)); memset (buf, 0, sizeof (glibtop_shm_limits));

View File

@@ -36,7 +36,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{ {
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_swap)); memset (buf, 0, sizeof (glibtop_swap));

View File

@@ -35,7 +35,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{ {
FILE *f; FILE *f;
glibtop_init_r (&server, 0, 0); glibtop_init_s (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_uptime)); memset (buf, 0, sizeof (glibtop_uptime));

View File

@@ -32,14 +32,14 @@ __BEGIN_DECLS
#define GLIBTOP_SUID_SHM_LIMITS 0 #define GLIBTOP_SUID_SHM_LIMITS 0
#define GLIBTOP_SUID_MSG_LIMITS 0 #define GLIBTOP_SUID_MSG_LIMITS 0
#define GLIBTOP_SUID_SEM_LIMITS 0 #define GLIBTOP_SUID_SEM_LIMITS 0
#define GLIBTOP_SUID_PROCLIST (GLIBTOP_SYSDEPS_PROCLIST+1) #define GLIBTOP_SUID_PROCLIST (1 << GLIBTOP_SYSDEPS_PROCLIST)
#define GLIBTOP_SUID_PROC_STATE (GLIBTOP_SYSDEPS_PROC_STATE+1) #define GLIBTOP_SUID_PROC_STATE (1 << GLIBTOP_SYSDEPS_PROC_STATE)
#define GLIBTOP_SUID_PROC_UID (GLIBTOP_SYSDEPS_PROC_UID+1) #define GLIBTOP_SUID_PROC_UID (1 << GLIBTOP_SYSDEPS_PROC_UID)
#define GLIBTOP_SUID_PROC_MEM (GLIBTOP_SYSDEPS_PROC_MEM+1) #define GLIBTOP_SUID_PROC_MEM (1 << GLIBTOP_SYSDEPS_PROC_MEM)
#define GLIBTOP_SUID_PROC_TIME (GLIBTOP_SYSDEPS_PROC_TIME+1) #define GLIBTOP_SUID_PROC_TIME (1 << GLIBTOP_SYSDEPS_PROC_TIME)
#define GLIBTOP_SUID_PROC_SIGNAL (GLIBTOP_SYSDEPS_PROC_SIGNAL+1) #define GLIBTOP_SUID_PROC_SIGNAL (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL)
#define GLIBTOP_SUID_PROC_KERNEL (GLIBTOP_SYSDEPS_PROC_KERNEL+1) #define GLIBTOP_SUID_PROC_KERNEL (1 << GLIBTOP_SYSDEPS_PROC_KERNEL)
#define GLIBTOP_SUID_PROC_SEGMENT (GLIBTOP_SYSDEPS_PROC_SEGMENT+1) #define GLIBTOP_SUID_PROC_SEGMENT (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT)
__END_DECLS __END_DECLS

View File

@@ -0,0 +1,44 @@
/* $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_SUID_H__
#define __GLIBTOP_SUID_H__
#include <sys/table.h>
__BEGIN_DECLS
static inline void glibtop_suid_enter (glibtop *server) {
setreuid (server->machine.uid, server->machine.euid);
};
static inline void glibtop_suid_leave (glibtop *server) {
if (setreuid (server->machine.euid, server->machine.uid))
_exit (1);
};
extern void glibtop_init_p __P((glibtop *, const unsigned long, const unsigned));
extern void glibtop_open_p __P((glibtop *, const char *, const unsigned long, const unsigned));
__END_DECLS
#endif

View File

@@ -22,6 +22,8 @@
#include <glibtop.h> #include <glibtop.h>
#include <glibtop/open.h> #include <glibtop/open.h>
#include <glibtop_suid.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
@@ -29,6 +31,16 @@
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ /* !!! 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 void
glibtop_open_p (glibtop *server, const char *program_name, glibtop_open_p (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags) const unsigned long features, const unsigned flags)

View File

@@ -24,6 +24,8 @@
#include <glibtop/xmalloc.h> #include <glibtop/xmalloc.h>
#include <glibtop/proclist.h> #include <glibtop/proclist.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proclist = static const unsigned long _glibtop_sysdeps_proclist =
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) + (1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
(1 << GLIBTOP_PROCLIST_SIZE); (1 << GLIBTOP_PROCLIST_SIZE);
@@ -62,23 +64,23 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
struct tbl_procinfo procinfo [8]; struct tbl_procinfo procinfo [8];
int entry, max_elements, k; int entry, max_elements, k;
glibtop_open_p (server, 0, 0); glibtop_init_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proclist)); memset (buf, 0, sizeof (glibtop_proclist));
for (entry = 0; entry < server->machine.proctable_entries; for (entry = 0; entry < server->machine.proctable_entries;
entry += ELEMENTS_PER_ENTRY) entry += ELEMENTS_PER_ENTRY)
{ {
/* !!! THE FOLLOWING CODE RUNS SUID ROOT -
* CHANGE WITH CAUTION !!! */
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ glibtop_suid_enter (server);
setreuid (server->machine.uid, server->machine.euid); max_elements = table
(TBL_PROCINFO, entry, (char *) &procinfo,
ELEMENTS_PER_ENTRY, sizeof (struct tbl_procinfo));
max_elements = table (TBL_PROCINFO, entry, (char *) &procinfo, glibtop_suid_leave (server);
ELEMENTS_PER_ENTRY, sizeof (struct tbl_procinfo));
if (setreuid (server->machine.euid, server->machine.uid))
_exit (1);
/* !!! END OF SUID ROOT PART !!! */ /* !!! END OF SUID ROOT PART !!! */
@@ -89,23 +91,25 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
if (procinfo [k].pi_status == 0) if (procinfo [k].pi_status == 0)
continue; continue;
/* The following code is copied from the Linux implementation. /* Fine. Now we first try to store it in pids.
* It's safe since we are no longer root at this point here. */ * If this buffer is full, we copy it to the
* pids_chain. */
/* Fine. Now we first try to store it in pids. If this buffer is
* full, we copy it to the pids_chain. */
if (count >= BLOCK_COUNT) { if (count >= BLOCK_COUNT) {
/* The following call to glibtop_realloc will be equivalent to
* glibtop_malloc if pids_chain is NULL. We just calculate the /* The following call to glibtop_realloc ()
* new size and copy pids to the beginning of the newly allocated * will be equivalent to glibtop_malloc ()
* block. */ * if `pids_chain' is NULL. We just calculate
* the new size and copy `pids' to the
* beginning of the newly allocated block. */
new_size = pids_size + BLOCK_SIZE; new_size = pids_size + BLOCK_SIZE;
pids_chain = glibtop_realloc_r (server, pids_chain, new_size); pids_chain = glibtop_realloc_r
(server, pids_chain, new_size);
memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE); memcpy (pids_chain + pids_offset,
pids, BLOCK_SIZE);
pids_size = new_size; pids_size = new_size;
@@ -114,7 +118,8 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
count = 0; count = 0;
} }
/* pids is now big enough to hold at least one single pid. */ /* pids is now big enough to hold at least
* one single pid. */
pids [count++] = procinfo [k].pi_pid; pids [count++] = procinfo [k].pi_pid;
@@ -122,13 +127,14 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
} }
} }
/* count is only zero if an error occured (eg. the server is not suid root). */ /* count is only zero if an error occured
* (eg. the server is not suid root). */
if (!count) return NULL; if (!count) return NULL;
/* The following call to glibtop_realloc will be equivalent to /* The following call to glibtop_realloc () will be equivalent to
* glibtop_malloc if pids_chain is NULL. We just calculate the * glibtop_malloc () if `pids_chain' is NULL. We just calculate the
* new size and copy pids to the beginning of the newly allocated * new size and copy `pids' to the beginning of the newly allocated
* block. */ * block. */
new_size = pids_size + count * sizeof (unsigned); new_size = pids_size + count * sizeof (unsigned);
@@ -141,8 +147,8 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
pids_offset += BLOCK_COUNT; pids_offset += BLOCK_COUNT;
/* Since everything is ok now, we can set buf->flags, fill in the remaining fields /* Since everything is ok now, we can set buf->flags, fill in the
and return pids_chain. */ * remaining fields and return `pids_chain'. */
buf->flags = _glibtop_sysdeps_proclist; buf->flags = _glibtop_sysdeps_proclist;

View File

@@ -19,14 +19,75 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <config.h> #include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procmem.h> #include <glibtop/procmem.h>
#include <glibtop_suid.h>
#include <sys/user.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <mach.h>
#include <mach/mach_types.h>
#include <mach/task_info.h>
static const unsigned long _glibtop_sysdeps_proc_mem =
(1 << GLIBTOP_PROC_MEM_VSIZE) + (1 << GLIBTOP_PROC_MEM_RESIDENT) +
(1 << GLIBTOP_PROC_MEM_RSS);
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf, glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
pid_t pid) pid_t pid)
{ {
task_basic_info_data_t taskinfo;
int ret, info_count;
task_t thistask;
struct user u;
glibtop_init_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_mem)); memset (buf, 0, sizeof (glibtop_proc_mem));
/* Get task structure. */
ret = task_by_unix_pid (task_self(), pid, &thistask);
if (ret != KERN_SUCCESS) return;
/* Get taskinfo about this task. */
info_count = TASK_BASIC_INFO_COUNT;
ret = task_info (thistask, TASK_BASIC_INFO,
(task_info_t) &taskinfo, &info_count);
if (ret != KERN_SUCCESS) return;
buf->resident = taskinfo.resident_size;
buf->rss = taskinfo.resident_size;
buf->vsize = taskinfo.virtual_size;
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
ret = table (TBL_UAREA, pid, (char *) &u, 1,
sizeof (struct user));
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
if (ret != 1) return;
buf->rss_rlim = u.u_rlimit [RLIMIT_RSS].rlim_cur;
buf->share = u.u_ru.ru_ixrss;
buf->flags |= (1 << GLIBTOP_PROC_MEM_RSS_RLIM) |
(1 << GLIBTOP_PROC_MEM_SHARE);
} }

View File

@@ -19,14 +19,50 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <config.h> #include <glibtop.h>
#include <glibtop/procsegment.h> #include <glibtop/procsegment.h>
#include <glibtop_suid.h>
#include <sys/user.h>
static const unsigned long _glibtop_sysdeps_proc_segment =
(1 << GLIBTOP_PROC_SEGMENT_TRS) + (1 << GLIBTOP_PROC_SEGMENT_DRS) +
(1 << GLIBTOP_PROC_SEGMENT_START_CODE) + (1 << GLIBTOP_PROC_SEGMENT_END_CODE) +
(1 << GLIBTOP_PROC_SEGMENT_START_STACK);
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf, glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
pid_t pid) pid_t pid)
{ {
int ret;
struct user u;
glibtop_init_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_segment)); memset (buf, 0, sizeof (glibtop_proc_segment));
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
ret = table (TBL_UAREA, pid, (char *) &u, 1,
sizeof (struct user));
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
if (ret != 1) return;
buf->start_code = (unsigned long) u.u_text_start;
buf->end_code = (unsigned long) u.u_data_start;
buf->start_stack = (unsigned long) u.u_stack_start;
buf->trs = u.u_tsize;
buf->drs = u.u_dsize;
buf->flags = _glibtop_sysdeps_proc_segment;
} }

View File

@@ -19,14 +19,46 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <config.h> #include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procsignal.h> #include <glibtop/procsignal.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_signal =
(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << GLIBTOP_PROC_SIGNAL_SIGCATCH);
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf, glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
pid_t pid) pid_t pid)
{ {
struct tbl_procinfo procinfo;
int ret;
glibtop_init_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_signal)); memset (buf, 0, sizeof (glibtop_proc_signal));
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
ret = table (TBL_PROCINFO, pid, (char *) &procinfo, 1,
sizeof (struct tbl_procinfo));
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
if (ret != 1) return;
buf->signal = procinfo.pi_sig;
buf->blocked = procinfo.pi_sigmask;
buf->sigignore = procinfo.pi_sigignore;
buf->sigcatch = procinfo.pi_sigcatch;
buf->flags = _glibtop_sysdeps_proc_signal;
} }

View File

@@ -19,14 +19,50 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <config.h> #include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procstate.h> #include <glibtop/procstate.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_state =
(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE) +
(1 << GLIBTOP_PROC_STATE_UID);
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf, glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
pid_t pid) pid_t pid)
{ {
struct tbl_procinfo procinfo;
int ret;
glibtop_init_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_state)); memset (buf, 0, sizeof (glibtop_proc_state));
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
ret = table (TBL_PROCINFO, pid, (char *) &procinfo, 1,
sizeof (struct tbl_procinfo));
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
if (ret != 1) return;
strncpy (buf->cmd, procinfo.pi_comm, sizeof (buf->cmd)-1);
buf->cmd [sizeof (buf->cmd)-1] = 0;
buf->state = procinfo.pi_status;
buf->uid = procinfo.pi_uid;
buf->gid = procinfo.pi_svgid;
buf->flags = _glibtop_sysdeps_proc_state;
} }

View File

@@ -19,14 +19,51 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <config.h> #include <glibtop.h>
#include <glibtop/proctime.h> #include <glibtop/proctime.h>
#include <glibtop_suid.h>
#include <sys/user.h>
#include <sys/time.h>
static const unsigned long _glibtop_sysdeps_proc_time =
(1 << GLIBTOP_PROC_TIME_UTIME) + (1 << GLIBTOP_PROC_TIME_CUTIME) +
(1 << GLIBTOP_PROC_TIME_STIME) + (1 << GLIBTOP_PROC_TIME_CSTIME) +
(1 << GLIBTOP_PROC_TIME_START_TIME);
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf, glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
pid_t pid) pid_t pid)
{ {
struct user u;
int ret;
glibtop_init_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_time)); memset (buf, 0, sizeof (glibtop_proc_time));
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
ret = table (TBL_UAREA, pid, (char *) &u, 1,
sizeof (struct user));
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
if (ret != 1) return;
buf->start_time = u.u_start.tv_sec;
buf->utime = u.u_ru.ru_utime.tv_sec;
buf->stime = u.u_ru.ru_stime.tv_sec;
buf->cutime = u.u_cru.ru_utime.tv_sec;
buf->cstime = u.u_cru.ru_stime.tv_sec;
buf->flags = _glibtop_sysdeps_proc_time;
} }

View File

@@ -19,9 +19,11 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <config.h> #include <glibtop.h>
#include <glibtop/procuid.h> #include <glibtop/procuid.h>
#include <glibtop_suid.h>
#include <sys/table.h> #include <sys/table.h>
#include <sys/resource.h> #include <sys/resource.h>
@@ -47,19 +49,18 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
int ret, info_count; int ret, info_count;
task_t thistask; task_t thistask;
glibtop_open_p (server, 0, 0); glibtop_init_p (server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_uid)); memset (buf, 0, sizeof (glibtop_proc_uid));
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
setreuid (server->machine.uid, server->machine.euid); glibtop_suid_enter (server);
ret = table (TBL_PROCINFO, pid, (char *) &procinfo, 1, ret = table (TBL_PROCINFO, pid, (char *) &procinfo, 1,
sizeof (struct tbl_procinfo)); sizeof (struct tbl_procinfo));
if (setreuid (server->machine.euid, server->machine.uid)) glibtop_suid_leave (server);
_exit (1);
/* !!! END OF SUID ROOT PART !!! */ /* !!! END OF SUID ROOT PART !!! */
@@ -81,7 +82,7 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
setreuid (server->machine.uid, server->machine.euid); glibtop_suid_enter (server);
/* Get task structure. */ /* Get task structure. */
@@ -96,10 +97,10 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
ret = task_info (thistask, TASK_BASIC_INFO, ret = task_info (thistask, TASK_BASIC_INFO,
(task_info_t) &taskinfo, &info_count); (task_info_t) &taskinfo, &info_count);
/* `ret' is evaluated outside the `if' clause. */
} }
if (setreuid (server->machine.euid, server->machine.uid)) glibtop_suid_leave (server);
_exit (1);
/* !!! END OF SUID ROOT PART !!! */ /* !!! END OF SUID ROOT PART !!! */

View File

@@ -63,13 +63,13 @@ struct nlist _glibtop_nlist[] = {
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ /* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
void void
glibtop_init_p (glibtop *server, const char *program_name, glibtop_init_p (glibtop *server, const unsigned long features,
const unsigned long features, const unsigned flags) const unsigned flags)
{ {
if (server == NULL) if (server == NULL)
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)"); glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
glibtop_open_p (server, program_name, features, flags); glibtop_open_p (server, "glibtop", features, flags);
} }
void void
@@ -164,12 +164,14 @@ glibtop_open_p (glibtop *server, const char *program_name,
server->machine.bytesize = server->machine.epages - server->machine.bytesize = server->machine.epages -
server->machine.pages; server->machine.pages;
server->machine.count = server->machine.bytesize / sizeof (struct page); server->machine.count = server->machine.bytesize /
sizeof (struct page);
server->machine.physpage = server->machine.physpage = (struct page *)
(struct page *) glibtop_malloc_r (server, server->machine.bytesize); glibtop_malloc_r (server, server->machine.bytesize);
/* get the page size with "getpagesize" and calculate pageshift from it */ /* get the page size with "getpagesize" and
* calculate pageshift from it */
pagesize = getpagesize(); pagesize = getpagesize();