Using correct `(1 << GLIBTOP_SYSDPES_*)'. (<glibtop_suid.h>): Include.

1998-08-25  Martin Baulig  <martin@home-of-linux.org>

	* *.c (glibtop_init_p): Using correct `(1 << GLIBTOP_SYSDPES_*)'.
	(<glibtop_suid.h>): Include.

	* glibtop_suid.h: New file.

	* ChangeLog: New file.
This commit is contained in:
Martin Baulig
1998-08-25 08:03:52 +00:00
committed by Martin Baulig
parent 4789169c80
commit 8e540b8fc0
19 changed files with 111 additions and 34 deletions

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/cpu.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
@@ -35,13 +37,13 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
long cp_time [CPUSTATES], mp_time [NCPU][CPUSTATES];
int i;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_CPU), 0);
memset (buf, 0, sizeof (glibtop_cpu));
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
setregid (server->machine.gid, server->machine.egid);
glibtop_suid_enter (server);
/* get the cp_time array */
@@ -59,16 +61,16 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
}
#endif
if (setregid (server->machine.egid, server->machine.gid))
_exit (1);
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
#ifdef MULTIPROCESSOR
/* If we have multiple processors, we add the times for each of them and set
frequency to 100 times the number of the processors. */
/* If we have multiple processors, we add the times for each of them
* and set frequency to 100 times the number of the processors. */
/* [FIXME]: I had no machine with more than one processor to test this code !!! */
/* [FIXME]: I had no machine with more than one processor to test
* this code !!! */
if (server->machine.ncpu > 1) {
for (i = 0; i < server->machine.ncpu; i++) {

View File

@@ -40,6 +40,7 @@ __BEGIN_DECLS
#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)
#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
__END_DECLS

View File

@@ -0,0 +1,42 @@
/* $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__
__BEGIN_DECLS
static inline void glibtop_suid_enter (glibtop *server) {
setregid (server->machine.gid, server->machine.egid);
};
static inline void glibtop_suid_leave (glibtop *server) {
if (setregid (server->machine.egid, server->machine.gid))
_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/loadavg.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_loadavg =
(1 << GLIBTOP_LOADAVG_LOADAVG);
@@ -33,7 +35,7 @@ glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
load_avg avenrun [3];
int i;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_LOADAVG), 0);
memset (buf, 0, sizeof (glibtop_loadavg));

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/mem.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_mem =
(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
(1 << GLIBTOP_MEM_FREE) + (1 << GLIBTOP_MEM_LOCKED);
@@ -35,13 +37,13 @@ static const unsigned long _glibtop_sysdeps_mem =
void
glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
{
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_MEM), 0);
memset (buf, 0, sizeof (glibtop_mem));
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
setregid (server->machine.gid, server->machine.egid);
glibtop_suid_enter (server);
/* get the array of physpage descriptors */
@@ -50,8 +52,7 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
server->machine.bytesize,
"array _page");
if (setregid (server->machine.egid, server->machine.gid))
_exit (1);
glibtop_suid_leave (server);
/* !!! END OF SGID KMEM PART !!! */

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/msg_limits.h>
#include <glibtop_suid.h>
/* #define KERNEL to get declaration of `struct msginfo'. */
#define KERNEL
@@ -41,7 +43,7 @@ glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
{
struct msginfo msginfo;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
memset (buf, 0, sizeof (glibtop_msg_limits));

View File

@@ -21,6 +21,7 @@
#include <glibtop.h>
#include <glibtop/open.h>
#include <glibtop/close.h>
void
glibtop_open_s (glibtop *server, const char *program_name,

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/prockernel.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_kernel =
(1 << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1 << GLIBTOP_PROC_KERNEL_WCHAN);
@@ -33,7 +35,7 @@ glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
{
struct proc *pp;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_KERNEL), 0);
memset (buf, 0, sizeof (glibtop_proc_kernel));
@@ -50,7 +52,7 @@ glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
/* Fill in data fields. */
buf->k_flags = pp->p_flag;
buf->wchan = pp->p_wchan;
buf->nwchan = (unsigned long) pp->p_wchan;
buf->flags = _glibtop_sysdeps_proc_kernel;
}

View File

@@ -23,6 +23,8 @@
#include <glibtop/xmalloc.h>
#include <glibtop/proclist.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proclist =
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
(1 << GLIBTOP_PROCLIST_SIZE);
@@ -35,14 +37,15 @@ static const unsigned long _glibtop_sysdeps_proclist =
* each buf->size big. The total size is stored in buf->total. */
unsigned *
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
int64_t which, int64_t arg)
{
register struct proc *pp;
register int i, nproc = 0;
unsigned *proc_list = NULL;
size_t proc_size;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROCLIST), 0);
memset (buf, 0, sizeof (glibtop_proclist));

View File

@@ -22,6 +22,8 @@
#include <config.h>
#include <glibtop/procmem.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_mem =
(1 << GLIBTOP_PROC_MEM_SIZE) + (1 << GLIBTOP_PROC_MEM_RSS) +
(1 << GLIBTOP_PROC_MEM_RSS_RLIM);
@@ -34,7 +36,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
{
struct proc *pp;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_MEM), 0);
memset (buf, 0, sizeof (glibtop_proc_mem));

View File

@@ -22,8 +22,11 @@
#include <glibtop.h>
#include <glibtop/procsegment.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_segment =
(1 << GLIBTOP_PROC_SEGMENT_TRS) + (1 << GLIBTOP_PROC_SEGMENT_DRS);
(1 << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
(1 << GLIBTOP_PROC_SEGMENT_DATA_RSS);
/* Provides detailed information about a process. */
@@ -33,7 +36,7 @@ glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
{
struct proc *pp;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
memset (buf, 0, sizeof (glibtop_proc_segment));
@@ -49,8 +52,8 @@ glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
/* Fill in data fields. */
buf->trs = pp->p_tsize;
buf->drs = pp->p_dsize;
buf->text_rss = pp->p_tsize;
buf->data_rss = pp->p_dsize;
buf->flags = _glibtop_sysdeps_proc_segment;
}

View File

@@ -22,6 +22,8 @@
#include <glibtop.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);
@@ -34,7 +36,7 @@ glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
{
struct proc *pp;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
memset (buf, 0, sizeof (glibtop_proc_signal));

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/procstate.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_state =
(1 << GLIBTOP_PROC_STATE_STATE) + (1 << GLIBTOP_PROC_STATE_UID);
@@ -33,7 +35,7 @@ glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
{
struct proc *pp;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_STATE), 0);
memset (buf, 0, sizeof (glibtop_proc_state));

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/proctime.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_time =
(1 << GLIBTOP_PROC_TIME_START_TIME) + (1 << GLIBTOP_PROC_TIME_UTIME);
@@ -33,7 +35,7 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
{
struct proc *pp;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_TIME), 0);
memset (buf, 0, sizeof (glibtop_proc_time));

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/procuid.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_uid =
(1 << GLIBTOP_PROC_UID_UID) + (1 << GLIBTOP_PROC_UID_EUID) +
(1 << GLIBTOP_PROC_UID_EGID) + (1 << GLIBTOP_PROC_UID_PID) +
@@ -37,7 +39,7 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
{
struct proc *pp;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_UID), 0);
memset (buf, 0, sizeof (glibtop_proc_uid));

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/sem_limits.h>
#include <glibtop_suid.h>
/* #define KERNEL to get declaration of `struct seminfo'. */
#define KERNEL
@@ -43,7 +45,7 @@ glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
{
struct seminfo seminfo;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
memset (buf, 0, sizeof (glibtop_sem_limits));

View File

@@ -22,6 +22,8 @@
#include <glibtop.h>
#include <glibtop/shm_limits.h>
#include <glibtop_suid.h>
/* #define KERNEL to get declaration of `struct shminfo'. */
#define KERNEL
@@ -41,7 +43,7 @@ glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
{
struct shminfo shminfo;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
memset (buf, 0, sizeof (glibtop_shm_limits));

View File

@@ -22,12 +22,14 @@
#include <glibtop.h>
#include <glibtop/swap.h>
#include <glibtop_suid.h>
/* Provides information about swap usage. */
void
glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
{
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SWAP), 0);
memset (buf, 0, sizeof (glibtop_swap));
}

View File

@@ -23,6 +23,8 @@
#include <glibtop/cpu.h>
#include <glibtop/uptime.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_uptime =
(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
@@ -33,7 +35,7 @@ glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
{
glibtop_cpu cpu;
glibtop_init_p (&server, 0, 0);
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_UPTIME), 0);
/* Get currect cpu usage. */