New directory. This is mainly used as example for people porting libgtop

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

	* sysdeps/stub_suid: New directory. This is mainly used as example
	for people porting libgtop to other systems.
This commit is contained in:
Martin Baulig
1998-08-07 12:35:20 +00:00
committed by Martin Baulig
parent 4b3fcf149a
commit d72da1bb2f
28 changed files with 1293 additions and 0 deletions

View File

@@ -1,5 +1,8 @@
1998-08-07 Martin Baulig <martin@home-of-linux.org> 1998-08-07 Martin Baulig <martin@home-of-linux.org>
* sysdeps/stub_suid: New directory. This is mainly used as example
for people porting libgtop to other systems.
* glibtop.h (_glibtop): New fields `error_method', `sysdeps' and * glibtop.h (_glibtop): New fields `error_method', `sysdeps' and
`required'. I added an improved error handling: the client can tell `required'. I added an improved error handling: the client can tell
the libraries which fields are absolutely required for each features the libraries which fields are absolutely required for each features

View File

@@ -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

View File

@@ -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

28
sysdeps/stub_suid/close.c Normal file
View File

@@ -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)
{ }

46
sysdeps/stub_suid/cpu.c Normal file
View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/cpu.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_cpu = 0;
/* Init function. */
void
glibtop_init_cpu_p (glibtop *server)
{
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
}
/* Provides information about cpu usage. */
void
glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_CPU, 0);
memset (buf, 0, sizeof (glibtop_cpu));
}

View File

@@ -0,0 +1,37 @@
/* $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__
__BEGIN_DECLS
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 */
};
__END_DECLS
#endif

View File

@@ -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

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) {
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

43
sysdeps/stub_suid/init.c Normal file
View File

@@ -0,0 +1,43 @@
/* $Id$ */
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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>
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = NULL;
glibtop *
glibtop_init_r (glibtop **server,
const unsigned long features,
const unsigned flags)
{
if (*server != NULL)
return *server;
if (glibtop_global_server == NULL) {
glibtop_global_server = &_glibtop_global_server;
glibtop_open (glibtop_global_server, "glibtop",
features, flags);
}
return *server = glibtop_global_server;
}

View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/loadavg.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_loadavg = 0;
/* Init function. */
void
glibtop_init_loadavg_p (glibtop *server)
{
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
}
/* Provides load averange. */
void
glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_LOADAVG, 0);
memset (buf, 0, sizeof (glibtop_loadavg));
}

46
sysdeps/stub_suid/mem.c Normal file
View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/mem.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_mem = 0;
/* Init function. */
void
glibtop_init_mem_p (glibtop *server)
{
server->sysdeps.mem = _glibtop_sysdeps_mem;
}
/* Provides information about memory usage. */
void
glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_MEM, 0);
memset (buf, 0, sizeof (glibtop_mem));
}

View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/msg_limits.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_msg_limits = 0;
/* Init function. */
void
glibtop_init_msg_limits_p (glibtop *server)
{
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
}
/* Provides information about sysv ipc limits. */
void
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_msg_limits));
}

View File

@@ -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)
{ }

75
sysdeps/stub_suid/open.c Normal file
View File

@@ -0,0 +1,75 @@
/* $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>
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
void
glibtop_init_p (glibtop *server, const unsigned long features,
const unsigned flags)
{
glibtop_init_func_t *init_fkt;
if (server == NULL)
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
/* Do the initialization, but only if not already initialized. */
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
glibtop_open_p (server, "glibtop", features, flags);
for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
(*init_fkt) (server);
server->flags |= _GLIBTOP_INIT_STATE_INIT;
}
}
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 ();
/* 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. */
}

View File

@@ -0,0 +1,178 @@
/* $Id$ */
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
Contributed by Joshua Sled <jsled@xcf.berkeley.edu>, July 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/procdata.h>
#include <sys/stat.h>
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
#define BIT_SHIFT(x) (1 << (x % 32))
static const unsigned long _glibtop_sysdeps_procdata_0 =
BIT_SHIFT(GLIBTOP_PROCDATA_CMD) +
BIT_SHIFT(GLIBTOP_PROCDATA_STATE) +
BIT_SHIFT(GLIBTOP_PROCDATA_UID) +
BIT_SHIFT(GLIBTOP_PROCDATA_PID) +
BIT_SHIFT(GLIBTOP_PROCDATA_PPID) +
BIT_SHIFT(GLIBTOP_PROCDATA_PGRP) +
BIT_SHIFT(GLIBTOP_PROCDATA_SESSION) +
BIT_SHIFT(GLIBTOP_PROCDATA_TTY) +
BIT_SHIFT(GLIBTOP_PROCDATA_TPGID) +
BIT_SHIFT(GLIBTOP_PROCDATA_PRIORITY) +
BIT_SHIFT(GLIBTOP_PROCDATA_NICE) +
BIT_SHIFT(GLIBTOP_PROCDATA_SIGNAL) +
BIT_SHIFT(GLIBTOP_PROCDATA_BLOCKED) +
BIT_SHIFT(GLIBTOP_PROCDATA_SIGIGNORE) +
BIT_SHIFT(GLIBTOP_PROCDATA_SIGCATCH) +
BIT_SHIFT(GLIBTOP_PROCDATA_START_TIME) +
BIT_SHIFT(GLIBTOP_PROCDATA_UTIME) +
BIT_SHIFT(GLIBTOP_PROCDATA_STIME) +
BIT_SHIFT(GLIBTOP_PROCDATA_CUTIME) +
BIT_SHIFT(GLIBTOP_PROCDATA_CSTIME) +
BIT_SHIFT(GLIBTOP_PROCDATA_SIZE) +
BIT_SHIFT(GLIBTOP_PROCDATA_RESIDENT) +
BIT_SHIFT(GLIBTOP_PROCDATA_SHARE) +
BIT_SHIFT(GLIBTOP_PROCDATA_TRS) +
BIT_SHIFT(GLIBTOP_PROCDATA_LRS) +
BIT_SHIFT(GLIBTOP_PROCDATA_DRS) +
BIT_SHIFT(GLIBTOP_PROCDATA_DT) +
BIT_SHIFT(GLIBTOP_PROCDATA_VSIZE) +
BIT_SHIFT(GLIBTOP_PROCDATA_RSS) +
BIT_SHIFT(GLIBTOP_PROCDATA_RSS_RLIM) +
BIT_SHIFT(GLIBTOP_PROCDATA_TIMEOUT) +
BIT_SHIFT(GLIBTOP_PROCDATA_IT_REAL_VALUE);
static const unsigned long _glibtop_sysdeps_procdata_1 =
BIT_SHIFT(GLIBTOP_PROCDATA_K_FLAGS) +
BIT_SHIFT(GLIBTOP_PROCDATA_MIN_FLT) +
BIT_SHIFT(GLIBTOP_PROCDATA_MAJ_FLT) +
BIT_SHIFT(GLIBTOP_PROCDATA_CMIN_FLT) +
BIT_SHIFT(GLIBTOP_PROCDATA_CMAJ_FLT) +
BIT_SHIFT(GLIBTOP_PROCDATA_START_CODE) +
BIT_SHIFT(GLIBTOP_PROCDATA_END_CODE) +
BIT_SHIFT(GLIBTOP_PROCDATA_START_STACK) +
BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_ESP) +
BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_EIP) +
BIT_SHIFT(GLIBTOP_PROCDATA_WCHAN);
/* Provides detailed information about a process. */
void
glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
{
char input [BUFSIZ], *tmp;
struct stat statb;
int nread;
FILE *f;
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_procdata));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags [0] = _glibtop_sysdeps_procdata_0;
buf->flags [1] = _glibtop_sysdeps_procdata_1;
return;
}
sprintf (input, "/proc/%d/stat", pid);
if (stat (input, &statb)) return;
buf->uid = statb.st_uid;
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */
tmp = strrchr (input, ')');
*tmp = '\0'; /* replace trailing ')' with NUL */
/* parse these two strings separately, skipping the leading "(". */
memset (buf->cmd, 0, sizeof (buf->cmd));
sscanf (input, "%d (%39c", &buf->pid, buf->cmd);
sscanf(tmp + 2, /* skip space after ')' too */
"%c %d %d %d %d %d %lu %lu %lu %lu %lu "
"%ld %ld %ld %ld %d %d %lu %lu %ld %lu "
"%lu %lu %lu %lu %lu %lu %lu %d %d %d %d %lu",
&buf->state, &buf->ppid, &buf->pgrp, &buf->session,
&buf->tty, &buf->tpgid, &buf->k_flags, &buf->min_flt,
&buf->cmin_flt, &buf->maj_flt, &buf->cmaj_flt,
&buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
&buf->priority, &buf->nice, &buf->timeout,
&buf->it_real_value, &buf->start_time, &buf->vsize,
&buf->rss, &buf->rss_rlim, &buf->start_code,
&buf->end_code, &buf->start_stack, &buf->kstk_esp,
&buf->kstk_eip, &buf->signal, &buf->blocked,
&buf->sigignore, &buf->sigcatch, &buf->wchan);
if (buf->tty == 0)
/* the old notty val, update elsewhere bef. moving to 0 */
buf->tty = -1;
if (server->os_version_code < LINUX_VERSION(1,3,39)) {
/* map old meanings to new */
buf->priority = 2*15 - buf->priority;
buf->nice = 15 - buf->nice;
}
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
/* when tty wasn't full devno */
buf->tty = 4*0x100 + buf->tty;
fclose (f);
sprintf (input, "/proc/%d/statm", pid);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
sscanf (input, "%ld %ld %ld %ld %ld %ld %ld",
&buf->size, &buf->resident, &buf->share,
&buf->trs, &buf->lrs, &buf->drs, &buf->dt);
fclose (f);
buf->flags [0] = _glibtop_sysdeps_procdata_0;
buf->flags [1] = _glibtop_sysdeps_procdata_1;
}

View File

@@ -0,0 +1,47 @@
/* $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/error.h>
#include <glibtop/prockernel.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_kernel = 0;
/* Init function. */
void
glibtop_init_proc_kernel_p (glibtop *server)
{
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
pid_t pid)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
memset (buf, 0, sizeof (glibtop_proc_kernel));
}

View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/proclist.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proclist = 0;
/* Init function. */
void
glibtop_init_proclist_p (glibtop *server)
{
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
}
unsigned *
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROCLIST, 0);
memset (buf, 0, sizeof (glibtop_proclist));
return NULL;
}

View File

@@ -0,0 +1,47 @@
/* $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/error.h>
#include <glibtop/procmem.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_mem = 0;
/* Init function. */
void
glibtop_init_proc_mem_p (glibtop *server)
{
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
pid_t pid)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_MEM, 0);
memset (buf, 0, sizeof (glibtop_proc_mem));
}

View File

@@ -0,0 +1,47 @@
/* $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/error.h>
#include <glibtop/procsegment.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_segment = 0;
/* Init function. */
void
glibtop_init_proc_segment_p (glibtop *server)
{
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
memset (buf, 0, sizeof (glibtop_proc_segment));
}

View File

@@ -0,0 +1,47 @@
/* $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/error.h>
#include <glibtop/procsignal.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_signal = 0;
/* Init function. */
void
glibtop_init_proc_signal_p (glibtop *server)
{
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
pid_t pid)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
memset (buf, 0, sizeof (glibtop_proc_signal));
}

View File

@@ -0,0 +1,47 @@
/* $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/error.h>
#include <glibtop/procstate.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_state = 0;
/* Init function. */
void
glibtop_init_proc_state_p (glibtop *server)
{
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
pid_t pid)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
memset (buf, 0, sizeof (glibtop_proc_state));
}

View File

@@ -0,0 +1,47 @@
/* $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/error.h>
#include <glibtop/proctime.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_time = 0;
/* Init function. */
void
glibtop_init_proc_time_p (glibtop *server)
{
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
pid_t pid)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
memset (buf, 0, sizeof (glibtop_proc_time));
}

View File

@@ -0,0 +1,47 @@
/* $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/error.h>
#include <glibtop/procuid.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_uid = 0;
/* Init function. */
void
glibtop_init_proc_uid_p (glibtop *server)
{
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
pid_t pid)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_UID, 0);
memset (buf, 0, sizeof (glibtop_proc_uid));
}

View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/sem_limits.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_sem_limits = 0;
/* Init function. */
void
glibtop_init_sem_limits_p (glibtop *server)
{
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
}
/* Provides information about sysv sem limits. */
void
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_sem_limits));
}

View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/shm_limits.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_shm_limits = 0;
/* Init function. */
void
glibtop_init_shm_limits_p (glibtop *server)
{
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
}
/* Provides information about sysv ipc limits. */
void
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_shm_limits));
}

View File

@@ -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 } };

46
sysdeps/stub_suid/swap.c Normal file
View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/swap.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_swap = 0;
/* Init function. */
void
glibtop_init_swap_p (glibtop *server)
{
server->sysdeps.swap = _glibtop_sysdeps_swap;
}
/* Provides information about swap usage. */
void
glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_SWAP, 0);
memset (buf, 0, sizeof (glibtop_swap));
}

View File

@@ -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. */
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/uptime.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_uptime = 0;
/* Init function. */
void
glibtop_init_uptime_p (glibtop *server)
{
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
}
/* Provides uptime and idle time. */
void
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_UPTIME, 0);
memset (buf, 0, sizeof (glibtop_uptime));
}