diff --git a/ChangeLog b/ChangeLog index 81fc43a2..aa172184 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +1998-07-24 Martin Baulig + + * 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 * include/glibtop/procsignal.h (glibtop_proc_signal): diff --git a/sysdeps/kernel/cpu.c b/sysdeps/kernel/cpu.c index 1e8dfdf5..6e348b1d 100644 --- a/sysdeps/kernel/cpu.c +++ b/sysdeps/kernel/cpu.c @@ -37,7 +37,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_cpu)); diff --git a/sysdeps/kernel/loadavg.c b/sysdeps/kernel/loadavg.c index e104c0f4..fc1718f5 100644 --- a/sysdeps/kernel/loadavg.c +++ b/sysdeps/kernel/loadavg.c @@ -35,7 +35,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf) { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_loadavg)); diff --git a/sysdeps/kernel/mem.c b/sysdeps/kernel/mem.c index 1639a07a..b0bf598e 100644 --- a/sysdeps/kernel/mem.c +++ b/sysdeps/kernel/mem.c @@ -38,7 +38,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf) { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_mem)); diff --git a/sysdeps/kernel/msg_limits.c b/sysdeps/kernel/msg_limits.c index 8b0e6fdc..08fdc8e8 100644 --- a/sysdeps/kernel/msg_limits.c +++ b/sysdeps/kernel/msg_limits.c @@ -37,7 +37,7 @@ glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf) { struct msginfo msginfo; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_msg_limits)); diff --git a/sysdeps/kernel/procdata.c b/sysdeps/kernel/procdata.c index 9226b7e0..c1e9126d 100644 --- a/sysdeps/kernel/procdata.c +++ b/sysdeps/kernel/procdata.c @@ -85,7 +85,7 @@ glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid) int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_procdata)); diff --git a/sysdeps/kernel/prockernel.c b/sysdeps/kernel/prockernel.c index ce56b8e5..f987b35d 100644 --- a/sysdeps/kernel/prockernel.c +++ b/sysdeps/kernel/prockernel.c @@ -39,7 +39,7 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_kernel)); diff --git a/sysdeps/kernel/proclist.c b/sysdeps/kernel/proclist.c index 2af70a8c..f812e915 100644 --- a/sysdeps/kernel/proclist.c +++ b/sysdeps/kernel/proclist.c @@ -51,7 +51,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf) union table tbl; unsigned *pids_chain; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proclist)); diff --git a/sysdeps/kernel/procmem.c b/sysdeps/kernel/procmem.c index e81acfce..71a34cc5 100644 --- a/sysdeps/kernel/procmem.c +++ b/sysdeps/kernel/procmem.c @@ -38,7 +38,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_mem)); diff --git a/sysdeps/kernel/procsegment.c b/sysdeps/kernel/procsegment.c index b17130d8..86b06854 100644 --- a/sysdeps/kernel/procsegment.c +++ b/sysdeps/kernel/procsegment.c @@ -39,7 +39,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf, { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_segment)); diff --git a/sysdeps/kernel/procsignal.c b/sysdeps/kernel/procsignal.c index accd6bac..ac4012d7 100644 --- a/sysdeps/kernel/procsignal.c +++ b/sysdeps/kernel/procsignal.c @@ -37,7 +37,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_signal)); diff --git a/sysdeps/kernel/procstate.c b/sysdeps/kernel/procstate.c index 16da8fa1..2fa471f4 100644 --- a/sysdeps/kernel/procstate.c +++ b/sysdeps/kernel/procstate.c @@ -41,7 +41,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, { 'R', 'S', 'D', 'Z', 'T', 'W', '.' }; unsigned state; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_state)); diff --git a/sysdeps/kernel/proctime.c b/sysdeps/kernel/proctime.c index 65172974..3b8d2fb8 100644 --- a/sysdeps/kernel/proctime.c +++ b/sysdeps/kernel/proctime.c @@ -39,7 +39,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_time)); diff --git a/sysdeps/kernel/procuid.c b/sysdeps/kernel/procuid.c index 5df101fc..0fb298ac 100644 --- a/sysdeps/kernel/procuid.c +++ b/sysdeps/kernel/procuid.c @@ -44,7 +44,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, union table tbl; long def_priority, priority, nice; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_uid)); diff --git a/sysdeps/kernel/sem_limits.c b/sysdeps/kernel/sem_limits.c index 88176f0b..778567f5 100644 --- a/sysdeps/kernel/sem_limits.c +++ b/sysdeps/kernel/sem_limits.c @@ -39,7 +39,7 @@ glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf) struct seminfo seminfo; union semun arg; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_sem_limits)); diff --git a/sysdeps/kernel/shm_limits.c b/sysdeps/kernel/shm_limits.c index 2849b22d..1f595a58 100644 --- a/sysdeps/kernel/shm_limits.c +++ b/sysdeps/kernel/shm_limits.c @@ -36,7 +36,7 @@ glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf) { struct shminfo shminfo; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_shm_limits)); diff --git a/sysdeps/kernel/swap.c b/sysdeps/kernel/swap.c index 938e23fc..cb7643e9 100644 --- a/sysdeps/kernel/swap.c +++ b/sysdeps/kernel/swap.c @@ -36,7 +36,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf) { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_swap)); diff --git a/sysdeps/kernel/uptime.c b/sysdeps/kernel/uptime.c index 85637846..7d91c255 100644 --- a/sysdeps/kernel/uptime.c +++ b/sysdeps/kernel/uptime.c @@ -35,7 +35,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf) { union table tbl; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_uptime)); diff --git a/sysdeps/linux/cpu.c b/sysdeps/linux/cpu.c index 750161a6..16f29939 100644 --- a/sysdeps/linux/cpu.c +++ b/sysdeps/linux/cpu.c @@ -37,7 +37,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) { FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_cpu)); diff --git a/sysdeps/linux/loadavg.c b/sysdeps/linux/loadavg.c index dbda3e6d..a4b308e9 100644 --- a/sysdeps/linux/loadavg.c +++ b/sysdeps/linux/loadavg.c @@ -35,7 +35,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf) { FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_loadavg)); diff --git a/sysdeps/linux/mem.c b/sysdeps/linux/mem.c index 6b17b671..ca52092b 100644 --- a/sysdeps/linux/mem.c +++ b/sysdeps/linux/mem.c @@ -38,7 +38,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf) { FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_mem)); diff --git a/sysdeps/linux/msg_limits.c b/sysdeps/linux/msg_limits.c index 8b0e6fdc..08fdc8e8 100644 --- a/sysdeps/linux/msg_limits.c +++ b/sysdeps/linux/msg_limits.c @@ -37,7 +37,7 @@ glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf) { struct msginfo msginfo; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_msg_limits)); diff --git a/sysdeps/linux/procdata.c b/sysdeps/linux/procdata.c index 9226b7e0..c1e9126d 100644 --- a/sysdeps/linux/procdata.c +++ b/sysdeps/linux/procdata.c @@ -85,7 +85,7 @@ glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid) int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_procdata)); diff --git a/sysdeps/linux/prockernel.c b/sysdeps/linux/prockernel.c index 777af80d..3264fb13 100644 --- a/sysdeps/linux/prockernel.c +++ b/sysdeps/linux/prockernel.c @@ -38,7 +38,7 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid) int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_kernel)); diff --git a/sysdeps/linux/proclist.c b/sysdeps/linux/proclist.c index 4581cadc..f1f73a8c 100644 --- a/sysdeps/linux/proclist.c +++ b/sysdeps/linux/proclist.c @@ -60,7 +60,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf) struct stat statb; int len, i, ok; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proclist)); diff --git a/sysdeps/linux/procmem.c b/sysdeps/linux/procmem.c index a39a0553..dcbbc198 100644 --- a/sysdeps/linux/procmem.c +++ b/sysdeps/linux/procmem.c @@ -37,7 +37,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid) int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_mem)); diff --git a/sysdeps/linux/procsegment.c b/sysdeps/linux/procsegment.c index b5b37ba4..5300b5f8 100644 --- a/sysdeps/linux/procsegment.c +++ b/sysdeps/linux/procsegment.c @@ -39,7 +39,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf, int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_segment)); diff --git a/sysdeps/linux/procsignal.c b/sysdeps/linux/procsignal.c index 3b409e8b..428463f7 100644 --- a/sysdeps/linux/procsignal.c +++ b/sysdeps/linux/procsignal.c @@ -36,7 +36,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid) int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_signal)); diff --git a/sysdeps/linux/procstate.c b/sysdeps/linux/procstate.c index 7b843aa5..47138325 100644 --- a/sysdeps/linux/procstate.c +++ b/sysdeps/linux/procstate.c @@ -39,7 +39,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid) int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_state)); diff --git a/sysdeps/linux/proctime.c b/sysdeps/linux/proctime.c index 0d0eaeda..fed8ad20 100644 --- a/sysdeps/linux/proctime.c +++ b/sysdeps/linux/proctime.c @@ -38,7 +38,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid) int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_time)); diff --git a/sysdeps/linux/procuid.c b/sysdeps/linux/procuid.c index 582a9ebd..901060f2 100644 --- a/sysdeps/linux/procuid.c +++ b/sysdeps/linux/procuid.c @@ -42,7 +42,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid) int nread; FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_uid)); diff --git a/sysdeps/linux/sem_limits.c b/sysdeps/linux/sem_limits.c index 19203a33..f56c093c 100644 --- a/sysdeps/linux/sem_limits.c +++ b/sysdeps/linux/sem_limits.c @@ -49,7 +49,7 @@ glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf) struct seminfo seminfo; union semun arg; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_sem_limits)); diff --git a/sysdeps/linux/shm_limits.c b/sysdeps/linux/shm_limits.c index 2849b22d..1f595a58 100644 --- a/sysdeps/linux/shm_limits.c +++ b/sysdeps/linux/shm_limits.c @@ -36,7 +36,7 @@ glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf) { struct shminfo shminfo; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_shm_limits)); diff --git a/sysdeps/linux/swap.c b/sysdeps/linux/swap.c index dd54e1bd..af316ead 100644 --- a/sysdeps/linux/swap.c +++ b/sysdeps/linux/swap.c @@ -36,7 +36,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf) { FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_swap)); diff --git a/sysdeps/linux/uptime.c b/sysdeps/linux/uptime.c index 8233e1ff..67f3d159 100644 --- a/sysdeps/linux/uptime.c +++ b/sysdeps/linux/uptime.c @@ -35,7 +35,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf) { FILE *f; - glibtop_init_r (&server, 0, 0); + glibtop_init_s (&server, 0, 0); memset (buf, 0, sizeof (glibtop_uptime)); diff --git a/sysdeps/osf1/glibtop_server.h b/sysdeps/osf1/glibtop_server.h index 4b1ee107..0c925cbf 100644 --- a/sysdeps/osf1/glibtop_server.h +++ b/sysdeps/osf1/glibtop_server.h @@ -32,14 +32,14 @@ __BEGIN_DECLS #define GLIBTOP_SUID_SHM_LIMITS 0 #define GLIBTOP_SUID_MSG_LIMITS 0 #define GLIBTOP_SUID_SEM_LIMITS 0 -#define GLIBTOP_SUID_PROCLIST (GLIBTOP_SYSDEPS_PROCLIST+1) -#define GLIBTOP_SUID_PROC_STATE (GLIBTOP_SYSDEPS_PROC_STATE+1) -#define GLIBTOP_SUID_PROC_UID (GLIBTOP_SYSDEPS_PROC_UID+1) -#define GLIBTOP_SUID_PROC_MEM (GLIBTOP_SYSDEPS_PROC_MEM+1) -#define GLIBTOP_SUID_PROC_TIME (GLIBTOP_SYSDEPS_PROC_TIME+1) -#define GLIBTOP_SUID_PROC_SIGNAL (GLIBTOP_SYSDEPS_PROC_SIGNAL+1) -#define GLIBTOP_SUID_PROC_KERNEL (GLIBTOP_SYSDEPS_PROC_KERNEL+1) -#define GLIBTOP_SUID_PROC_SEGMENT (GLIBTOP_SYSDEPS_PROC_SEGMENT+1) +#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 diff --git a/sysdeps/osf1/glibtop_suid.h b/sysdeps/osf1/glibtop_suid.h new file mode 100644 index 00000000..f6faaf38 --- /dev/null +++ b/sysdeps/osf1/glibtop_suid.h @@ -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 , 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 + +__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 diff --git a/sysdeps/osf1/open_suid.c b/sysdeps/osf1/open_suid.c index 891ab4a2..f2e7a353 100644 --- a/sysdeps/osf1/open_suid.c +++ b/sysdeps/osf1/open_suid.c @@ -22,6 +22,8 @@ #include #include +#include + #include #include @@ -29,6 +31,16 @@ /* !!! 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) diff --git a/sysdeps/osf1/proclist.c b/sysdeps/osf1/proclist.c index 8dcb8af7..79d9bcb5 100644 --- a/sysdeps/osf1/proclist.c +++ b/sysdeps/osf1/proclist.c @@ -24,6 +24,8 @@ #include #include +#include + static const unsigned long _glibtop_sysdeps_proclist = (1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) + (1 << GLIBTOP_PROCLIST_SIZE); @@ -62,24 +64,24 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf) struct tbl_procinfo procinfo [8]; int entry, max_elements, k; - glibtop_open_p (server, 0, 0); + glibtop_init_p (server, 0, 0); memset (buf, 0, sizeof (glibtop_proclist)); for (entry = 0; entry < server->machine.proctable_entries; entry += ELEMENTS_PER_ENTRY) { + /* !!! 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); - - max_elements = table (TBL_PROCINFO, entry, (char *) &procinfo, - ELEMENTS_PER_ENTRY, sizeof (struct tbl_procinfo)); + glibtop_suid_enter (server); + + max_elements = table + (TBL_PROCINFO, entry, (char *) &procinfo, + ELEMENTS_PER_ENTRY, sizeof (struct tbl_procinfo)); + + glibtop_suid_leave (server); - if (setreuid (server->machine.euid, server->machine.uid)) - _exit (1); - /* !!! END OF SUID ROOT PART !!! */ for (k = 0; k < max_elements; k++) @@ -89,46 +91,50 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf) if (procinfo [k].pi_status == 0) continue; - /* The following code is copied from the Linux implementation. - * It's safe since we are no longer root at this point here. */ - - /* Fine. Now we first try to store it in pids. 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) { - /* The following call to glibtop_realloc will be equivalent to - * glibtop_malloc if pids_chain is NULL. We just calculate the - * new size and copy pids to the beginning of the newly allocated - * block. */ + + /* The following call to glibtop_realloc () + * will be equivalent to glibtop_malloc () + * 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; - 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_offset += BLOCK_COUNT; - + 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; - + total++; } } - /* 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; - /* The following call to glibtop_realloc will be equivalent to - * glibtop_malloc if pids_chain is NULL. We just calculate the - * new size and copy pids to the beginning of the newly allocated + /* The following call to glibtop_realloc () will be equivalent to + * glibtop_malloc () 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 + count * sizeof (unsigned); @@ -141,8 +147,8 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf) pids_offset += BLOCK_COUNT; - /* Since everything is ok now, we can set buf->flags, fill in the remaining fields - and return pids_chain. */ + /* Since everything is ok now, we can set buf->flags, fill in the + * remaining fields and return `pids_chain'. */ buf->flags = _glibtop_sysdeps_proclist; diff --git a/sysdeps/osf1/procmem.c b/sysdeps/osf1/procmem.c index 70eadd88..34eb915d 100644 --- a/sysdeps/osf1/procmem.c +++ b/sysdeps/osf1/procmem.c @@ -19,14 +19,75 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include +#include #include +#include + +#include +#include +#include + +#include +#include +#include + +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. */ void glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf, 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)); + + /* 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); } diff --git a/sysdeps/osf1/procsegment.c b/sysdeps/osf1/procsegment.c index 6bc504d1..59f98fad 100644 --- a/sysdeps/osf1/procsegment.c +++ b/sysdeps/osf1/procsegment.c @@ -19,14 +19,50 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include #include +#include + +#include + +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. */ void glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf, pid_t pid) { + int ret; + struct user u; + + glibtop_init_p (server, 0, 0); + 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; } diff --git a/sysdeps/osf1/procsignal.c b/sysdeps/osf1/procsignal.c index 09f4c7d0..1871a384 100644 --- a/sysdeps/osf1/procsignal.c +++ b/sysdeps/osf1/procsignal.c @@ -19,14 +19,46 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include +#include #include +#include + +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. */ void glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf, pid_t pid) { + struct tbl_procinfo procinfo; + int ret; + + glibtop_init_p (server, 0, 0); + 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; } diff --git a/sysdeps/osf1/procstate.c b/sysdeps/osf1/procstate.c index 4a3bd963..d0debb36 100644 --- a/sysdeps/osf1/procstate.c +++ b/sysdeps/osf1/procstate.c @@ -19,14 +19,50 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include +#include #include +#include + +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. */ void glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf, pid_t pid) { + struct tbl_procinfo procinfo; + int ret; + + glibtop_init_p (server, 0, 0); + 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; } diff --git a/sysdeps/osf1/proctime.c b/sysdeps/osf1/proctime.c index c0e6fddc..f1d0aa74 100644 --- a/sysdeps/osf1/proctime.c +++ b/sysdeps/osf1/proctime.c @@ -19,14 +19,51 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include #include +#include + +#include +#include + +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. */ void glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf, pid_t pid) { + struct user u; + int ret; + + glibtop_init_p (server, 0, 0); + 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; } diff --git a/sysdeps/osf1/procuid.c b/sysdeps/osf1/procuid.c index c289ce54..40dc3a05 100644 --- a/sysdeps/osf1/procuid.c +++ b/sysdeps/osf1/procuid.c @@ -19,9 +19,11 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include #include +#include + #include #include @@ -47,20 +49,19 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf, int ret, info_count; task_t thistask; - glibtop_open_p (server, 0, 0); + glibtop_init_p (server, 0, 0); memset (buf, 0, sizeof (glibtop_proc_uid)); /* !!! 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, sizeof (struct tbl_procinfo)); + + glibtop_suid_leave (server); - if (setreuid (server->machine.euid, server->machine.uid)) - _exit (1); - /* !!! END OF SUID ROOT PART !!! */ if (ret != 1) return; @@ -81,7 +82,7 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf, /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ - setreuid (server->machine.uid, server->machine.euid); + glibtop_suid_enter (server); /* Get task structure. */ @@ -95,12 +96,12 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf, ret = task_info (thistask, TASK_BASIC_INFO, (task_info_t) &taskinfo, &info_count); - + + /* `ret' is evaluated outside the `if' clause. */ } + + glibtop_suid_leave (server); - if (setreuid (server->machine.euid, server->machine.uid)) - _exit (1); - /* !!! END OF SUID ROOT PART !!! */ if (ret != KERN_SUCCESS) return; diff --git a/sysdeps/sun4/open.c b/sysdeps/sun4/open.c index 507461b7..777e9525 100644 --- a/sysdeps/sun4/open.c +++ b/sysdeps/sun4/open.c @@ -63,13 +63,13 @@ struct nlist _glibtop_nlist[] = { /* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ void -glibtop_init_p (glibtop *server, const char *program_name, - const unsigned long features, const unsigned flags) +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, program_name, features, flags); + glibtop_open_p (server, "glibtop", features, flags); } void @@ -164,12 +164,14 @@ glibtop_open_p (glibtop *server, const char *program_name, server->machine.bytesize = server->machine.epages - server->machine.pages; - server->machine.count = server->machine.bytesize / sizeof (struct page); + server->machine.count = server->machine.bytesize / + sizeof (struct page); - server->machine.physpage = - (struct page *) glibtop_malloc_r (server, server->machine.bytesize); + server->machine.physpage = (struct page *) + 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();