The indentation in LibGTop was done with the following command:
find . -name \*.[ch] | xargs -i emacs -batch {} \ -l /gnome/compile/libgtop/misc/format.el -f save-buffer December 26, 1999 Martin
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
|
|
||||||
/* Define if gethostname () must be declared. */
|
/* Define if gethostname () must be declared. */
|
||||||
#undef NEED_DECLARATION_GETHOSTNAME
|
#undef NEED_DECLARATION_GETHOSTNAME
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -31,12 +33,12 @@
|
|||||||
struct _glibtop_server_private
|
struct _glibtop_server_private
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GLIBTOP_MACHINE_H
|
#ifdef HAVE_GLIBTOP_MACHINE_H
|
||||||
glibtop_machine machine; /* Machine dependent data */
|
glibtop_machine machine; /* Machine dependent data */
|
||||||
#endif
|
#endif
|
||||||
int input [2]; /* Pipe client <- server */
|
int input [2]; /* Pipe client <- server */
|
||||||
int output [2]; /* Pipe client -> server */
|
int output [2]; /* Pipe client -> server */
|
||||||
int socket; /* Accepted connection of a socket */
|
int socket; /* Accepted connection of a socket */
|
||||||
pid_t pid; /* PID of the server */
|
pid_t pid; /* PID of the server */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
38
glibtop.h
38
glibtop.h
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -48,24 +50,24 @@ typedef struct _glibtop_server_private glibtop_server_private;
|
|||||||
|
|
||||||
struct _glibtop
|
struct _glibtop
|
||||||
{
|
{
|
||||||
int refcount; /* Reference count */
|
int refcount; /* Reference count */
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
unsigned method; /* Server Method */
|
unsigned method; /* Server Method */
|
||||||
unsigned error_method; /* Error Method */
|
unsigned error_method; /* Error Method */
|
||||||
int ncpu; /* Number of CPUs, zero if single-processor */
|
int ncpu; /* Number of CPUs, zero if single-processor */
|
||||||
unsigned long os_version_code; /* Version code of the operating system */
|
unsigned long os_version_code; /* Version code of the operating system */
|
||||||
const char *name; /* Program name for error messages */
|
const char *name; /* Program name for error messages */
|
||||||
const char *server_command; /* Command used to invoke server */
|
const char *server_command; /* Command used to invoke server */
|
||||||
const char *server_host; /* Host the server should run on */
|
const char *server_host; /* Host the server should run on */
|
||||||
const char *server_user; /* Name of the user on the target host */
|
const char *server_user; /* Name of the user on the target host */
|
||||||
const char *server_rsh; /* Command used to connect to the target host */
|
const char *server_rsh; /* Command used to connect to the target host */
|
||||||
unsigned long features; /* Server is required for this features */
|
unsigned long features; /* Server is required for this features */
|
||||||
unsigned long server_port; /* Port on which daemon is listening */
|
unsigned long server_port; /* Port on which daemon is listening */
|
||||||
glibtop_sysdeps sysdeps; /* Detailed feature list */
|
glibtop_sysdeps sysdeps; /* Detailed feature list */
|
||||||
glibtop_sysdeps required; /* Required feature list */
|
glibtop_sysdeps required; /* Required feature list */
|
||||||
glibtop_sysdeps wanted; /* We only want this features */
|
glibtop_sysdeps wanted; /* We only want this features */
|
||||||
glibtop_server_private *_priv; /* Private data */
|
glibtop_server_private *_priv; /* Private data */
|
||||||
unsigned glibtop_errno;
|
unsigned glibtop_errno;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern glibtop *glibtop_global_server;
|
extern glibtop *glibtop_global_server;
|
||||||
|
@@ -41,10 +41,10 @@ typedef struct _glibtop_array glibtop_array;
|
|||||||
|
|
||||||
struct _glibtop_array
|
struct _glibtop_array
|
||||||
{
|
{
|
||||||
u_int64_t flags,
|
u_int64_t flags,
|
||||||
number, /* GLIBTOP_ARRAY_NUMBER */
|
number, /* GLIBTOP_ARRAY_NUMBER */
|
||||||
size, /* GLIBTOP_ARRAY_SIZE */
|
size, /* GLIBTOP_ARRAY_SIZE */
|
||||||
total; /* GLIBTOP_ARRAY_TOTAL */
|
total; /* GLIBTOP_ARRAY_TOTAL */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* linux/libgtop/module.c
|
* linux/libgtop/module.c
|
||||||
* Copyright (C) 1999 Martin Baulig
|
* Copyright (C) 1999 Martin Baulig
|
||||||
@@ -282,7 +284,7 @@ get_wchan (struct task_struct *p)
|
|||||||
# define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
|
# define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
|
||||||
# define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
|
# define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
|
||||||
#elif defined(__alpha__)
|
#elif defined(__alpha__)
|
||||||
/*
|
/*
|
||||||
* See arch/alpha/kernel/ptrace.c for details.
|
* See arch/alpha/kernel/ptrace.c for details.
|
||||||
*/
|
*/
|
||||||
# define PT_REG(reg) (PAGE_SIZE - sizeof(struct pt_regs) \
|
# define PT_REG(reg) (PAGE_SIZE - sizeof(struct pt_regs) \
|
||||||
@@ -426,8 +428,8 @@ statm_pgd_range (pgd_t * pgd, unsigned long address, unsigned long end,
|
|||||||
statm_pmd_range (pgd, address, end - address, pages,
|
statm_pmd_range (pgd, address, end - address, pages,
|
||||||
shared, dirty, total);
|
shared, dirty, total);
|
||||||
address = (address + PGDIR_SIZE) & PGDIR_MASK;
|
address = (address + PGDIR_SIZE) & PGDIR_MASK;
|
||||||
pgd++;
|
pgd++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
#ifndef _LINUX_LIBGTOP_H
|
#ifndef _LINUX_LIBGTOP_H
|
||||||
#define _LINUX_LIBGTOP_H 1
|
#define _LINUX_LIBGTOP_H 1
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* linux/libgtop/libgtop_syms.c
|
* linux/libgtop/libgtop_syms.c
|
||||||
* Copyright (C) 1999 Martin Baulig
|
* Copyright (C) 1999 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* linux/libgtop/main.c
|
* linux/libgtop/main.c
|
||||||
* Copyright (C) 1999 Martin Baulig
|
* Copyright (C) 1999 Martin Baulig
|
||||||
|
30
lib/close.c
30
lib/close.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -31,20 +33,20 @@
|
|||||||
void
|
void
|
||||||
glibtop_close_r (glibtop *server)
|
glibtop_close_r (glibtop *server)
|
||||||
{
|
{
|
||||||
switch (server->method) {
|
switch (server->method) {
|
||||||
case GLIBTOP_METHOD_UNIX:
|
case GLIBTOP_METHOD_UNIX:
|
||||||
case GLIBTOP_METHOD_INET:
|
case GLIBTOP_METHOD_INET:
|
||||||
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
|
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
|
||||||
0, NULL, 0, NULL, NULL);
|
0, NULL, 0, NULL, NULL);
|
||||||
|
|
||||||
if (close (server->_priv->socket))
|
if (close (server->_priv->socket))
|
||||||
glibtop_warn_io ("close");
|
glibtop_warn_io ("close");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_METHOD_PIPE:
|
case GLIBTOP_METHOD_PIPE:
|
||||||
kill (server->_priv->pid, SIGKILL);
|
kill (server->_priv->pid, SIGKILL);
|
||||||
close (server->_priv->input [0]);
|
close (server->_priv->input [0]);
|
||||||
close (server->_priv->output [1]);
|
close (server->_priv->output [1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -33,51 +35,51 @@ glibtop_call_l (glibtop *server, unsigned command, size_t send_size,
|
|||||||
const void *send_buf, size_t recv_size, void *recv_buf,
|
const void *send_buf, size_t recv_size, void *recv_buf,
|
||||||
int *retval_ptr)
|
int *retval_ptr)
|
||||||
{
|
{
|
||||||
glibtop_command cmnd;
|
glibtop_command cmnd;
|
||||||
glibtop_response response;
|
glibtop_response response;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
glibtop_init_r (&server, 0, 0);
|
glibtop_init_r (&server, 0, 0);
|
||||||
|
|
||||||
memset (&cmnd, 0, sizeof (glibtop_command));
|
memset (&cmnd, 0, sizeof (glibtop_command));
|
||||||
|
|
||||||
cmnd.command = command;
|
cmnd.command = command;
|
||||||
|
|
||||||
/* If send_size is less than _GLIBTOP_PARAM_SIZE (normally 16 Bytes), we
|
/* If send_size is less than _GLIBTOP_PARAM_SIZE (normally 16 Bytes), we
|
||||||
* send it together with command, so we only need one system call instead
|
* send it together with command, so we only need one system call instead
|
||||||
* of two. */
|
* of two. */
|
||||||
|
|
||||||
if (send_size <= _GLIBTOP_PARAM_SIZE) {
|
if (send_size <= _GLIBTOP_PARAM_SIZE) {
|
||||||
memcpy (cmnd.parameter, send_buf, send_size);
|
memcpy (cmnd.parameter, send_buf, send_size);
|
||||||
cmnd.size = send_size;
|
cmnd.size = send_size;
|
||||||
} else {
|
} else {
|
||||||
cmnd.data_size = send_size;
|
cmnd.data_size = send_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
glibtop_write_l (server, sizeof (glibtop_command), &cmnd);
|
glibtop_write_l (server, sizeof (glibtop_command), &cmnd);
|
||||||
|
|
||||||
glibtop_read_l (server, sizeof (glibtop_response), &response);
|
glibtop_read_l (server, sizeof (glibtop_response), &response);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "RESPONSE: %lu - %d\n",
|
fprintf (stderr, "RESPONSE: %lu - %d\n",
|
||||||
response.offset, response.data_size);
|
response.offset, response.data_size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glibtop_read_l (server, sizeof (int), &retval);
|
glibtop_read_l (server, sizeof (int), &retval);
|
||||||
if (retval_ptr)
|
if (retval_ptr)
|
||||||
*retval_ptr = retval;
|
*retval_ptr = retval;
|
||||||
|
|
||||||
if (recv_buf)
|
if (recv_buf)
|
||||||
memcpy (recv_buf, ((char *) &response) + response.offset,
|
memcpy (recv_buf, ((char *) &response) + response.offset,
|
||||||
recv_size);
|
recv_size);
|
||||||
|
|
||||||
if (response.data_size) {
|
if (response.data_size) {
|
||||||
void *ptr = glibtop_malloc_r (server, response.data_size);
|
void *ptr = glibtop_malloc_r (server, response.data_size);
|
||||||
|
|
||||||
glibtop_read_l (server, response.data_size, ptr);
|
glibtop_read_l (server, response.data_size, ptr);
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
364
lib/init.c
364
lib/init.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -36,242 +38,242 @@ glibtop *glibtop_global_server = &_glibtop_global_server;
|
|||||||
static void
|
static void
|
||||||
_init_server (glibtop *server, const unsigned features)
|
_init_server (glibtop *server, const unsigned features)
|
||||||
{
|
{
|
||||||
char *command, *temp;
|
char *command, *temp;
|
||||||
|
|
||||||
/* Try to get server command, but don't override if already
|
/* Try to get server command, but don't override if already
|
||||||
* set via glibtop_set_parameter () */
|
* set via glibtop_set_parameter () */
|
||||||
|
|
||||||
if (server->server_command == NULL) {
|
if (server->server_command == NULL) {
|
||||||
const char *temp = getenv ("LIBGTOP_SERVER") ?
|
const char *temp = getenv ("LIBGTOP_SERVER") ?
|
||||||
getenv ("LIBGTOP_SERVER") : LIBGTOP_SERVER;
|
getenv ("LIBGTOP_SERVER") : LIBGTOP_SERVER;
|
||||||
|
|
||||||
server->server_command = glibtop_strdup_r (server, temp);
|
server->server_command = glibtop_strdup_r (server, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server->server_rsh == NULL) {
|
if (server->server_rsh == NULL) {
|
||||||
const char *temp = getenv ("LIBGTOP_RSH") ?
|
const char *temp = getenv ("LIBGTOP_RSH") ?
|
||||||
getenv ("LIBGTOP_RSH") : "/usr/bin/ssh";
|
getenv ("LIBGTOP_RSH") : "/usr/bin/ssh";
|
||||||
|
|
||||||
server->server_rsh = glibtop_strdup_r (server, temp);
|
server->server_rsh = glibtop_strdup_r (server, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to get server method, but don't override if already
|
/* Try to get server method, but don't override if already
|
||||||
* set via glibtop_set_parameter () */
|
* set via glibtop_set_parameter () */
|
||||||
|
|
||||||
if (server->method) return;
|
if (server->method) return;
|
||||||
|
|
||||||
/* If server->command doesn't start with a colon, then it is
|
/* If server->command doesn't start with a colon, then it is
|
||||||
* the full pathname of the server executable. */
|
* the full pathname of the server executable. */
|
||||||
|
|
||||||
if (server->server_command [0] != ':') {
|
|
||||||
if (features & glibtop_server_features) {
|
|
||||||
/* We really need the server. */
|
|
||||||
server->method = GLIBTOP_METHOD_PIPE;
|
|
||||||
} else {
|
|
||||||
/* Fine. No server is needed, so we call the
|
|
||||||
* sysdeps functions directly. */
|
|
||||||
server->method = GLIBTOP_METHOD_DIRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* If the first character of 'server_command' is a colon,
|
|
||||||
* the first field is the method to connect to the server. */
|
|
||||||
|
|
||||||
/* Everything up to the next colon is the method. */
|
|
||||||
|
|
||||||
command = glibtop_strdup_r (server, server->server_command+1);
|
|
||||||
temp = strstr (command, ":");
|
|
||||||
if (temp) *temp = 0;
|
|
||||||
|
|
||||||
/* Dispatch method. */
|
|
||||||
|
|
||||||
if (!strcmp (command, "direct")) {
|
|
||||||
/* Use sysdeps dir instead of connecting to server
|
|
||||||
* even if using the server would be required on
|
|
||||||
* the current system. */
|
|
||||||
server->method = GLIBTOP_METHOD_DIRECT;
|
|
||||||
|
|
||||||
} else if (!strcmp (command, "inet")) {
|
|
||||||
|
|
||||||
server->method = GLIBTOP_METHOD_INET;
|
|
||||||
|
|
||||||
/* Connect to internet server. */
|
|
||||||
|
|
||||||
if (temp == NULL) {
|
|
||||||
/* If no value was set, we use 'localhost'. */
|
|
||||||
if (server->server_host == NULL)
|
|
||||||
server->server_host = glibtop_strdup_r
|
|
||||||
(server, "localhost");
|
|
||||||
} else {
|
|
||||||
char *temp2 = strstr (temp+1, ":");
|
|
||||||
if (temp2) *temp2 = 0;
|
|
||||||
|
|
||||||
/* Override default. */
|
|
||||||
if (server->server_host)
|
|
||||||
glibtop_free_r (server,
|
|
||||||
(char *) server->server_host);
|
|
||||||
|
|
||||||
server->server_host = glibtop_strdup_r
|
|
||||||
(server, temp+1);
|
|
||||||
|
|
||||||
temp = temp2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (temp == NULL) {
|
|
||||||
/* If no value was set, we use DEFAULT_PORT. */
|
|
||||||
if (server->server_port == 0)
|
|
||||||
server->server_port = DEFAULT_PORT;
|
|
||||||
} else {
|
|
||||||
char *temp2 = strstr (temp+1, ":");
|
|
||||||
if (temp2) *temp2 = 0;
|
|
||||||
|
|
||||||
if (sscanf (temp+1, "%ld", &server->server_port) != 1)
|
|
||||||
server->server_port = DEFAULT_PORT;
|
|
||||||
|
|
||||||
temp = temp2 ? temp2 + 1 : temp2;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (!strcmp (command, "unix")) {
|
|
||||||
|
|
||||||
/* Connect to unix domain socket. */
|
|
||||||
server->method = GLIBTOP_METHOD_UNIX;
|
|
||||||
|
|
||||||
} else if (!strcmp (command, "pipe")) {
|
|
||||||
|
|
||||||
/* Open pipe to server. */
|
|
||||||
server->method = GLIBTOP_METHOD_PIPE;
|
|
||||||
|
|
||||||
|
if (server->server_command [0] != ':') {
|
||||||
|
if (features & glibtop_server_features) {
|
||||||
|
/* We really need the server. */
|
||||||
|
server->method = GLIBTOP_METHOD_PIPE;
|
||||||
} else {
|
} else {
|
||||||
|
/* Fine. No server is needed, so we call the
|
||||||
glibtop_error_r (server, "Unknown server method '%s'",
|
* sysdeps functions directly. */
|
||||||
server->server_command+1);
|
server->method = GLIBTOP_METHOD_DIRECT;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glibtop_free_r (server, command);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* If the first character of 'server_command' is a colon,
|
||||||
|
* the first field is the method to connect to the server. */
|
||||||
|
|
||||||
|
/* Everything up to the next colon is the method. */
|
||||||
|
|
||||||
|
command = glibtop_strdup_r (server, server->server_command+1);
|
||||||
|
temp = strstr (command, ":");
|
||||||
|
if (temp) *temp = 0;
|
||||||
|
|
||||||
|
/* Dispatch method. */
|
||||||
|
|
||||||
|
if (!strcmp (command, "direct")) {
|
||||||
|
/* Use sysdeps dir instead of connecting to server
|
||||||
|
* even if using the server would be required on
|
||||||
|
* the current system. */
|
||||||
|
server->method = GLIBTOP_METHOD_DIRECT;
|
||||||
|
|
||||||
|
} else if (!strcmp (command, "inet")) {
|
||||||
|
|
||||||
|
server->method = GLIBTOP_METHOD_INET;
|
||||||
|
|
||||||
|
/* Connect to internet server. */
|
||||||
|
|
||||||
|
if (temp == NULL) {
|
||||||
|
/* If no value was set, we use 'localhost'. */
|
||||||
|
if (server->server_host == NULL)
|
||||||
|
server->server_host = glibtop_strdup_r
|
||||||
|
(server, "localhost");
|
||||||
|
} else {
|
||||||
|
char *temp2 = strstr (temp+1, ":");
|
||||||
|
if (temp2) *temp2 = 0;
|
||||||
|
|
||||||
|
/* Override default. */
|
||||||
|
if (server->server_host)
|
||||||
|
glibtop_free_r (server,
|
||||||
|
(char *) server->server_host);
|
||||||
|
|
||||||
|
server->server_host = glibtop_strdup_r
|
||||||
|
(server, temp+1);
|
||||||
|
|
||||||
|
temp = temp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp == NULL) {
|
||||||
|
/* If no value was set, we use DEFAULT_PORT. */
|
||||||
|
if (server->server_port == 0)
|
||||||
|
server->server_port = DEFAULT_PORT;
|
||||||
|
} else {
|
||||||
|
char *temp2 = strstr (temp+1, ":");
|
||||||
|
if (temp2) *temp2 = 0;
|
||||||
|
|
||||||
|
if (sscanf (temp+1, "%ld", &server->server_port) != 1)
|
||||||
|
server->server_port = DEFAULT_PORT;
|
||||||
|
|
||||||
|
temp = temp2 ? temp2 + 1 : temp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (!strcmp (command, "unix")) {
|
||||||
|
|
||||||
|
/* Connect to unix domain socket. */
|
||||||
|
server->method = GLIBTOP_METHOD_UNIX;
|
||||||
|
|
||||||
|
} else if (!strcmp (command, "pipe")) {
|
||||||
|
|
||||||
|
/* Open pipe to server. */
|
||||||
|
server->method = GLIBTOP_METHOD_PIPE;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
glibtop_error_r (server, "Unknown server method '%s'",
|
||||||
|
server->server_command+1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
glibtop_free_r (server, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_server_ref (glibtop *server)
|
glibtop_server_ref (glibtop *server)
|
||||||
{
|
{
|
||||||
if (server == NULL)
|
if (server == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
server->refcount++;
|
server->refcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_server_unref (glibtop *server)
|
glibtop_server_unref (glibtop *server)
|
||||||
{
|
{
|
||||||
if (server == NULL)
|
if (server == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!server->refcount) {
|
if (!server->refcount) {
|
||||||
glibtop_warn_r (server, "Attempted to unref server "
|
glibtop_warn_r (server, "Attempted to unref server "
|
||||||
"which refcount == 0");
|
"which refcount == 0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
server->refcount--;
|
server->refcount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
glibtop *
|
glibtop *
|
||||||
glibtop_init_r (glibtop **server_ptr, unsigned long features, unsigned flags)
|
glibtop_init_r (glibtop **server_ptr, unsigned long features, unsigned flags)
|
||||||
{
|
{
|
||||||
glibtop *server;
|
glibtop *server;
|
||||||
|
|
||||||
if (server_ptr == NULL)
|
if (server_ptr == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (*server_ptr == NULL)
|
if (*server_ptr == NULL)
|
||||||
*server_ptr = glibtop_global_server;
|
*server_ptr = glibtop_global_server;
|
||||||
|
|
||||||
server = *server_ptr;
|
server = *server_ptr;
|
||||||
|
|
||||||
/* Should we do the initialization? */
|
/* Should we do the initialization? */
|
||||||
|
|
||||||
if (flags & GLIBTOP_INIT_NO_INIT)
|
if (flags & GLIBTOP_INIT_NO_INIT)
|
||||||
return server;
|
return server;
|
||||||
|
|
||||||
/* Do the initialization, but only if not already initialized. */
|
/* Do the initialization, but only if not already initialized. */
|
||||||
|
|
||||||
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
|
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
|
||||||
if (flags & GLIBTOP_FEATURES_EXCEPT)
|
if (flags & GLIBTOP_FEATURES_EXCEPT)
|
||||||
features = ~features & GLIBTOP_SYSDEPS_ALL;
|
features = ~features & GLIBTOP_SYSDEPS_ALL;
|
||||||
|
|
||||||
if (features == 0)
|
if (features == 0)
|
||||||
features = GLIBTOP_SYSDEPS_ALL;
|
features = GLIBTOP_SYSDEPS_ALL;
|
||||||
|
|
||||||
if (flags & GLIBTOP_FEATURES_NO_SERVER) {
|
if (flags & GLIBTOP_FEATURES_NO_SERVER) {
|
||||||
server->method = GLIBTOP_METHOD_DIRECT;
|
server->method = GLIBTOP_METHOD_DIRECT;
|
||||||
features = 0;
|
features = 0;
|
||||||
}
|
|
||||||
|
|
||||||
server->features = features;
|
|
||||||
|
|
||||||
_init_server (server, features);
|
|
||||||
|
|
||||||
server->flags |= _GLIBTOP_INIT_STATE_INIT;
|
|
||||||
|
|
||||||
switch (server->method) {
|
|
||||||
case GLIBTOP_METHOD_PIPE:
|
|
||||||
case GLIBTOP_METHOD_UNIX:
|
|
||||||
if (glibtop_server_features & features)
|
|
||||||
break;
|
|
||||||
|
|
||||||
server->method = GLIBTOP_METHOD_DIRECT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should we open the server? */
|
server->features = features;
|
||||||
|
|
||||||
if (flags & GLIBTOP_INIT_NO_OPEN)
|
_init_server (server, features);
|
||||||
return server;
|
|
||||||
|
|
||||||
/* Open server, but only if not already opened. */
|
server->flags |= _GLIBTOP_INIT_STATE_INIT;
|
||||||
|
|
||||||
if ((server->flags & _GLIBTOP_INIT_STATE_OPEN) == 0)
|
switch (server->method) {
|
||||||
glibtop_open_l (glibtop_global_server, "glibtop",
|
case GLIBTOP_METHOD_PIPE:
|
||||||
features, flags);
|
case GLIBTOP_METHOD_UNIX:
|
||||||
|
if (glibtop_server_features & features)
|
||||||
|
break;
|
||||||
|
|
||||||
|
server->method = GLIBTOP_METHOD_DIRECT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Should we open the server? */
|
||||||
|
|
||||||
|
if (flags & GLIBTOP_INIT_NO_OPEN)
|
||||||
return server;
|
return server;
|
||||||
|
|
||||||
|
/* Open server, but only if not already opened. */
|
||||||
|
|
||||||
|
if ((server->flags & _GLIBTOP_INIT_STATE_OPEN) == 0)
|
||||||
|
glibtop_open_l (glibtop_global_server, "glibtop",
|
||||||
|
features, flags);
|
||||||
|
|
||||||
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
glibtop *
|
glibtop *
|
||||||
glibtop_init_s (glibtop **server_ptr, unsigned long features, unsigned flags)
|
glibtop_init_s (glibtop **server_ptr, unsigned long features, unsigned flags)
|
||||||
{
|
{
|
||||||
glibtop *server;
|
glibtop *server;
|
||||||
glibtop_init_func_t *init_fkt;
|
glibtop_init_func_t *init_fkt;
|
||||||
|
|
||||||
if (server_ptr == NULL)
|
if (server_ptr == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (*server_ptr == NULL)
|
if (*server_ptr == NULL)
|
||||||
*server_ptr = glibtop_global_server;
|
*server_ptr = glibtop_global_server;
|
||||||
|
|
||||||
server = *server_ptr;
|
server = *server_ptr;
|
||||||
|
|
||||||
/* Should we do the initialization? */
|
/* Should we do the initialization? */
|
||||||
|
|
||||||
if (flags & GLIBTOP_INIT_NO_INIT)
|
|
||||||
return server;
|
|
||||||
|
|
||||||
/* Do the initialization, but only if not already initialized. */
|
|
||||||
|
|
||||||
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
|
|
||||||
glibtop_open_s (server, "glibtop", features, flags);
|
|
||||||
|
|
||||||
for (init_fkt = _glibtop_init_hook_s; *init_fkt; init_fkt++)
|
|
||||||
(*init_fkt) (server);
|
|
||||||
|
|
||||||
server->sysdeps.pointer_size = sizeof (void*)*8;
|
|
||||||
|
|
||||||
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (flags & GLIBTOP_INIT_NO_INIT)
|
||||||
return server;
|
return server;
|
||||||
|
|
||||||
|
/* Do the initialization, but only if not already initialized. */
|
||||||
|
|
||||||
|
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
|
||||||
|
glibtop_open_s (server, "glibtop", features, flags);
|
||||||
|
|
||||||
|
for (init_fkt = _glibtop_init_hook_s; *init_fkt; init_fkt++)
|
||||||
|
(*init_fkt) (server);
|
||||||
|
|
||||||
|
server->sysdeps.pointer_size = sizeof (void*)*8;
|
||||||
|
|
||||||
|
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return server;
|
||||||
}
|
}
|
||||||
|
100
lib/inodedb.c
100
lib/inodedb.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -37,44 +39,44 @@ glibtop_inodedb *
|
|||||||
glibtop_inodedb_open_s (glibtop *server, unsigned databases,
|
glibtop_inodedb_open_s (glibtop *server, unsigned databases,
|
||||||
unsigned long cachesize)
|
unsigned long cachesize)
|
||||||
{
|
{
|
||||||
glibtop_inodedb *inodedb;
|
glibtop_inodedb *inodedb;
|
||||||
char filename [BUFSIZ];
|
char filename [BUFSIZ];
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
|
|
||||||
if (!databases)
|
if (!databases)
|
||||||
databases = GLIBTOP_INODEDB_ALL;
|
databases = GLIBTOP_INODEDB_ALL;
|
||||||
|
|
||||||
inodedb = glibtop_calloc_r (server, 1, sizeof (glibtop_inodedb));
|
inodedb = glibtop_calloc_r (server, 1, sizeof (glibtop_inodedb));
|
||||||
|
|
||||||
if (stat (SYSTEM_INODEDB, &statb))
|
if (stat (SYSTEM_INODEDB, &statb))
|
||||||
databases &= ~GLIBTOP_INODEDB_SYSTEM;
|
databases &= ~GLIBTOP_INODEDB_SYSTEM;
|
||||||
|
|
||||||
if (databases & GLIBTOP_INODEDB_SYSTEM) {
|
if (databases & GLIBTOP_INODEDB_SYSTEM) {
|
||||||
inodedb->system_dbf = gdbm_open
|
inodedb->system_dbf = gdbm_open
|
||||||
(SYSTEM_INODEDB, 0, GDBM_READER, 0, 0);
|
(SYSTEM_INODEDB, 0, GDBM_READER, 0, 0);
|
||||||
if (!inodedb->system_dbf)
|
if (!inodedb->system_dbf)
|
||||||
glibtop_error_io_r
|
glibtop_error_io_r
|
||||||
(server, "gdbm_open (%s)", SYSTEM_INODEDB);
|
(server, "gdbm_open (%s)", SYSTEM_INODEDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
pwd = getpwuid (getuid ());
|
pwd = getpwuid (getuid ());
|
||||||
if (!pwd) glibtop_error_io_r (server, "getpwuid");
|
if (!pwd) glibtop_error_io_r (server, "getpwuid");
|
||||||
|
|
||||||
sprintf (filename, "%s/var/libgtop/inodedb.db", pwd->pw_dir);
|
sprintf (filename, "%s/var/libgtop/inodedb.db", pwd->pw_dir);
|
||||||
|
|
||||||
if (stat (filename, &statb))
|
if (stat (filename, &statb))
|
||||||
databases &= ~GLIBTOP_INODEDB_USER;
|
databases &= ~GLIBTOP_INODEDB_USER;
|
||||||
|
|
||||||
if (databases & GLIBTOP_INODEDB_USER) {
|
if (databases & GLIBTOP_INODEDB_USER) {
|
||||||
inodedb->user_dbf = gdbm_open
|
inodedb->user_dbf = gdbm_open
|
||||||
(filename, 0, GDBM_READER, 0, 0);
|
(filename, 0, GDBM_READER, 0, 0);
|
||||||
if (!inodedb->user_dbf)
|
if (!inodedb->user_dbf)
|
||||||
glibtop_error_io_r
|
glibtop_error_io_r
|
||||||
(server, "gdbm_open (%s)", filename);
|
(server, "gdbm_open (%s)", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return inodedb;
|
return inodedb;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
@@ -82,36 +84,36 @@ glibtop_inodedb_lookup_s (glibtop *server,
|
|||||||
glibtop_inodedb *inodedb,
|
glibtop_inodedb *inodedb,
|
||||||
u_int64_t device, u_int64_t inode)
|
u_int64_t device, u_int64_t inode)
|
||||||
{
|
{
|
||||||
glibtop_inodedb_key key;
|
glibtop_inodedb_key key;
|
||||||
datum d_key, d_content;
|
datum d_key, d_content;
|
||||||
|
|
||||||
d_key.dptr = (void *) &key;
|
d_key.dptr = (void *) &key;
|
||||||
d_key.dsize = sizeof (key);
|
d_key.dsize = sizeof (key);
|
||||||
|
|
||||||
key.device = device;
|
key.device = device;
|
||||||
key.inode = inode;
|
key.inode = inode;
|
||||||
|
|
||||||
if (inodedb->system_dbf) {
|
if (inodedb->system_dbf) {
|
||||||
d_content = gdbm_fetch (inodedb->system_dbf, d_key);
|
d_content = gdbm_fetch (inodedb->system_dbf, d_key);
|
||||||
if (d_content.dptr) return d_content.dptr;
|
if (d_content.dptr) return d_content.dptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inodedb->user_dbf) {
|
if (inodedb->user_dbf) {
|
||||||
d_content = gdbm_fetch (inodedb->user_dbf, d_key);
|
d_content = gdbm_fetch (inodedb->user_dbf, d_key);
|
||||||
if (d_content.dptr) return d_content.dptr;
|
if (d_content.dptr) return d_content.dptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_inodedb_close_s (glibtop *server, glibtop_inodedb *inodedb)
|
glibtop_inodedb_close_s (glibtop *server, glibtop_inodedb *inodedb)
|
||||||
{
|
{
|
||||||
if (inodedb->system_dbf)
|
if (inodedb->system_dbf)
|
||||||
gdbm_close (inodedb->system_dbf);
|
gdbm_close (inodedb->system_dbf);
|
||||||
|
|
||||||
if (inodedb->user_dbf)
|
if (inodedb->user_dbf)
|
||||||
gdbm_close (inodedb->user_dbf);
|
gdbm_close (inodedb->user_dbf);
|
||||||
|
|
||||||
glibtop_free_r (server, inodedb);
|
glibtop_free_r (server, inodedb);
|
||||||
}
|
}
|
||||||
|
198
lib/open.c
198
lib/open.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -36,154 +38,154 @@ void
|
|||||||
glibtop_open_l (glibtop *server, const char *program_name,
|
glibtop_open_l (glibtop *server, const char *program_name,
|
||||||
const unsigned long features, const unsigned flags)
|
const unsigned long features, const unsigned flags)
|
||||||
{
|
{
|
||||||
int connect_type;
|
int connect_type;
|
||||||
|
|
||||||
if (!server->_priv)
|
if (!server->_priv)
|
||||||
server->_priv = glibtop_calloc_r
|
server->_priv = glibtop_calloc_r
|
||||||
(server, 1, sizeof (glibtop_server_private));
|
(server, 1, sizeof (glibtop_server_private));
|
||||||
|
|
||||||
server->name = program_name;
|
server->name = program_name;
|
||||||
|
|
||||||
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
|
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
|
||||||
* do recursive calls to glibtop_init_r (). */
|
* do recursive calls to glibtop_init_r (). */
|
||||||
|
|
||||||
server->flags |= _GLIBTOP_INIT_STATE_OPEN;
|
server->flags |= _GLIBTOP_INIT_STATE_OPEN;
|
||||||
|
|
||||||
server->error_method = GLIBTOP_ERROR_METHOD_DEFAULT;
|
server->error_method = GLIBTOP_ERROR_METHOD_DEFAULT;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "SIZEOF: %u - %u - %u - %u - %u - %u\n",
|
fprintf (stderr, "SIZEOF: %u - %u - %u - %u - %u - %u\n",
|
||||||
sizeof (glibtop_command), sizeof (glibtop_response),
|
sizeof (glibtop_command), sizeof (glibtop_response),
|
||||||
sizeof (glibtop_mountentry), sizeof (glibtop_union),
|
sizeof (glibtop_mountentry), sizeof (glibtop_union),
|
||||||
sizeof (glibtop_sysdeps), sizeof (glibtop_response_union));
|
sizeof (glibtop_sysdeps), sizeof (glibtop_response_union));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (server->method) {
|
switch (server->method) {
|
||||||
case GLIBTOP_METHOD_DIRECT:
|
case GLIBTOP_METHOD_DIRECT:
|
||||||
server->features = 0;
|
server->features = 0;
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_METHOD_INET:
|
case GLIBTOP_METHOD_INET:
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Connecting to '%s' port %ld.\n",
|
fprintf (stderr, "Connecting to '%s' port %ld.\n",
|
||||||
server->server_host, server->server_port);
|
server->server_host, server->server_port);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect_type = glibtop_make_connection
|
connect_type = glibtop_make_connection
|
||||||
(server->server_host, server->server_port,
|
(server->server_host, server->server_port,
|
||||||
&server->_priv->socket);
|
&server->_priv->socket);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
||||||
|
|
||||||
server->features = -1;
|
server->features = -1;
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_METHOD_UNIX:
|
case GLIBTOP_METHOD_UNIX:
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Connecting to Unix Domain Socket.\n");
|
fprintf (stderr, "Connecting to Unix Domain Socket.\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect_type = glibtop_make_connection
|
connect_type = glibtop_make_connection
|
||||||
("unix", 0, &server->_priv->socket);
|
("unix", 0, &server->_priv->socket);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
||||||
|
|
||||||
server->features = -1;
|
server->features = -1;
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_METHOD_PIPE:
|
case GLIBTOP_METHOD_PIPE:
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Opening pipe to server (%s).\n",
|
fprintf (stderr, "Opening pipe to server (%s).\n",
|
||||||
LIBGTOP_SERVER);
|
LIBGTOP_SERVER);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (pipe (server->_priv->input) ||
|
if (pipe (server->_priv->input) ||
|
||||||
pipe (server->_priv->output))
|
pipe (server->_priv->output))
|
||||||
glibtop_error_io_r (server, "cannot make a pipe");
|
glibtop_error_io_r (server, "cannot make a pipe");
|
||||||
|
|
||||||
server->_priv->pid = fork ();
|
server->_priv->pid = fork ();
|
||||||
|
|
||||||
if (server->_priv->pid < 0) {
|
if (server->_priv->pid < 0) {
|
||||||
glibtop_error_io_r (server, "fork failed");
|
glibtop_error_io_r (server, "fork failed");
|
||||||
} else if (server->_priv->pid == 0) {
|
} else if (server->_priv->pid == 0) {
|
||||||
close (0); close (1);
|
close (0); close (1);
|
||||||
close (server->_priv->input [0]);
|
close (server->_priv->input [0]);
|
||||||
close (server->_priv->output [1]);
|
close (server->_priv->output [1]);
|
||||||
dup2 (server->_priv->input [1], 1);
|
dup2 (server->_priv->input [1], 1);
|
||||||
dup2 (server->_priv->output [0], 0);
|
dup2 (server->_priv->output [0], 0);
|
||||||
execl (LIBGTOP_SERVER, "libgtop-server", NULL);
|
execl (LIBGTOP_SERVER, "libgtop-server", NULL);
|
||||||
glibtop_error_io_r (server, "execl (%s)",
|
glibtop_error_io_r (server, "execl (%s)",
|
||||||
LIBGTOP_SERVER);
|
LIBGTOP_SERVER);
|
||||||
_exit (2);
|
_exit (2);
|
||||||
}
|
|
||||||
|
|
||||||
close (server->_priv->input [1]);
|
|
||||||
close (server->_priv->output [0]);
|
|
||||||
|
|
||||||
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
|
||||||
|
|
||||||
server->features = -1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the server has been started, ask it for its features. */
|
close (server->_priv->input [1]);
|
||||||
|
close (server->_priv->output [0]);
|
||||||
|
|
||||||
if (server->flags & _GLIBTOP_INIT_STATE_SERVER) {
|
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
||||||
char version [BUFSIZ], buffer [BUFSIZ];
|
|
||||||
glibtop_sysdeps sysdeps;
|
|
||||||
size_t size, nbytes;
|
|
||||||
|
|
||||||
/* First check whether the server version is correct. */
|
server->features = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
sprintf (version, LIBGTOP_VERSION_STRING,
|
/* If the server has been started, ask it for its features. */
|
||||||
LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
|
|
||||||
sizeof (glibtop_command),
|
|
||||||
sizeof (glibtop_response),
|
|
||||||
sizeof (glibtop_union),
|
|
||||||
sizeof (glibtop_sysdeps));
|
|
||||||
|
|
||||||
size = strlen (version) + 1;
|
if (server->flags & _GLIBTOP_INIT_STATE_SERVER) {
|
||||||
|
char version [BUFSIZ], buffer [BUFSIZ];
|
||||||
|
glibtop_sysdeps sysdeps;
|
||||||
|
size_t size, nbytes;
|
||||||
|
|
||||||
glibtop_read_l (server, sizeof (nbytes), &nbytes);
|
/* First check whether the server version is correct. */
|
||||||
|
|
||||||
if (nbytes != size)
|
sprintf (version, LIBGTOP_VERSION_STRING,
|
||||||
glibtop_error_r (server,
|
LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
|
||||||
"Requested %u bytes but got %u.",
|
sizeof (glibtop_command),
|
||||||
size, nbytes);
|
sizeof (glibtop_response),
|
||||||
|
sizeof (glibtop_union),
|
||||||
|
sizeof (glibtop_sysdeps));
|
||||||
|
|
||||||
glibtop_read_l (server, nbytes, buffer);
|
size = strlen (version) + 1;
|
||||||
|
|
||||||
if (memcmp (version, buffer, size))
|
glibtop_read_l (server, sizeof (nbytes), &nbytes);
|
||||||
glibtop_error_r (server, "server version is not %s",
|
|
||||||
LIBGTOP_VERSION);
|
|
||||||
|
|
||||||
/* Now ask it for its features. */
|
if (nbytes != size)
|
||||||
|
glibtop_error_r (server,
|
||||||
|
"Requested %u bytes but got %u.",
|
||||||
|
size, nbytes);
|
||||||
|
|
||||||
glibtop_call_l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL,
|
glibtop_read_l (server, nbytes, buffer);
|
||||||
sizeof (glibtop_sysdeps), &sysdeps,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
server->features = sysdeps.features;
|
if (memcmp (version, buffer, size))
|
||||||
|
glibtop_error_r (server, "server version is not %s",
|
||||||
|
LIBGTOP_VERSION);
|
||||||
|
|
||||||
memcpy (&server->sysdeps, &sysdeps, sizeof (glibtop_sysdeps));
|
/* Now ask it for its features. */
|
||||||
|
|
||||||
|
glibtop_call_l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL,
|
||||||
|
sizeof (glibtop_sysdeps), &sysdeps,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
server->features = sysdeps.features;
|
||||||
|
|
||||||
|
memcpy (&server->sysdeps, &sysdeps, sizeof (glibtop_sysdeps));
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Server features are %lu.\n",
|
fprintf (stderr, "Server features are %lu.\n",
|
||||||
server->features);
|
server->features);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In any case, we call the open functions of our own sysdeps
|
/* In any case, we call the open functions of our own sysdeps
|
||||||
* directory. */
|
* directory. */
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Calling sysdeps open function.\n");
|
fprintf (stderr, "Calling sysdeps open function.\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glibtop_init_s (&server, features, flags);
|
glibtop_init_s (&server, features, flags);
|
||||||
}
|
}
|
||||||
|
192
lib/parameter.c
192
lib/parameter.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -46,113 +48,113 @@ ssize_t
|
|||||||
glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
|
glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
|
||||||
void *data_ptr, size_t data_size)
|
void *data_ptr, size_t data_size)
|
||||||
{
|
{
|
||||||
switch (parameter) {
|
switch (parameter) {
|
||||||
case GLIBTOP_PARAM_METHOD:
|
case GLIBTOP_PARAM_METHOD:
|
||||||
_write_data (&server->method,
|
_write_data (&server->method,
|
||||||
sizeof (server->method));
|
sizeof (server->method));
|
||||||
case GLIBTOP_PARAM_FEATURES:
|
case GLIBTOP_PARAM_FEATURES:
|
||||||
_write_data (&server->features,
|
_write_data (&server->features,
|
||||||
sizeof (server->features));
|
sizeof (server->features));
|
||||||
case GLIBTOP_PARAM_COMMAND:
|
case GLIBTOP_PARAM_COMMAND:
|
||||||
_write_data (server->server_command,
|
_write_data (server->server_command,
|
||||||
_strlen(server->server_command));
|
_strlen(server->server_command));
|
||||||
case GLIBTOP_PARAM_HOST:
|
case GLIBTOP_PARAM_HOST:
|
||||||
_write_data (server->server_host,
|
_write_data (server->server_host,
|
||||||
_strlen(server->server_host));
|
_strlen(server->server_host));
|
||||||
case GLIBTOP_PARAM_PORT:
|
case GLIBTOP_PARAM_PORT:
|
||||||
_write_data (&server->server_port,
|
_write_data (&server->server_port,
|
||||||
sizeof (server->server_port));
|
sizeof (server->server_port));
|
||||||
case GLIBTOP_PARAM_REMOTE_USER:
|
case GLIBTOP_PARAM_REMOTE_USER:
|
||||||
_write_data (server->server_user,
|
_write_data (server->server_user,
|
||||||
_strlen(server->server_user));
|
_strlen(server->server_user));
|
||||||
case GLIBTOP_PARAM_PATH_RSH:
|
case GLIBTOP_PARAM_PATH_RSH:
|
||||||
_write_data (server->server_rsh,
|
_write_data (server->server_rsh,
|
||||||
_strlen(server->server_rsh));
|
_strlen(server->server_rsh));
|
||||||
case GLIBTOP_PARAM_ERROR_METHOD:
|
case GLIBTOP_PARAM_ERROR_METHOD:
|
||||||
_write_data (&server->error_method,
|
_write_data (&server->error_method,
|
||||||
sizeof (server->error_method));
|
sizeof (server->error_method));
|
||||||
case GLIBTOP_PARAM_REQUIRED:
|
case GLIBTOP_PARAM_REQUIRED:
|
||||||
_write_data (&server->required,
|
_write_data (&server->required,
|
||||||
sizeof (server->required));
|
sizeof (server->required));
|
||||||
}
|
}
|
||||||
|
|
||||||
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
|
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
glibtop_get_parameter_size_l (glibtop *server, const unsigned parameter)
|
glibtop_get_parameter_size_l (glibtop *server, const unsigned parameter)
|
||||||
{
|
{
|
||||||
switch (parameter) {
|
switch (parameter) {
|
||||||
case GLIBTOP_PARAM_METHOD:
|
case GLIBTOP_PARAM_METHOD:
|
||||||
return sizeof (server->method);
|
return sizeof (server->method);
|
||||||
case GLIBTOP_PARAM_FEATURES:
|
case GLIBTOP_PARAM_FEATURES:
|
||||||
return sizeof (server->features);
|
return sizeof (server->features);
|
||||||
case GLIBTOP_PARAM_COMMAND:
|
case GLIBTOP_PARAM_COMMAND:
|
||||||
return _strlen(server->server_command);
|
return _strlen(server->server_command);
|
||||||
case GLIBTOP_PARAM_HOST:
|
case GLIBTOP_PARAM_HOST:
|
||||||
return _strlen(server->server_host);
|
return _strlen(server->server_host);
|
||||||
case GLIBTOP_PARAM_PORT:
|
case GLIBTOP_PARAM_PORT:
|
||||||
return sizeof (server->server_port);
|
return sizeof (server->server_port);
|
||||||
case GLIBTOP_PARAM_REMOTE_USER:
|
case GLIBTOP_PARAM_REMOTE_USER:
|
||||||
return _strlen(server->server_user);
|
return _strlen(server->server_user);
|
||||||
case GLIBTOP_PARAM_PATH_RSH:
|
case GLIBTOP_PARAM_PATH_RSH:
|
||||||
return _strlen(server->server_rsh);
|
return _strlen(server->server_rsh);
|
||||||
case GLIBTOP_PARAM_ERROR_METHOD:
|
case GLIBTOP_PARAM_ERROR_METHOD:
|
||||||
return sizeof (server->error_method);
|
return sizeof (server->error_method);
|
||||||
case GLIBTOP_PARAM_REQUIRED:
|
case GLIBTOP_PARAM_REQUIRED:
|
||||||
return sizeof (server->required);
|
return sizeof (server->required);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
|
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
|
glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
|
||||||
const void *data_ptr, size_t data_size)
|
const void *data_ptr, size_t data_size)
|
||||||
{
|
{
|
||||||
switch (parameter) {
|
switch (parameter) {
|
||||||
case GLIBTOP_PARAM_METHOD:
|
case GLIBTOP_PARAM_METHOD:
|
||||||
_check_data (sizeof (server->method));
|
_check_data (sizeof (server->method));
|
||||||
memcpy (&server->method, data_ptr, data_size);
|
memcpy (&server->method, data_ptr, data_size);
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_PARAM_FEATURES:
|
case GLIBTOP_PARAM_FEATURES:
|
||||||
return -GLIBTOP_ERROR_READONLY_VALUE;
|
return -GLIBTOP_ERROR_READONLY_VALUE;
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_PARAM_COMMAND:
|
case GLIBTOP_PARAM_COMMAND:
|
||||||
if (server->server_command)
|
if (server->server_command)
|
||||||
glibtop_free_r (server, server->server_command);
|
glibtop_free_r (server, server->server_command);
|
||||||
server->server_command = glibtop_strdup_r (server, data_ptr);
|
server->server_command = glibtop_strdup_r (server, data_ptr);
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_PARAM_HOST:
|
case GLIBTOP_PARAM_HOST:
|
||||||
if (server->server_host)
|
if (server->server_host)
|
||||||
glibtop_free_r (server, server->server_host);
|
glibtop_free_r (server, server->server_host);
|
||||||
server->server_host = glibtop_strdup_r (server, data_ptr);
|
server->server_host = glibtop_strdup_r (server, data_ptr);
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_PARAM_PORT:
|
case GLIBTOP_PARAM_PORT:
|
||||||
_check_data (sizeof (server->server_port));
|
_check_data (sizeof (server->server_port));
|
||||||
memcpy (&server->server_port, data_ptr, data_size);
|
memcpy (&server->server_port, data_ptr, data_size);
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_PARAM_REMOTE_USER:
|
case GLIBTOP_PARAM_REMOTE_USER:
|
||||||
if (server->server_user)
|
if (server->server_user)
|
||||||
glibtop_free_r (server, server->server_user);
|
glibtop_free_r (server, server->server_user);
|
||||||
server->server_user = glibtop_strdup_r (server, data_ptr);
|
server->server_user = glibtop_strdup_r (server, data_ptr);
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_PARAM_PATH_RSH:
|
case GLIBTOP_PARAM_PATH_RSH:
|
||||||
if (server->server_rsh)
|
if (server->server_rsh)
|
||||||
glibtop_free_r (server, server->server_rsh);
|
glibtop_free_r (server, server->server_rsh);
|
||||||
server->server_rsh = glibtop_strdup_r (server, data_ptr);
|
server->server_rsh = glibtop_strdup_r (server, data_ptr);
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_PARAM_ERROR_METHOD:
|
case GLIBTOP_PARAM_ERROR_METHOD:
|
||||||
_check_data (sizeof (server->error_method));
|
_check_data (sizeof (server->error_method));
|
||||||
memcpy (&server->error_method, data_ptr, data_size);
|
memcpy (&server->error_method, data_ptr, data_size);
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_PARAM_REQUIRED:
|
case GLIBTOP_PARAM_REQUIRED:
|
||||||
_check_data (sizeof (server->required));
|
_check_data (sizeof (server->required));
|
||||||
memcpy (&server->required, data_ptr, data_size);
|
memcpy (&server->required, data_ptr, data_size);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
|
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
64
lib/read.c
64
lib/read.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -28,49 +30,49 @@
|
|||||||
static void
|
static void
|
||||||
do_read (int s, void *ptr, size_t total_size)
|
do_read (int s, void *ptr, size_t total_size)
|
||||||
{
|
{
|
||||||
int nread;
|
int nread;
|
||||||
size_t already_read = 0, remaining = total_size;
|
size_t already_read = 0, remaining = total_size;
|
||||||
char *tmp_ptr;
|
char *tmp_ptr;
|
||||||
|
|
||||||
while (already_read < total_size) {
|
while (already_read < total_size) {
|
||||||
nread = recv (s, ptr, remaining, 0);
|
nread = recv (s, ptr, remaining, 0);
|
||||||
|
|
||||||
if (nread == 0) {
|
if (nread == 0) {
|
||||||
close (s);
|
close (s);
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (nread <= 0) {
|
|
||||||
glibtop_error_io ("recv");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
already_read += nread;
|
|
||||||
remaining -= nread;
|
|
||||||
/* (char *) ptr += nread; */
|
|
||||||
tmp_ptr = ptr;
|
|
||||||
tmp_ptr += nread;
|
|
||||||
ptr = tmp_ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nread <= 0) {
|
||||||
|
glibtop_error_io ("recv");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
already_read += nread;
|
||||||
|
remaining -= nread;
|
||||||
|
/* (char *) ptr += nread; */
|
||||||
|
tmp_ptr = ptr;
|
||||||
|
tmp_ptr += nread;
|
||||||
|
ptr = tmp_ptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_read_l (glibtop *server, size_t size, void *buf)
|
glibtop_read_l (glibtop *server, size_t size, void *buf)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
glibtop_init_r (&server, 0, 0);
|
glibtop_init_r (&server, 0, 0);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size);
|
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (server->_priv->socket) {
|
if (server->_priv->socket) {
|
||||||
do_read (server->_priv->socket, buf, size);
|
do_read (server->_priv->socket, buf, size);
|
||||||
} else {
|
} else {
|
||||||
ret = read (server->_priv->input [0], buf, size);
|
ret = read (server->_priv->input [0], buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
glibtop_error_io_r (server, _("read %d bytes"), size);
|
glibtop_error_io_r (server, _("read %d bytes"), size);
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -29,43 +31,43 @@
|
|||||||
void *
|
void *
|
||||||
glibtop_read_data_l (glibtop *server)
|
glibtop_read_data_l (glibtop *server)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
glibtop_init_r (&server, 0, 0);
|
glibtop_init_r (&server, 0, 0);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t));
|
fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (server->_priv->socket) {
|
if (server->_priv->socket) {
|
||||||
ret = recv (server->_priv->socket, (void *)&size,
|
ret = recv (server->_priv->socket, (void *)&size,
|
||||||
sizeof (size_t), 0);
|
sizeof (size_t), 0);
|
||||||
} else {
|
} else {
|
||||||
ret = read (server->_priv->input [0], (void *)&size,
|
ret = read (server->_priv->input [0], (void *)&size,
|
||||||
sizeof (size_t));
|
sizeof (size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
glibtop_error_io_r (server, _("read data size"));
|
glibtop_error_io_r (server, _("read data size"));
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "LIBRARY: really reading %d data bytes (ret = %d).\n", size, ret);
|
fprintf (stderr, "LIBRARY: really reading %d data bytes (ret = %d).\n", size, ret);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!size) return NULL;
|
if (!size) return NULL;
|
||||||
|
|
||||||
ptr = glibtop_malloc_r (server, size);
|
ptr = glibtop_malloc_r (server, size);
|
||||||
|
|
||||||
if (server->_priv->socket) {
|
if (server->_priv->socket) {
|
||||||
ret = recv (server->_priv->socket, ptr, size, 0);
|
ret = recv (server->_priv->socket, ptr, size, 0);
|
||||||
} else {
|
} else {
|
||||||
ret = read (server->_priv->input [0], ptr, size);
|
ret = read (server->_priv->input [0], ptr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
glibtop_error_io_r (server, _("read data %d bytes"));
|
glibtop_error_io_r (server, _("read data %d bytes"));
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
This file is part of LibGTop 1.0.
|
This file is part of LibGTop 1.0.
|
||||||
|
|
||||||
@@ -47,66 +49,66 @@ GLIBTOP_SUID_PPP;
|
|||||||
|
|
||||||
glibtop_init_func_t _glibtop_init_hook_s [] = {
|
glibtop_init_func_t _glibtop_init_hook_s [] = {
|
||||||
#if !GLIBTOP_SUID_CPU
|
#if !GLIBTOP_SUID_CPU
|
||||||
glibtop_init_cpu_s,
|
glibtop_init_cpu_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_MEM
|
#if !GLIBTOP_SUID_MEM
|
||||||
glibtop_init_mem_s,
|
glibtop_init_mem_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_SWAP
|
#if !GLIBTOP_SUID_SWAP
|
||||||
glibtop_init_swap_s,
|
glibtop_init_swap_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_UPTIME
|
#if !GLIBTOP_SUID_UPTIME
|
||||||
glibtop_init_uptime_s,
|
glibtop_init_uptime_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_LOADAVG
|
#if !GLIBTOP_SUID_LOADAVG
|
||||||
glibtop_init_loadavg_s,
|
glibtop_init_loadavg_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_SHM_LIMITS
|
#if !GLIBTOP_SUID_SHM_LIMITS
|
||||||
glibtop_init_shm_limits_s,
|
glibtop_init_shm_limits_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_MSG_LIMITS
|
#if !GLIBTOP_SUID_MSG_LIMITS
|
||||||
glibtop_init_msg_limits_s,
|
glibtop_init_msg_limits_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_SEM_LIMITS
|
#if !GLIBTOP_SUID_SEM_LIMITS
|
||||||
glibtop_init_sem_limits_s,
|
glibtop_init_sem_limits_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROCLIST
|
#if !GLIBTOP_SUID_PROCLIST
|
||||||
glibtop_init_proclist_s,
|
glibtop_init_proclist_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_STATE
|
#if !GLIBTOP_SUID_PROC_STATE
|
||||||
glibtop_init_proc_state_s,
|
glibtop_init_proc_state_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_UID
|
#if !GLIBTOP_SUID_PROC_UID
|
||||||
glibtop_init_proc_uid_s,
|
glibtop_init_proc_uid_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_MEM
|
#if !GLIBTOP_SUID_PROC_MEM
|
||||||
glibtop_init_proc_mem_s,
|
glibtop_init_proc_mem_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_TIME
|
#if !GLIBTOP_SUID_PROC_TIME
|
||||||
glibtop_init_proc_time_s,
|
glibtop_init_proc_time_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_SIGNAL
|
#if !GLIBTOP_SUID_PROC_SIGNAL
|
||||||
glibtop_init_proc_signal_s,
|
glibtop_init_proc_signal_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_KERNEL
|
#if !GLIBTOP_SUID_PROC_KERNEL
|
||||||
glibtop_init_proc_kernel_s,
|
glibtop_init_proc_kernel_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_SEGMENT
|
#if !GLIBTOP_SUID_PROC_SEGMENT
|
||||||
glibtop_init_proc_segment_s,
|
glibtop_init_proc_segment_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_ARGS
|
#if !GLIBTOP_SUID_PROC_ARGS
|
||||||
glibtop_init_proc_args_s,
|
glibtop_init_proc_args_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PROC_MAP
|
#if !GLIBTOP_SUID_PROC_MAP
|
||||||
glibtop_init_proc_map_s,
|
glibtop_init_proc_map_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_NETLOAD
|
#if !GLIBTOP_SUID_NETLOAD
|
||||||
glibtop_init_netload_s,
|
glibtop_init_netload_s,
|
||||||
#endif
|
#endif
|
||||||
#if !GLIBTOP_SUID_PPP
|
#if !GLIBTOP_SUID_PPP
|
||||||
glibtop_init_ppp_s,
|
glibtop_init_ppp_s,
|
||||||
#endif
|
#endif
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Checks which features are implemented. */
|
/* Checks which features are implemented. */
|
||||||
@@ -114,5 +116,5 @@ glibtop_init_func_t _glibtop_init_hook_s [] = {
|
|||||||
void
|
void
|
||||||
glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf)
|
glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf)
|
||||||
{
|
{
|
||||||
memcpy (buf, &server->sysdeps, sizeof (glibtop_sysdeps));
|
memcpy (buf, &server->sysdeps, sizeof (glibtop_sysdeps));
|
||||||
}
|
}
|
||||||
|
24
lib/write.c
24
lib/write.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -28,22 +30,22 @@
|
|||||||
void
|
void
|
||||||
glibtop_write_l (glibtop *server, size_t size, void *buf)
|
glibtop_write_l (glibtop *server, size_t size, void *buf)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
glibtop_init_r (&server, 0, 0);
|
glibtop_init_r (&server, 0, 0);
|
||||||
|
|
||||||
if (size == 0) return;
|
if (size == 0) return;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size);
|
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (server->_priv->socket) {
|
if (server->_priv->socket) {
|
||||||
ret = send (server->_priv->socket, buf, size, 0);
|
ret = send (server->_priv->socket, buf, size, 0);
|
||||||
} else {
|
} else {
|
||||||
ret = write (server->_priv->output [1], buf, size);
|
ret = write (server->_priv->output [1], buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
glibtop_error_io_r (server, _("write %d bytes"), size);
|
glibtop_error_io_r (server, _("write %d bytes"), size);
|
||||||
}
|
}
|
||||||
|
8
misc/README.indent
Normal file
8
misc/README.indent
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
The indentation in LibGTop was done with the following command:
|
||||||
|
|
||||||
|
find . -name \*.[ch] | xargs -i emacs -batch {} \
|
||||||
|
-l /gnome/compile/libgtop/misc/format.el -f save-buffer
|
||||||
|
|
||||||
|
December 26, 1999
|
||||||
|
Martin
|
||||||
|
|
5
misc/format.el
Normal file
5
misc/format.el
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
(setq c-basic-offset 4)
|
||||||
|
(if (not (word-search-forward "Mode: C" nil t))
|
||||||
|
(insert-string "/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */\n\n"))
|
||||||
|
(mark-whole-buffer)
|
||||||
|
(indent-region (region-beginning) (region-end) nil)
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* -*-C-*-
|
/* -*-C-*-
|
||||||
* Server code for handling requests from clients and forwarding them
|
* Server code for handling requests from clients and forwarding them
|
||||||
* on to the GNU Emacs process.
|
* on to the GNU Emacs process.
|
||||||
|
116
src/daemon/io.c
116
src/daemon/io.c
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -28,80 +30,80 @@ do_output (int s, glibtop_response *resp, off_t offset,
|
|||||||
size_t data_size, const void *data, int retval)
|
size_t data_size, const void *data, int retval)
|
||||||
{
|
{
|
||||||
#ifdef REAL_DEBUG
|
#ifdef REAL_DEBUG
|
||||||
fprintf (stderr, "Really writing %d bytes at offset %lu.\n",
|
fprintf (stderr, "Really writing %d bytes at offset %lu.\n",
|
||||||
sizeof (glibtop_response), offset);
|
sizeof (glibtop_response), offset);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
resp->offset = offset;
|
resp->offset = offset;
|
||||||
resp->data_size = data_size;
|
resp->data_size = data_size;
|
||||||
|
|
||||||
if (s == 0) {
|
if (s == 0) {
|
||||||
if (write (1, (const void *) resp, sizeof (glibtop_response)) < 0)
|
if (write (1, (const void *) resp, sizeof (glibtop_response)) < 0)
|
||||||
glibtop_warn_io ("write");
|
glibtop_warn_io ("write");
|
||||||
} else {
|
} else {
|
||||||
if (send (s, (const void *) resp, sizeof (glibtop_response), 0) < 0)
|
if (send (s, (const void *) resp, sizeof (glibtop_response), 0) < 0)
|
||||||
glibtop_warn_io ("send");
|
glibtop_warn_io ("send");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (s == 0) {
|
if (s == 0) {
|
||||||
if (write (1, &retval, sizeof (int)) < 0)
|
if (write (1, &retval, sizeof (int)) < 0)
|
||||||
glibtop_warn_io ("write retval");
|
glibtop_warn_io ("write retval");
|
||||||
} else {
|
} else {
|
||||||
if (send (s, &retval, sizeof (int), 0) < 0)
|
if (send (s, &retval, sizeof (int), 0) < 0)
|
||||||
glibtop_warn_io ("send retval");
|
glibtop_warn_io ("send retval");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp->data_size) {
|
if (resp->data_size) {
|
||||||
#ifdef REAL_DEBUG
|
#ifdef REAL_DEBUG
|
||||||
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
|
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (s == 0) {
|
if (s == 0) {
|
||||||
if (write (1, data, resp->data_size) < 0)
|
if (write (1, data, resp->data_size) < 0)
|
||||||
glibtop_warn_io ("write");
|
glibtop_warn_io ("write");
|
||||||
} else {
|
} else {
|
||||||
if (send (s, data, resp->data_size, 0) < 0)
|
if (send (s, data, resp->data_size, 0) < 0)
|
||||||
glibtop_warn_io ("send");
|
glibtop_warn_io ("send");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
do_read (int s, void *ptr, size_t total_size)
|
do_read (int s, void *ptr, size_t total_size)
|
||||||
{
|
{
|
||||||
int nread;
|
int nread;
|
||||||
char *tmp_ptr;
|
char *tmp_ptr;
|
||||||
size_t already_read = 0, remaining = total_size;
|
size_t already_read = 0, remaining = total_size;
|
||||||
|
|
||||||
while (already_read < total_size) {
|
while (already_read < total_size) {
|
||||||
if (s)
|
if (s)
|
||||||
nread = recv (s, ptr, remaining, 0);
|
nread = recv (s, ptr, remaining, 0);
|
||||||
else
|
else
|
||||||
nread = read (0, ptr, remaining);
|
nread = read (0, ptr, remaining);
|
||||||
|
|
||||||
if ((already_read == 0) && (nread == 0)) {
|
if ((already_read == 0) && (nread == 0)) {
|
||||||
glibtop_warn ("pid %d received eof.", getpid ());
|
glibtop_warn ("pid %d received eof.", getpid ());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (nread <= 0) {
|
|
||||||
glibtop_warn_io ("recv");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
already_read += nread;
|
|
||||||
remaining -= nread;
|
|
||||||
/* (char *) ptr += nread; */
|
|
||||||
tmp_ptr = ptr;
|
|
||||||
tmp_ptr += nread;
|
|
||||||
ptr = tmp_ptr;
|
|
||||||
|
|
||||||
#ifdef REAL_DEBUG
|
|
||||||
fprintf (stderr, "READ (%d): %d - %d - %d\n",
|
|
||||||
nread, already_read, remaining, total_size);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return already_read;
|
if (nread <= 0) {
|
||||||
|
glibtop_warn_io ("recv");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
already_read += nread;
|
||||||
|
remaining -= nread;
|
||||||
|
/* (char *) ptr += nread; */
|
||||||
|
tmp_ptr = ptr;
|
||||||
|
tmp_ptr += nread;
|
||||||
|
ptr = tmp_ptr;
|
||||||
|
|
||||||
|
#ifdef REAL_DEBUG
|
||||||
|
fprintf (stderr, "READ (%d): %d - %d - %d\n",
|
||||||
|
nread, already_read, remaining, total_size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return already_read;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -62,35 +64,35 @@ GLIBTOP_SUID_PPP;
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct utsname uts;
|
struct utsname uts;
|
||||||
int uid, euid, gid, egid;
|
int uid, euid, gid, egid;
|
||||||
|
|
||||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||||
|
|
||||||
uid = getuid (); euid = geteuid ();
|
uid = getuid (); euid = geteuid ();
|
||||||
gid = getgid (); egid = getegid ();
|
gid = getgid (); egid = getegid ();
|
||||||
|
|
||||||
if (uname (&uts) < 0) _exit (1);
|
if (uname (&uts) < 0) _exit (1);
|
||||||
|
|
||||||
if (strcmp (uts.sysname, LIBGTOP_COMPILE_SYSTEM) ||
|
if (strcmp (uts.sysname, LIBGTOP_COMPILE_SYSTEM) ||
|
||||||
strcmp (uts.release, LIBGTOP_COMPILE_RELEASE) ||
|
strcmp (uts.release, LIBGTOP_COMPILE_RELEASE) ||
|
||||||
strcmp (uts.machine, LIBGTOP_COMPILE_MACHINE)) {
|
strcmp (uts.machine, LIBGTOP_COMPILE_MACHINE)) {
|
||||||
fprintf (stderr, "Can only run on %s %s %s\n",
|
fprintf (stderr, "Can only run on %s %s %s\n",
|
||||||
LIBGTOP_COMPILE_SYSTEM,
|
LIBGTOP_COMPILE_SYSTEM,
|
||||||
LIBGTOP_COMPILE_RELEASE,
|
LIBGTOP_COMPILE_RELEASE,
|
||||||
LIBGTOP_COMPILE_MACHINE);
|
LIBGTOP_COMPILE_MACHINE);
|
||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glibtop_init_p (glibtop_global_server, 0, 0);
|
glibtop_init_p (glibtop_global_server, 0, 0);
|
||||||
|
|
||||||
if (setreuid (euid, uid)) _exit (1);
|
if (setreuid (euid, uid)) _exit (1);
|
||||||
|
|
||||||
if (setregid (egid, gid)) _exit (1);
|
if (setregid (egid, gid)) _exit (1);
|
||||||
|
|
||||||
/* !!! END OF SUID ROOT PART !!! */
|
/* !!! END OF SUID ROOT PART !!! */
|
||||||
|
|
||||||
handle_slave_connection (0, 0);
|
handle_slave_connection (0, 0);
|
||||||
|
|
||||||
_exit (0);
|
_exit (0);
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -26,269 +28,269 @@
|
|||||||
void
|
void
|
||||||
handle_slave_connection (int input, int output)
|
handle_slave_connection (int input, int output)
|
||||||
{
|
{
|
||||||
glibtop *server G_GNUC_UNUSED = glibtop_global_server;
|
glibtop *server G_GNUC_UNUSED = glibtop_global_server;
|
||||||
int64_t *param_ptr G_GNUC_UNUSED;
|
int64_t *param_ptr G_GNUC_UNUSED;
|
||||||
const void *ptr G_GNUC_UNUSED;
|
const void *ptr G_GNUC_UNUSED;
|
||||||
int ret G_GNUC_UNUSED = -1;
|
int ret G_GNUC_UNUSED = -1;
|
||||||
|
|
||||||
u_int64_t interface G_GNUC_UNUSED;
|
u_int64_t interface G_GNUC_UNUSED;
|
||||||
u_int64_t number G_GNUC_UNUSED;
|
u_int64_t number G_GNUC_UNUSED;
|
||||||
u_int64_t instance G_GNUC_UNUSED;
|
u_int64_t instance G_GNUC_UNUSED;
|
||||||
u_int64_t strategy G_GNUC_UNUSED;
|
u_int64_t strategy G_GNUC_UNUSED;
|
||||||
u_int64_t transport G_GNUC_UNUSED;
|
u_int64_t transport G_GNUC_UNUSED;
|
||||||
u_int64_t protocol G_GNUC_UNUSED;
|
u_int64_t protocol G_GNUC_UNUSED;
|
||||||
|
|
||||||
unsigned short max_len G_GNUC_UNUSED;
|
unsigned short max_len G_GNUC_UNUSED;
|
||||||
pid_t pid G_GNUC_UNUSED;
|
pid_t pid G_GNUC_UNUSED;
|
||||||
|
|
||||||
glibtop_response _resp, *resp = &_resp;
|
glibtop_response _resp, *resp = &_resp;
|
||||||
glibtop_command _cmnd, *cmnd = &_cmnd;
|
glibtop_command _cmnd, *cmnd = &_cmnd;
|
||||||
char parameter [BUFSIZ];
|
char parameter [BUFSIZ];
|
||||||
|
|
||||||
glibtop_send_version (glibtop_global_server, output);
|
glibtop_send_version (glibtop_global_server, output);
|
||||||
|
|
||||||
while (do_read (input, cmnd, sizeof (glibtop_command))) {
|
while (do_read (input, cmnd, sizeof (glibtop_command))) {
|
||||||
#ifdef SLAVE_DEBUG
|
#ifdef SLAVE_DEBUG
|
||||||
fprintf (stderr, "Slave %d received command "
|
fprintf (stderr, "Slave %d received command "
|
||||||
"%d from client.\n", getpid (), cmnd->command);
|
"%d from client.\n", getpid (), cmnd->command);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (cmnd->data_size >= BUFSIZ)
|
if (cmnd->data_size >= BUFSIZ)
|
||||||
glibtop_error ("Client sent %d bytes, "
|
glibtop_error ("Client sent %d bytes, "
|
||||||
"but buffer is %d",
|
"but buffer is %d",
|
||||||
cmnd->size, BUFSIZ);
|
cmnd->size, BUFSIZ);
|
||||||
|
|
||||||
memset (resp, 0, sizeof (glibtop_response));
|
memset (resp, 0, sizeof (glibtop_response));
|
||||||
|
|
||||||
memset (parameter, 0, sizeof (parameter));
|
memset (parameter, 0, sizeof (parameter));
|
||||||
|
|
||||||
if (cmnd->data_size) {
|
if (cmnd->data_size) {
|
||||||
#ifdef SLAVE_DEBUG
|
#ifdef SLAVE_DEBUG
|
||||||
fprintf (stderr, "Client has %d bytes of data.\n",
|
fprintf (stderr, "Client has %d bytes of data.\n",
|
||||||
cmnd->data_size);
|
cmnd->data_size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
do_read (input, parameter, cmnd->data_size);
|
do_read (input, parameter, cmnd->data_size);
|
||||||
|
|
||||||
} else if (cmnd->size) {
|
} else if (cmnd->size) {
|
||||||
memcpy (parameter, cmnd->parameter, cmnd->size);
|
memcpy (parameter, cmnd->parameter, cmnd->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cmnd->command) {
|
switch (cmnd->command) {
|
||||||
case GLIBTOP_CMND_QUIT:
|
case GLIBTOP_CMND_QUIT:
|
||||||
do_output (output, resp, 0, 0, NULL, 0);
|
do_output (output, resp, 0, 0, NULL, 0);
|
||||||
return;
|
return;
|
||||||
#if GLIBTOP_SUID_PROCLIST
|
#if GLIBTOP_SUID_PROCLIST
|
||||||
case GLIBTOP_CMND_PROCLIST:
|
case GLIBTOP_CMND_PROCLIST:
|
||||||
param_ptr = (int64_t *) parameter;
|
param_ptr = (int64_t *) parameter;
|
||||||
ptr = glibtop_get_proclist_p
|
ptr = glibtop_get_proclist_p
|
||||||
(server, &resp->u.data.proclist,
|
(server, &resp->u.data.proclist,
|
||||||
param_ptr [0], param_ptr [1]);
|
param_ptr [0], param_ptr [1]);
|
||||||
do_output (output, resp, _offset_data (proclist),
|
do_output (output, resp, _offset_data (proclist),
|
||||||
resp->u.data.proclist.total,
|
resp->u.data.proclist.total,
|
||||||
ptr, (ptr != NULL) ? 0 : -1);
|
ptr, (ptr != NULL) ? 0 : -1);
|
||||||
glibtop_free_r (server, ptr);
|
glibtop_free_r (server, ptr);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_ARGS
|
#if GLIBTOP_SUID_PROC_ARGS
|
||||||
case GLIBTOP_CMND_PROC_ARGS:
|
case GLIBTOP_CMND_PROC_ARGS:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
memcpy (&max_len, parameter + sizeof (pid_t),
|
memcpy (&max_len, parameter + sizeof (pid_t),
|
||||||
sizeof (max_len));
|
sizeof (max_len));
|
||||||
ptr = glibtop_get_proc_args_p (server,
|
ptr = glibtop_get_proc_args_p (server,
|
||||||
&resp->u.data.proc_args,
|
&resp->u.data.proc_args,
|
||||||
pid);
|
pid);
|
||||||
do_output (output, resp, _offset_data (proc_args),
|
do_output (output, resp, _offset_data (proc_args),
|
||||||
ptr ? resp->u.data.proc_args.size+1 : 0,
|
ptr ? resp->u.data.proc_args.size+1 : 0,
|
||||||
ptr, (ptr != NULL) ? 0 : -1);
|
ptr, (ptr != NULL) ? 0 : -1);
|
||||||
glibtop_free_r (server, ptr);
|
glibtop_free_r (server, ptr);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_MAP
|
#if GLIBTOP_SUID_PROC_MAP
|
||||||
case GLIBTOP_CMND_PROC_MAP:
|
case GLIBTOP_CMND_PROC_MAP:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
ptr = glibtop_get_proc_map_p (server,
|
ptr = glibtop_get_proc_map_p (server,
|
||||||
&resp->u.data.proc_map,
|
&resp->u.data.proc_map,
|
||||||
pid);
|
pid);
|
||||||
do_output (output, resp, _offset_data (proc_map),
|
do_output (output, resp, _offset_data (proc_map),
|
||||||
resp->u.data.proc_map.total,
|
resp->u.data.proc_map.total,
|
||||||
ptr, (ptr != NULL) ? 0 : -1);
|
ptr, (ptr != NULL) ? 0 : -1);
|
||||||
glibtop_free_r (server, ptr);
|
glibtop_free_r (server, ptr);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_INTERFACE_NAMES
|
#if GLIBTOP_SUID_INTERFACE_NAMES
|
||||||
case GLIBTOP_CMND_INTERFACE_NAMES:
|
case GLIBTOP_CMND_INTERFACE_NAMES:
|
||||||
memcpy (&interface, parameter, sizeof (u_int64_t));
|
memcpy (&interface, parameter, sizeof (u_int64_t));
|
||||||
memcpy (&number, parameter + sizeof (u_int64_t),
|
memcpy (&number, parameter + sizeof (u_int64_t),
|
||||||
sizeof (u_int64_t));
|
sizeof (u_int64_t));
|
||||||
memcpy (&instance, parameter + 2 * sizeof (u_int64_t),
|
memcpy (&instance, parameter + 2 * sizeof (u_int64_t),
|
||||||
sizeof (u_int64_t));
|
sizeof (u_int64_t));
|
||||||
memcpy (&strategy, parameter + 3 * sizeof (u_int64_t),
|
memcpy (&strategy, parameter + 3 * sizeof (u_int64_t),
|
||||||
sizeof (u_int64_t));
|
sizeof (u_int64_t));
|
||||||
ptr = glibtop_get_interface_names_p
|
ptr = glibtop_get_interface_names_p
|
||||||
(server, &resp->u.data.interface_names,
|
(server, &resp->u.data.interface_names,
|
||||||
interface, number, instance, strategy);
|
interface, number, instance, strategy);
|
||||||
do_output (output, resp, _offset_data (interface_names),
|
do_output (output, resp, _offset_data (interface_names),
|
||||||
ptr ? resp->u.data.interface_names.size+1 : 0,
|
ptr ? resp->u.data.interface_names.size+1 : 0,
|
||||||
ptr, (ptr != NULL) ? 0 : -1);
|
ptr, (ptr != NULL) ? 0 : -1);
|
||||||
glibtop_free_r (server, ptr);
|
glibtop_free_r (server, ptr);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ret = handle_slave_command (cmnd, resp, parameter);
|
ret = handle_slave_command (cmnd, resp, parameter);
|
||||||
do_output (output, resp, resp->offset, 0, NULL, ret);
|
do_output (output, resp, resp->offset, 0, NULL, ret);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,
|
handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,
|
||||||
const void *parameter)
|
const void *parameter)
|
||||||
{
|
{
|
||||||
glibtop *server = glibtop_global_server;
|
glibtop *server = glibtop_global_server;
|
||||||
unsigned device G_GNUC_UNUSED;
|
unsigned device G_GNUC_UNUSED;
|
||||||
pid_t pid G_GNUC_UNUSED;
|
pid_t pid G_GNUC_UNUSED;
|
||||||
int retval G_GNUC_UNUSED = -1;
|
int retval G_GNUC_UNUSED = -1;
|
||||||
|
|
||||||
switch (cmnd->command) {
|
switch (cmnd->command) {
|
||||||
case GLIBTOP_CMND_SYSDEPS:
|
case GLIBTOP_CMND_SYSDEPS:
|
||||||
memcpy (&resp->u.sysdeps, &server->sysdeps,
|
memcpy (&resp->u.sysdeps, &server->sysdeps,
|
||||||
sizeof (glibtop_sysdeps));
|
sizeof (glibtop_sysdeps));
|
||||||
resp->u.sysdeps.features = glibtop_server_features;
|
resp->u.sysdeps.features = glibtop_server_features;
|
||||||
resp->u.sysdeps.pointer_size = sizeof (void*)*8;
|
resp->u.sysdeps.pointer_size = sizeof (void*)*8;
|
||||||
resp->u.sysdeps.flags = glibtop_server_features;
|
resp->u.sysdeps.flags = glibtop_server_features;
|
||||||
resp->offset = _offset_union (sysdeps);
|
resp->offset = _offset_union (sysdeps);
|
||||||
retval = 0;
|
retval = 0;
|
||||||
break;
|
break;
|
||||||
#if GLIBTOP_SUID_CPU
|
#if GLIBTOP_SUID_CPU
|
||||||
case GLIBTOP_CMND_CPU:
|
case GLIBTOP_CMND_CPU:
|
||||||
retval = glibtop_get_cpu_p (server, &resp->u.data.cpu);
|
retval = glibtop_get_cpu_p (server, &resp->u.data.cpu);
|
||||||
resp->offset = _offset_data (cpu);
|
resp->offset = _offset_data (cpu);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_MEM
|
#if GLIBTOP_SUID_MEM
|
||||||
case GLIBTOP_CMND_MEM:
|
case GLIBTOP_CMND_MEM:
|
||||||
retval = glibtop_get_mem_p (server, &resp->u.data.mem);
|
retval = glibtop_get_mem_p (server, &resp->u.data.mem);
|
||||||
resp->offset = _offset_data (mem);
|
resp->offset = _offset_data (mem);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_SWAP
|
#if GLIBTOP_SUID_SWAP
|
||||||
case GLIBTOP_CMND_SWAP:
|
case GLIBTOP_CMND_SWAP:
|
||||||
retval = glibtop_get_swap_p (server, &resp->u.data.swap);
|
retval = glibtop_get_swap_p (server, &resp->u.data.swap);
|
||||||
resp->offset = _offset_data (swap);
|
resp->offset = _offset_data (swap);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_UPTIME
|
#if GLIBTOP_SUID_UPTIME
|
||||||
case GLIBTOP_CMND_UPTIME:
|
case GLIBTOP_CMND_UPTIME:
|
||||||
retval = glibtop_get_uptime_p (server, &resp->u.data.uptime);
|
retval = glibtop_get_uptime_p (server, &resp->u.data.uptime);
|
||||||
resp->offset = _offset_data (uptime);
|
resp->offset = _offset_data (uptime);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_LOADAVG
|
#if GLIBTOP_SUID_LOADAVG
|
||||||
case GLIBTOP_CMND_LOADAVG:
|
case GLIBTOP_CMND_LOADAVG:
|
||||||
retval = glibtop_get_loadavg_p (server, &resp->u.data.loadavg);
|
retval = glibtop_get_loadavg_p (server, &resp->u.data.loadavg);
|
||||||
resp->offset = _offset_data (loadavg);
|
resp->offset = _offset_data (loadavg);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_SHM_LIMITS
|
#if GLIBTOP_SUID_SHM_LIMITS
|
||||||
case GLIBTOP_CMND_SHM_LIMITS:
|
case GLIBTOP_CMND_SHM_LIMITS:
|
||||||
retval = glibtop_get_shm_limits_p (server, &resp->u.data.shm_limits);
|
retval = glibtop_get_shm_limits_p (server, &resp->u.data.shm_limits);
|
||||||
resp->offset = _offset_data (shm_limits);
|
resp->offset = _offset_data (shm_limits);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_MSG_LIMITS
|
#if GLIBTOP_SUID_MSG_LIMITS
|
||||||
case GLIBTOP_CMND_MSG_LIMITS:
|
case GLIBTOP_CMND_MSG_LIMITS:
|
||||||
retval = glibtop_get_msg_limits_p (server, &resp->u.data.msg_limits);
|
retval = glibtop_get_msg_limits_p (server, &resp->u.data.msg_limits);
|
||||||
resp->offset = _offset_data (msg_limits);
|
resp->offset = _offset_data (msg_limits);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_SEM_LIMITS
|
#if GLIBTOP_SUID_SEM_LIMITS
|
||||||
case GLIBTOP_CMND_SEM_LIMITS:
|
case GLIBTOP_CMND_SEM_LIMITS:
|
||||||
retval = glibtop_get_sem_limits_p (server, &resp->u.data.sem_limits);
|
retval = glibtop_get_sem_limits_p (server, &resp->u.data.sem_limits);
|
||||||
resp->offset = _offset_data (sem_limits);
|
resp->offset = _offset_data (sem_limits);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_STATE
|
#if GLIBTOP_SUID_PROC_STATE
|
||||||
case GLIBTOP_CMND_PROC_STATE:
|
case GLIBTOP_CMND_PROC_STATE:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
retval = glibtop_get_proc_state_p
|
retval = glibtop_get_proc_state_p
|
||||||
(server, &resp->u.data.proc_state, pid);
|
(server, &resp->u.data.proc_state, pid);
|
||||||
resp->offset = _offset_data (proc_state);
|
resp->offset = _offset_data (proc_state);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_UID
|
#if GLIBTOP_SUID_PROC_UID
|
||||||
case GLIBTOP_CMND_PROC_UID:
|
case GLIBTOP_CMND_PROC_UID:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
retval = glibtop_get_proc_uid_p
|
retval = glibtop_get_proc_uid_p
|
||||||
(server, &resp->u.data.proc_uid, pid);
|
(server, &resp->u.data.proc_uid, pid);
|
||||||
resp->offset = _offset_data (proc_uid);
|
resp->offset = _offset_data (proc_uid);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_MEM
|
#if GLIBTOP_SUID_PROC_MEM
|
||||||
case GLIBTOP_CMND_PROC_MEM:
|
case GLIBTOP_CMND_PROC_MEM:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
retval = glibtop_get_proc_mem_p
|
retval = glibtop_get_proc_mem_p
|
||||||
(server, &resp->u.data.proc_mem, pid);
|
(server, &resp->u.data.proc_mem, pid);
|
||||||
resp->offset = _offset_data (proc_mem);
|
resp->offset = _offset_data (proc_mem);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_TIME
|
#if GLIBTOP_SUID_PROC_TIME
|
||||||
case GLIBTOP_CMND_PROC_TIME:
|
case GLIBTOP_CMND_PROC_TIME:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
retval = glibtop_get_proc_time_p
|
retval = glibtop_get_proc_time_p
|
||||||
(server, &resp->u.data.proc_time, pid);
|
(server, &resp->u.data.proc_time, pid);
|
||||||
resp->offset = _offset_data (proc_time);
|
resp->offset = _offset_data (proc_time);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_SIGNAL
|
#if GLIBTOP_SUID_PROC_SIGNAL
|
||||||
case GLIBTOP_CMND_PROC_SIGNAL:
|
case GLIBTOP_CMND_PROC_SIGNAL:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
retval = glibtop_get_proc_signal_p
|
retval = glibtop_get_proc_signal_p
|
||||||
(server, &resp->u.data.proc_signal, pid);
|
(server, &resp->u.data.proc_signal, pid);
|
||||||
resp->offset = _offset_data (proc_signal);
|
resp->offset = _offset_data (proc_signal);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_KERNEL
|
#if GLIBTOP_SUID_PROC_KERNEL
|
||||||
case GLIBTOP_CMND_PROC_KERNEL:
|
case GLIBTOP_CMND_PROC_KERNEL:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
retval = glibtop_get_proc_kernel_p
|
retval = glibtop_get_proc_kernel_p
|
||||||
(server, &resp->u.data.proc_kernel, pid);
|
(server, &resp->u.data.proc_kernel, pid);
|
||||||
resp->offset = _offset_data (proc_kernel);
|
resp->offset = _offset_data (proc_kernel);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_SEGMENT
|
#if GLIBTOP_SUID_PROC_SEGMENT
|
||||||
case GLIBTOP_CMND_PROC_SEGMENT:
|
case GLIBTOP_CMND_PROC_SEGMENT:
|
||||||
memcpy (&pid, parameter, sizeof (pid_t));
|
memcpy (&pid, parameter, sizeof (pid_t));
|
||||||
retval = glibtop_get_proc_segment_p
|
retval = glibtop_get_proc_segment_p
|
||||||
(server, &resp->u.data.proc_segment, pid);
|
(server, &resp->u.data.proc_segment, pid);
|
||||||
resp->offset = _offset_data (proc_segment);
|
resp->offset = _offset_data (proc_segment);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_NETINFO
|
#if GLIBTOP_SUID_NETINFO
|
||||||
case GLIBTOP_CMND_NETINFO:
|
case GLIBTOP_CMND_NETINFO:
|
||||||
retval = glibtop_get_netinfo_p (server, &resp->u.data.netinfo, parameter, 0);
|
retval = glibtop_get_netinfo_p (server, &resp->u.data.netinfo, parameter, 0);
|
||||||
resp->offset = _offset_data (netload);
|
resp->offset = _offset_data (netload);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_NETLOAD
|
#if GLIBTOP_SUID_NETLOAD
|
||||||
case GLIBTOP_CMND_NETLOAD:
|
case GLIBTOP_CMND_NETLOAD:
|
||||||
retval = glibtop_get_netload_p (server, &resp->u.data.netload, parameter, 0, 0);
|
retval = glibtop_get_netload_p (server, &resp->u.data.netload, parameter, 0, 0);
|
||||||
resp->offset = _offset_data (netload);
|
resp->offset = _offset_data (netload);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PPP
|
#if GLIBTOP_SUID_PPP
|
||||||
case GLIBTOP_CMND_PPP:
|
case GLIBTOP_CMND_PPP:
|
||||||
memcpy (&device, parameter, sizeof (unsigned short));
|
memcpy (&device, parameter, sizeof (unsigned short));
|
||||||
retval = glibtop_get_ppp_p (server, &resp->u.data.ppp, device);
|
retval = glibtop_get_ppp_p (server, &resp->u.data.ppp, device);
|
||||||
resp->offset = _offset_data (ppp);
|
resp->offset = _offset_data (ppp);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
glibtop_error ("Child received unknown command %u",
|
glibtop_error ("Child received unknown command %u",
|
||||||
cmnd->command);
|
cmnd->command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -28,35 +30,35 @@
|
|||||||
void
|
void
|
||||||
glibtop_send_version (glibtop *server, int fd)
|
glibtop_send_version (glibtop *server, int fd)
|
||||||
{
|
{
|
||||||
char buffer [BUFSIZ];
|
char buffer [BUFSIZ];
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
sprintf (buffer, LIBGTOP_VERSION_STRING,
|
sprintf (buffer, LIBGTOP_VERSION_STRING,
|
||||||
LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
|
LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
|
||||||
sizeof (glibtop_command),
|
sizeof (glibtop_command),
|
||||||
sizeof (glibtop_response),
|
sizeof (glibtop_response),
|
||||||
sizeof (glibtop_union),
|
sizeof (glibtop_union),
|
||||||
sizeof (glibtop_sysdeps));
|
sizeof (glibtop_sysdeps));
|
||||||
|
|
||||||
size = strlen (buffer) + 1;
|
size = strlen (buffer) + 1;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "SERVER ID: |%s|\n", buffer);
|
fprintf (stderr, "SERVER ID: |%s|\n", buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fd == 0) {
|
if (fd == 0) {
|
||||||
if (write (1, (const void *) &size, sizeof (size)) < 0)
|
if (write (1, (const void *) &size, sizeof (size)) < 0)
|
||||||
glibtop_warn_io_r (server, "write");
|
glibtop_warn_io_r (server, "write");
|
||||||
} else {
|
} else {
|
||||||
if (send (fd, (const void *) &size, sizeof (size), 0) < 0)
|
if (send (fd, (const void *) &size, sizeof (size), 0) < 0)
|
||||||
glibtop_warn_io_r (server, "send");
|
glibtop_warn_io_r (server, "send");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd == 0) {
|
if (fd == 0) {
|
||||||
if (write (1, (const void *) buffer, size) < 0)
|
if (write (1, (const void *) buffer, size) < 0)
|
||||||
glibtop_warn_io_r (server, "write");
|
glibtop_warn_io_r (server, "write");
|
||||||
} else {
|
} else {
|
||||||
if (send (fd, (const void *) buffer, size, 0) < 0)
|
if (send (fd, (const void *) buffer, size, 0) < 0)
|
||||||
glibtop_warn_io_r (server, "send");
|
glibtop_warn_io_r (server, "send");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -33,33 +35,33 @@
|
|||||||
int
|
int
|
||||||
main (int argc, const char *argv [])
|
main (int argc, const char *argv [])
|
||||||
{
|
{
|
||||||
glibtop_inodedb *inodedb;
|
glibtop_inodedb *inodedb;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
unsigned device, inode;
|
unsigned device, inode;
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
fprintf (stderr, "Usage: %s device inode\n", argv [0]);
|
fprintf (stderr, "Usage: %s device inode\n", argv [0]);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf (argv [1], "%d", &device) != 1) {
|
if (sscanf (argv [1], "%d", &device) != 1) {
|
||||||
fprintf (stderr, "Usage: %s device inode\n", argv [0]);
|
fprintf (stderr, "Usage: %s device inode\n", argv [0]);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf (argv [2], "%d", &inode) != 1) {
|
if (sscanf (argv [2], "%d", &inode) != 1) {
|
||||||
fprintf (stderr, "Usage: %s device inode\n", argv [0]);
|
fprintf (stderr, "Usage: %s device inode\n", argv [0]);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inodedb = glibtop_inodedb_open (0, 0);
|
inodedb = glibtop_inodedb_open (0, 0);
|
||||||
if (!inodedb) exit (1);
|
if (!inodedb) exit (1);
|
||||||
|
|
||||||
filename = glibtop_inodedb_lookup (inodedb, device, inode);
|
filename = glibtop_inodedb_lookup (inodedb, device, inode);
|
||||||
if (!filename) exit (2);
|
if (!filename) exit (2);
|
||||||
|
|
||||||
fprintf (stderr, "FILENAME: %d - %d - '%s'\n",
|
fprintf (stderr, "FILENAME: %d - %d - '%s'\n",
|
||||||
(int) device, (int) inode, filename);
|
(int) device, (int) inode, filename);
|
||||||
|
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -33,103 +35,103 @@
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv [])
|
main (int argc, char *argv [])
|
||||||
{
|
{
|
||||||
GDBM_FILE dbf;
|
GDBM_FILE dbf;
|
||||||
char dirname [BUFSIZ];
|
char dirname [BUFSIZ];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
fprintf (stderr, "Usage: %s database filename\n", argv [0]);
|
fprintf (stderr, "Usage: %s database filename\n", argv [0]);
|
||||||
exit (1);
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
f = fopen (argv [2], "rt");
|
||||||
|
if (!f)
|
||||||
|
glibtop_error_io ("fopen (%s)", argv [2]);
|
||||||
|
|
||||||
|
dbf = gdbm_open (argv [1], 512, GDBM_WRCREAT, 0600, 0);
|
||||||
|
if (!dbf)
|
||||||
|
glibtop_error_io ("gdbm_open (%s)", argv [1]);
|
||||||
|
|
||||||
|
while (fgets (dirname, BUFSIZ-1, f)) {
|
||||||
|
struct dirent *entry;
|
||||||
|
struct stat statb;
|
||||||
|
DIR *directory;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = strlen (dirname);
|
||||||
|
if (!len) continue;
|
||||||
|
|
||||||
|
if (dirname [len-1] == '\n')
|
||||||
|
dirname [len-1] = 0;
|
||||||
|
|
||||||
|
if (stat (dirname, &statb))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (S_ISREG (statb.st_mode)) {
|
||||||
|
glibtop_inodedb_key key;
|
||||||
|
datum d_key, d_content;
|
||||||
|
|
||||||
|
d_key.dptr = (void *) &key;
|
||||||
|
d_key.dsize = sizeof (key);
|
||||||
|
|
||||||
|
d_content.dptr = dirname;
|
||||||
|
d_content.dsize = strlen (dirname) + 1;
|
||||||
|
|
||||||
|
key.device = (u_int64_t) statb.st_dev;
|
||||||
|
key.inode = (u_int64_t) statb.st_ino;
|
||||||
|
|
||||||
|
if (gdbm_store (dbf, d_key, d_content, GDBM_REPLACE))
|
||||||
|
glibtop_error_io ("gdbm_store (%s)", dirname);
|
||||||
|
|
||||||
|
printf ("%-52s - %8lu - %8lu\n",
|
||||||
|
dirname, (unsigned long) statb.st_dev,
|
||||||
|
(unsigned long) statb.st_ino);
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
f = fopen (argv [2], "rt");
|
if (!S_ISDIR (statb.st_mode))
|
||||||
if (!f)
|
continue;
|
||||||
glibtop_error_io ("fopen (%s)", argv [2]);
|
|
||||||
|
|
||||||
dbf = gdbm_open (argv [1], 512, GDBM_WRCREAT, 0600, 0);
|
directory = opendir (dirname);
|
||||||
if (!dbf)
|
if (!directory) continue;
|
||||||
glibtop_error_io ("gdbm_open (%s)", argv [1]);
|
|
||||||
|
|
||||||
while (fgets (dirname, BUFSIZ-1, f)) {
|
while ((entry = readdir (directory))) {
|
||||||
struct dirent *entry;
|
glibtop_inodedb_key key;
|
||||||
struct stat statb;
|
char filename [BUFSIZ];
|
||||||
DIR *directory;
|
datum d_key, d_content;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
len = strlen (dirname);
|
sprintf (filename, "%s/%s", dirname, entry->d_name);
|
||||||
if (!len) continue;
|
|
||||||
|
|
||||||
if (dirname [len-1] == '\n')
|
if (stat (filename, &statb))
|
||||||
dirname [len-1] = 0;
|
continue;
|
||||||
|
|
||||||
if (stat (dirname, &statb))
|
if (!S_ISREG (statb.st_mode))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (S_ISREG (statb.st_mode)) {
|
d_key.dptr = (void *) &key;
|
||||||
glibtop_inodedb_key key;
|
d_key.dsize = sizeof (key);
|
||||||
datum d_key, d_content;
|
|
||||||
|
|
||||||
d_key.dptr = (void *) &key;
|
d_content.dptr = filename;
|
||||||
d_key.dsize = sizeof (key);
|
d_content.dsize = strlen (filename) + 1;
|
||||||
|
|
||||||
d_content.dptr = dirname;
|
key.device = (u_int64_t) statb.st_dev;
|
||||||
d_content.dsize = strlen (dirname) + 1;
|
key.inode = (u_int64_t) statb.st_ino;
|
||||||
|
|
||||||
key.device = (u_int64_t) statb.st_dev;
|
if (gdbm_store (dbf, d_key, d_content, GDBM_REPLACE))
|
||||||
key.inode = (u_int64_t) statb.st_ino;
|
glibtop_error_io ("gdbm_store (%s)", filename);
|
||||||
|
|
||||||
if (gdbm_store (dbf, d_key, d_content, GDBM_REPLACE))
|
printf ("%-52s - %8lu - %8lu\n",
|
||||||
glibtop_error_io ("gdbm_store (%s)", dirname);
|
filename, (unsigned long) statb.st_dev,
|
||||||
|
(unsigned long) statb.st_ino);
|
||||||
printf ("%-52s - %8lu - %8lu\n",
|
|
||||||
dirname, (unsigned long) statb.st_dev,
|
|
||||||
(unsigned long) statb.st_ino);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!S_ISDIR (statb.st_mode))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
directory = opendir (dirname);
|
|
||||||
if (!directory) continue;
|
|
||||||
|
|
||||||
while ((entry = readdir (directory))) {
|
|
||||||
glibtop_inodedb_key key;
|
|
||||||
char filename [BUFSIZ];
|
|
||||||
datum d_key, d_content;
|
|
||||||
|
|
||||||
sprintf (filename, "%s/%s", dirname, entry->d_name);
|
|
||||||
|
|
||||||
if (stat (filename, &statb))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!S_ISREG (statb.st_mode))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
d_key.dptr = (void *) &key;
|
|
||||||
d_key.dsize = sizeof (key);
|
|
||||||
|
|
||||||
d_content.dptr = filename;
|
|
||||||
d_content.dsize = strlen (filename) + 1;
|
|
||||||
|
|
||||||
key.device = (u_int64_t) statb.st_dev;
|
|
||||||
key.inode = (u_int64_t) statb.st_ino;
|
|
||||||
|
|
||||||
if (gdbm_store (dbf, d_key, d_content, GDBM_REPLACE))
|
|
||||||
glibtop_error_io ("gdbm_store (%s)", filename);
|
|
||||||
|
|
||||||
printf ("%-52s - %8lu - %8lu\n",
|
|
||||||
filename, (unsigned long) statb.st_dev,
|
|
||||||
(unsigned long) statb.st_ino);
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir (directory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gdbm_close (dbf);
|
closedir (directory);
|
||||||
|
}
|
||||||
|
|
||||||
fclose (f);
|
gdbm_close (dbf);
|
||||||
|
|
||||||
exit (0);
|
fclose (f);
|
||||||
|
|
||||||
|
exit (0);
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -30,59 +32,59 @@
|
|||||||
static void
|
static void
|
||||||
print_server_name (glibtop *server)
|
print_server_name (glibtop *server)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s: ", server ?
|
fprintf (stderr, "%s: ", server ?
|
||||||
(server->name ? server->name : DEFAULT_NAME)
|
(server->name ? server->name : DEFAULT_NAME)
|
||||||
: DEFAULT_NAME);
|
: DEFAULT_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_error_vr (glibtop *server, char *format, va_list args)
|
glibtop_error_vr (glibtop *server, char *format, va_list args)
|
||||||
{
|
{
|
||||||
print_server_name (server);
|
print_server_name (server);
|
||||||
vfprintf (stderr, format, args);
|
vfprintf (stderr, format, args);
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
#ifdef LIBGTOP_ENABLE_DEBUG
|
#ifdef LIBGTOP_ENABLE_DEBUG
|
||||||
abort ();
|
abort ();
|
||||||
#else
|
#else
|
||||||
exit (1);
|
exit (1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_error_io_vr (glibtop *server, char *format, int error, va_list args)
|
glibtop_error_io_vr (glibtop *server, char *format, int error, va_list args)
|
||||||
{
|
{
|
||||||
print_server_name (server);
|
print_server_name (server);
|
||||||
vfprintf (stderr, format, args);
|
vfprintf (stderr, format, args);
|
||||||
fprintf (stderr, ": %s\n", strerror (error));
|
fprintf (stderr, ": %s\n", strerror (error));
|
||||||
|
|
||||||
#ifdef LIBGTOP_ENABLE_DEBUG
|
#ifdef LIBGTOP_ENABLE_DEBUG
|
||||||
abort ();
|
abort ();
|
||||||
#else
|
#else
|
||||||
exit (1);
|
exit (1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_warn_vr (glibtop *server, char *format, va_list args)
|
glibtop_warn_vr (glibtop *server, char *format, va_list args)
|
||||||
{
|
{
|
||||||
print_server_name (server);
|
print_server_name (server);
|
||||||
vfprintf (stderr, format, args);
|
vfprintf (stderr, format, args);
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
#ifdef LIBGTOP_FATAL_WARNINGS
|
#ifdef LIBGTOP_FATAL_WARNINGS
|
||||||
abort ();
|
abort ();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_warn_io_vr (glibtop *server, char *format, int error, va_list args)
|
glibtop_warn_io_vr (glibtop *server, char *format, int error, va_list args)
|
||||||
{
|
{
|
||||||
print_server_name (server);
|
print_server_name (server);
|
||||||
vfprintf (stderr, format, args);
|
vfprintf (stderr, format, args);
|
||||||
fprintf (stderr, ": %s\n", strerror (error));
|
fprintf (stderr, ": %s\n", strerror (error));
|
||||||
|
|
||||||
#ifdef LIBGTOP_FATAL_WARNINGS
|
#ifdef LIBGTOP_FATAL_WARNINGS
|
||||||
abort ();
|
abort ();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* fsusage.c -- return space usage of mounted filesystems
|
/* fsusage.c -- return space usage of mounted filesystems
|
||||||
Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc.
|
Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc.
|
||||||
|
|
||||||
@@ -85,17 +87,17 @@ adjust_blocks (blocks, fromsize, tosize)
|
|||||||
long blocks;
|
long blocks;
|
||||||
int fromsize, tosize;
|
int fromsize, tosize;
|
||||||
{
|
{
|
||||||
if (tosize <= 0)
|
if (tosize <= 0)
|
||||||
abort ();
|
abort ();
|
||||||
if (fromsize <= 0)
|
if (fromsize <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (fromsize == tosize) /* e.g., from 512 to 512 */
|
if (fromsize == tosize) /* e.g., from 512 to 512 */
|
||||||
return blocks;
|
return blocks;
|
||||||
else if (fromsize > tosize) /* e.g., from 2048 to 512 */
|
else if (fromsize > tosize) /* e.g., from 2048 to 512 */
|
||||||
return blocks * (fromsize / tosize);
|
return blocks * (fromsize / tosize);
|
||||||
else /* e.g., from 256 to 512 */
|
else /* e.g., from 256 to 512 */
|
||||||
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
|
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in the fields of FSP with information about space usage for
|
/* Fill in the fields of FSP with information about space usage for
|
||||||
@@ -114,25 +116,25 @@ get_fs_usage (path, disk, fsp)
|
|||||||
#ifdef STAT_STATFS3_OSF1
|
#ifdef STAT_STATFS3_OSF1
|
||||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512)
|
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512)
|
||||||
|
|
||||||
struct statfs fsd;
|
struct statfs fsd;
|
||||||
|
|
||||||
if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
|
if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#endif /* STAT_STATFS3_OSF1 */
|
#endif /* STAT_STATFS3_OSF1 */
|
||||||
|
|
||||||
#ifdef STAT_STATFS2_FS_DATA /* Ultrix */
|
#ifdef STAT_STATFS2_FS_DATA /* Ultrix */
|
||||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), 1024, 512)
|
# define CONVERT_BLOCKS(B) adjust_blocks ((B), 1024, 512)
|
||||||
|
|
||||||
struct fs_data fsd;
|
struct fs_data fsd;
|
||||||
|
|
||||||
if (statfs (path, &fsd) != 1)
|
if (statfs (path, &fsd) != 1)
|
||||||
return -1;
|
return -1;
|
||||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.fd_req.btot);
|
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.fd_req.btot);
|
||||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.fd_req.bfree);
|
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.fd_req.bfree);
|
||||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.fd_req.bfreen);
|
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.fd_req.bfreen);
|
||||||
fsp->fsu_files = fsd.fd_req.gtot;
|
fsp->fsu_files = fsd.fd_req.gtot;
|
||||||
fsp->fsu_ffree = fsd.fd_req.gfree;
|
fsp->fsu_ffree = fsd.fd_req.gfree;
|
||||||
|
|
||||||
#endif /* STAT_STATFS2_FS_DATA */
|
#endif /* STAT_STATFS2_FS_DATA */
|
||||||
|
|
||||||
@@ -143,54 +145,54 @@ get_fs_usage (path, disk, fsp)
|
|||||||
# define CONVERT_BLOCKS(B) \
|
# define CONVERT_BLOCKS(B) \
|
||||||
adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512)
|
adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512)
|
||||||
|
|
||||||
struct filsys fsd;
|
struct filsys fsd;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (! disk)
|
if (! disk)
|
||||||
{
|
{
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open (disk, O_RDONLY);
|
fd = open (disk, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
lseek (fd, (long) SUPERBOFF, 0);
|
lseek (fd, (long) SUPERBOFF, 0);
|
||||||
if (safe_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd)
|
if (safe_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd)
|
||||||
{
|
{
|
||||||
close (fd);
|
close (fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.s_fsize);
|
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.s_fsize);
|
||||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.s_tfree);
|
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.s_tfree);
|
||||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.s_tfree);
|
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.s_tfree);
|
||||||
fsp->fsu_files = (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1);
|
fsp->fsu_files = (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1);
|
||||||
fsp->fsu_ffree = fsd.s_tinode;
|
fsp->fsu_ffree = fsd.s_tinode;
|
||||||
|
|
||||||
#endif /* STAT_READ_FILSYS */
|
#endif /* STAT_READ_FILSYS */
|
||||||
|
|
||||||
#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
|
#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
|
||||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512)
|
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512)
|
||||||
|
|
||||||
struct statfs fsd;
|
struct statfs fsd;
|
||||||
|
|
||||||
if (statfs (path, &fsd) < 0)
|
if (statfs (path, &fsd) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
# ifdef STATFS_TRUNCATES_BLOCK_COUNTS
|
# ifdef STATFS_TRUNCATES_BLOCK_COUNTS
|
||||||
|
|
||||||
/* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the
|
/* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the
|
||||||
struct statfs are truncated to 2GB. These conditions detect that
|
struct statfs are truncated to 2GB. These conditions detect that
|
||||||
truncation, presumably without botching the 4.1.1 case, in which
|
truncation, presumably without botching the 4.1.1 case, in which
|
||||||
the values are not truncated. The correct counts are stored in
|
the values are not truncated. The correct counts are stored in
|
||||||
undocumented spare fields. */
|
undocumented spare fields. */
|
||||||
if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0)
|
if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0)
|
||||||
{
|
{
|
||||||
fsd.f_blocks = fsd.f_spare[0];
|
fsd.f_blocks = fsd.f_spare[0];
|
||||||
fsd.f_bfree = fsd.f_spare[1];
|
fsd.f_bfree = fsd.f_spare[1];
|
||||||
fsd.f_bavail = fsd.f_spare[2];
|
fsd.f_bavail = fsd.f_spare[2];
|
||||||
}
|
}
|
||||||
# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
|
# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
|
||||||
|
|
||||||
#endif /* STAT_STATFS2_BSIZE */
|
#endif /* STAT_STATFS2_BSIZE */
|
||||||
@@ -198,10 +200,10 @@ get_fs_usage (path, disk, fsp)
|
|||||||
#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */
|
#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */
|
||||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512)
|
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512)
|
||||||
|
|
||||||
struct statfs fsd;
|
struct statfs fsd;
|
||||||
|
|
||||||
if (statfs (path, &fsd) < 0)
|
if (statfs (path, &fsd) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#endif /* STAT_STATFS2_FSIZE */
|
#endif /* STAT_STATFS2_FSIZE */
|
||||||
|
|
||||||
@@ -220,13 +222,13 @@ get_fs_usage (path, disk, fsp)
|
|||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
struct statfs fsd;
|
struct statfs fsd;
|
||||||
|
|
||||||
if (statfs (path, &fsd, sizeof fsd, 0) < 0)
|
if (statfs (path, &fsd, sizeof fsd, 0) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
/* Empirically, the block counts on most SVR3 and SVR3-derived
|
/* Empirically, the block counts on most SVR3 and SVR3-derived
|
||||||
systems seem to always be in terms of 512-byte blocks,
|
systems seem to always be in terms of 512-byte blocks,
|
||||||
no matter what value f_bsize has. */
|
no matter what value f_bsize has. */
|
||||||
|
|
||||||
#endif /* STAT_STATFS4 */
|
#endif /* STAT_STATFS4 */
|
||||||
|
|
||||||
@@ -234,26 +236,26 @@ get_fs_usage (path, disk, fsp)
|
|||||||
# define CONVERT_BLOCKS(B) \
|
# define CONVERT_BLOCKS(B) \
|
||||||
adjust_blocks ((B), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512)
|
adjust_blocks ((B), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512)
|
||||||
|
|
||||||
struct statvfs fsd;
|
struct statvfs fsd;
|
||||||
|
|
||||||
if (statvfs (path, &fsd) < 0)
|
if (statvfs (path, &fsd) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
/* f_frsize isn't guaranteed to be supported. */
|
/* f_frsize isn't guaranteed to be supported. */
|
||||||
|
|
||||||
#endif /* STAT_STATVFS */
|
#endif /* STAT_STATVFS */
|
||||||
|
|
||||||
#if !defined(STAT_STATFS2_FS_DATA) && !defined(STAT_READ_FILSYS)
|
#if !defined(STAT_STATFS2_FS_DATA) && !defined(STAT_READ_FILSYS)
|
||||||
/* !Ultrix && !SVR2 */
|
/* !Ultrix && !SVR2 */
|
||||||
|
|
||||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
|
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
|
||||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
|
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
|
||||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
|
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
|
||||||
fsp->fsu_files = fsd.f_files;
|
fsp->fsu_files = fsd.f_files;
|
||||||
fsp->fsu_ffree = fsd.f_ffree;
|
fsp->fsu_ffree = fsd.f_ffree;
|
||||||
|
|
||||||
#endif /* not STAT_STATFS2_FS_DATA && not STAT_READ_FILSYS */
|
#endif /* not STAT_STATFS2_FS_DATA && not STAT_READ_FILSYS */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_AIX) && defined(_I386)
|
#if defined(_AIX) && defined(_I386)
|
||||||
@@ -264,23 +266,23 @@ statfs (path, fsb)
|
|||||||
char *path;
|
char *path;
|
||||||
struct statfs *fsb;
|
struct statfs *fsb;
|
||||||
{
|
{
|
||||||
struct stat stats;
|
struct stat stats;
|
||||||
struct dustat fsd;
|
struct dustat fsd;
|
||||||
|
|
||||||
if (stat (path, &stats))
|
if (stat (path, &stats))
|
||||||
return -1;
|
return -1;
|
||||||
if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd)))
|
if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd)))
|
||||||
return -1;
|
return -1;
|
||||||
fsb->f_type = 0;
|
fsb->f_type = 0;
|
||||||
fsb->f_bsize = fsd.du_bsize;
|
fsb->f_bsize = fsd.du_bsize;
|
||||||
fsb->f_blocks = fsd.du_fsize - fsd.du_isize;
|
fsb->f_blocks = fsd.du_fsize - fsd.du_isize;
|
||||||
fsb->f_bfree = fsd.du_tfree;
|
fsb->f_bfree = fsd.du_tfree;
|
||||||
fsb->f_bavail = fsd.du_tfree;
|
fsb->f_bavail = fsd.du_tfree;
|
||||||
fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb;
|
fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb;
|
||||||
fsb->f_ffree = fsd.du_tinode;
|
fsb->f_ffree = fsd.du_tinode;
|
||||||
fsb->f_fsid.val[0] = fsd.du_site;
|
fsb->f_fsid.val[0] = fsd.du_site;
|
||||||
fsb->f_fsid.val[1] = fsd.du_pckno;
|
fsb->f_fsid.val[1] = fsd.du_pckno;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _AIX && _I386 */
|
#endif /* _AIX && _I386 */
|
||||||
@@ -289,22 +291,22 @@ int
|
|||||||
glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
|
glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
|
||||||
const char *disk)
|
const char *disk)
|
||||||
{
|
{
|
||||||
struct fs_usage fsp;
|
struct fs_usage fsp;
|
||||||
|
|
||||||
glibtop_init_r (&server, 0, 0);
|
glibtop_init_r (&server, 0, 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_fsusage));
|
memset (buf, 0, sizeof (glibtop_fsusage));
|
||||||
|
|
||||||
if (get_fs_usage (disk, disk, &fsp))
|
if (get_fs_usage (disk, disk, &fsp))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
buf->blocks = fsp.fsu_blocks;
|
buf->blocks = fsp.fsu_blocks;
|
||||||
buf->bfree = fsp.fsu_bfree;
|
buf->bfree = fsp.fsu_bfree;
|
||||||
buf->bavail = fsp.fsu_bavail;
|
buf->bavail = fsp.fsu_bavail;
|
||||||
buf->files = fsp.fsu_files;
|
buf->files = fsp.fsu_files;
|
||||||
buf->ffree = fsp.fsu_ffree;
|
buf->ffree = fsp.fsu_ffree;
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_fsusage;
|
buf->flags = _glibtop_sysdeps_fsusage;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* fsusage.h -- declarations for filesystem space usage info
|
/* fsusage.h -- declarations for filesystem space usage info
|
||||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||||
|
|
||||||
@@ -18,10 +20,10 @@
|
|||||||
/* Space usage statistics for a filesystem. Blocks are 512-byte. */
|
/* Space usage statistics for a filesystem. Blocks are 512-byte. */
|
||||||
struct fs_usage
|
struct fs_usage
|
||||||
{
|
{
|
||||||
long fsu_blocks; /* Total blocks. */
|
long fsu_blocks; /* Total blocks. */
|
||||||
long fsu_bfree; /* Free blocks available to superuser. */
|
long fsu_bfree; /* Free blocks available to superuser. */
|
||||||
long fsu_bavail; /* Free blocks available to non-superuser. */
|
long fsu_bavail; /* Free blocks available to non-superuser. */
|
||||||
long fsu_files; /* Total file nodes. */
|
long fsu_files; /* Total file nodes. */
|
||||||
long fsu_ffree; /* Free file nodes. */
|
long fsu_ffree; /* Free file nodes. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -37,44 +39,44 @@ glibtop_inodedb *
|
|||||||
glibtop_inodedb_open_s (glibtop *server, unsigned databases,
|
glibtop_inodedb_open_s (glibtop *server, unsigned databases,
|
||||||
unsigned long cachesize)
|
unsigned long cachesize)
|
||||||
{
|
{
|
||||||
glibtop_inodedb *inodedb;
|
glibtop_inodedb *inodedb;
|
||||||
char filename [BUFSIZ];
|
char filename [BUFSIZ];
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
|
|
||||||
if (!databases)
|
if (!databases)
|
||||||
databases = GLIBTOP_INODEDB_ALL;
|
databases = GLIBTOP_INODEDB_ALL;
|
||||||
|
|
||||||
inodedb = glibtop_calloc_r (server, 1, sizeof (glibtop_inodedb));
|
inodedb = glibtop_calloc_r (server, 1, sizeof (glibtop_inodedb));
|
||||||
|
|
||||||
if (stat (SYSTEM_INODEDB, &statb))
|
if (stat (SYSTEM_INODEDB, &statb))
|
||||||
databases &= ~GLIBTOP_INODEDB_SYSTEM;
|
databases &= ~GLIBTOP_INODEDB_SYSTEM;
|
||||||
|
|
||||||
if (databases & GLIBTOP_INODEDB_SYSTEM) {
|
if (databases & GLIBTOP_INODEDB_SYSTEM) {
|
||||||
inodedb->system_dbf = gdbm_open
|
inodedb->system_dbf = gdbm_open
|
||||||
(SYSTEM_INODEDB, 0, GDBM_READER, 0, 0);
|
(SYSTEM_INODEDB, 0, GDBM_READER, 0, 0);
|
||||||
if (!inodedb->system_dbf)
|
if (!inodedb->system_dbf)
|
||||||
glibtop_error_io_r
|
glibtop_error_io_r
|
||||||
(server, "gdbm_open (%s)", SYSTEM_INODEDB);
|
(server, "gdbm_open (%s)", SYSTEM_INODEDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
pwd = getpwuid (getuid ());
|
pwd = getpwuid (getuid ());
|
||||||
if (!pwd) glibtop_error_io_r (server, "getpwuid");
|
if (!pwd) glibtop_error_io_r (server, "getpwuid");
|
||||||
|
|
||||||
sprintf (filename, "%s/var/libgtop/inodedb.db", pwd->pw_dir);
|
sprintf (filename, "%s/var/libgtop/inodedb.db", pwd->pw_dir);
|
||||||
|
|
||||||
if (stat (filename, &statb))
|
if (stat (filename, &statb))
|
||||||
databases &= ~GLIBTOP_INODEDB_USER;
|
databases &= ~GLIBTOP_INODEDB_USER;
|
||||||
|
|
||||||
if (databases & GLIBTOP_INODEDB_USER) {
|
if (databases & GLIBTOP_INODEDB_USER) {
|
||||||
inodedb->user_dbf = gdbm_open
|
inodedb->user_dbf = gdbm_open
|
||||||
(filename, 0, GDBM_READER, 0, 0);
|
(filename, 0, GDBM_READER, 0, 0);
|
||||||
if (!inodedb->user_dbf)
|
if (!inodedb->user_dbf)
|
||||||
glibtop_error_io_r
|
glibtop_error_io_r
|
||||||
(server, "gdbm_open (%s)", filename);
|
(server, "gdbm_open (%s)", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return inodedb;
|
return inodedb;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
@@ -82,36 +84,36 @@ glibtop_inodedb_lookup_s (glibtop *server,
|
|||||||
glibtop_inodedb *inodedb,
|
glibtop_inodedb *inodedb,
|
||||||
u_int64_t device, u_int64_t inode)
|
u_int64_t device, u_int64_t inode)
|
||||||
{
|
{
|
||||||
glibtop_inodedb_key key;
|
glibtop_inodedb_key key;
|
||||||
datum d_key, d_content;
|
datum d_key, d_content;
|
||||||
|
|
||||||
d_key.dptr = (void *) &key;
|
d_key.dptr = (void *) &key;
|
||||||
d_key.dsize = sizeof (key);
|
d_key.dsize = sizeof (key);
|
||||||
|
|
||||||
key.device = device;
|
key.device = device;
|
||||||
key.inode = inode;
|
key.inode = inode;
|
||||||
|
|
||||||
if (inodedb->system_dbf) {
|
if (inodedb->system_dbf) {
|
||||||
d_content = gdbm_fetch (inodedb->system_dbf, d_key);
|
d_content = gdbm_fetch (inodedb->system_dbf, d_key);
|
||||||
if (d_content.dptr) return d_content.dptr;
|
if (d_content.dptr) return d_content.dptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inodedb->user_dbf) {
|
if (inodedb->user_dbf) {
|
||||||
d_content = gdbm_fetch (inodedb->user_dbf, d_key);
|
d_content = gdbm_fetch (inodedb->user_dbf, d_key);
|
||||||
if (d_content.dptr) return d_content.dptr;
|
if (d_content.dptr) return d_content.dptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_inodedb_close_s (glibtop *server, glibtop_inodedb *inodedb)
|
glibtop_inodedb_close_s (glibtop *server, glibtop_inodedb *inodedb)
|
||||||
{
|
{
|
||||||
if (inodedb->system_dbf)
|
if (inodedb->system_dbf)
|
||||||
gdbm_close (inodedb->system_dbf);
|
gdbm_close (inodedb->system_dbf);
|
||||||
|
|
||||||
if (inodedb->user_dbf)
|
if (inodedb->user_dbf)
|
||||||
gdbm_close (inodedb->user_dbf);
|
gdbm_close (inodedb->user_dbf);
|
||||||
|
|
||||||
glibtop_free_r (server, inodedb);
|
glibtop_free_r (server, inodedb);
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* mountlist.c -- return a list of mounted filesystems
|
/* mountlist.c -- return a list of mounted filesystems
|
||||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||||
|
|
||||||
@@ -117,22 +119,22 @@ static int
|
|||||||
xatoi (cp)
|
xatoi (cp)
|
||||||
char *cp;
|
char *cp;
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
val = 0;
|
val = 0;
|
||||||
while (*cp)
|
while (*cp)
|
||||||
{
|
{
|
||||||
if (*cp >= 'a' && *cp <= 'f')
|
if (*cp >= 'a' && *cp <= 'f')
|
||||||
val = val * 16 + *cp - 'a' + 10;
|
val = val * 16 + *cp - 'a' + 10;
|
||||||
else if (*cp >= 'A' && *cp <= 'F')
|
else if (*cp >= 'A' && *cp <= 'F')
|
||||||
val = val * 16 + *cp - 'A' + 10;
|
val = val * 16 + *cp - 'A' + 10;
|
||||||
else if (*cp >= '0' && *cp <= '9')
|
else if (*cp >= '0' && *cp <= '9')
|
||||||
val = val * 16 + *cp - '0';
|
val = val * 16 + *cp - '0';
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
cp++;
|
cp++;
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_GETMNTENT1. */
|
#endif /* MOUNTED_GETMNTENT1. */
|
||||||
|
|
||||||
@@ -141,95 +143,95 @@ static char *
|
|||||||
fstype_to_string (t)
|
fstype_to_string (t)
|
||||||
short t;
|
short t;
|
||||||
{
|
{
|
||||||
switch (t)
|
switch (t)
|
||||||
{
|
{
|
||||||
#ifdef MOUNT_PC
|
#ifdef MOUNT_PC
|
||||||
case MOUNT_PC:
|
case MOUNT_PC:
|
||||||
return "pc";
|
return "pc";
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_MFS
|
#ifdef MOUNT_MFS
|
||||||
case MOUNT_MFS:
|
case MOUNT_MFS:
|
||||||
return "mfs";
|
return "mfs";
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_LO
|
#ifdef MOUNT_LO
|
||||||
case MOUNT_LO:
|
case MOUNT_LO:
|
||||||
return "lo";
|
return "lo";
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_TFS
|
#ifdef MOUNT_TFS
|
||||||
case MOUNT_TFS:
|
case MOUNT_TFS:
|
||||||
return "tfs";
|
return "tfs";
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_TMP
|
#ifdef MOUNT_TMP
|
||||||
case MOUNT_TMP:
|
case MOUNT_TMP:
|
||||||
return "tmp";
|
return "tmp";
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_UFS
|
#ifdef MOUNT_UFS
|
||||||
case MOUNT_UFS:
|
case MOUNT_UFS:
|
||||||
return "ufs" ;
|
return "ufs" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_NFS
|
#ifdef MOUNT_NFS
|
||||||
case MOUNT_NFS:
|
case MOUNT_NFS:
|
||||||
return "nfs" ;
|
return "nfs" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_MSDOS
|
#ifdef MOUNT_MSDOS
|
||||||
case MOUNT_MSDOS:
|
case MOUNT_MSDOS:
|
||||||
return "msdos" ;
|
return "msdos" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_LFS
|
#ifdef MOUNT_LFS
|
||||||
case MOUNT_LFS:
|
case MOUNT_LFS:
|
||||||
return "lfs" ;
|
return "lfs" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_LOFS
|
#ifdef MOUNT_LOFS
|
||||||
case MOUNT_LOFS:
|
case MOUNT_LOFS:
|
||||||
return "lofs" ;
|
return "lofs" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_FDESC
|
#ifdef MOUNT_FDESC
|
||||||
case MOUNT_FDESC:
|
case MOUNT_FDESC:
|
||||||
return "fdesc" ;
|
return "fdesc" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_PORTAL
|
#ifdef MOUNT_PORTAL
|
||||||
case MOUNT_PORTAL:
|
case MOUNT_PORTAL:
|
||||||
return "portal" ;
|
return "portal" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_NULL
|
#ifdef MOUNT_NULL
|
||||||
case MOUNT_NULL:
|
case MOUNT_NULL:
|
||||||
return "null" ;
|
return "null" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_UMAP
|
#ifdef MOUNT_UMAP
|
||||||
case MOUNT_UMAP:
|
case MOUNT_UMAP:
|
||||||
return "umap" ;
|
return "umap" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_KERNFS
|
#ifdef MOUNT_KERNFS
|
||||||
case MOUNT_KERNFS:
|
case MOUNT_KERNFS:
|
||||||
return "kernfs" ;
|
return "kernfs" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_PROCFS
|
#ifdef MOUNT_PROCFS
|
||||||
case MOUNT_PROCFS:
|
case MOUNT_PROCFS:
|
||||||
return "procfs" ;
|
return "procfs" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_AFS
|
#ifdef MOUNT_AFS
|
||||||
case MOUNT_AFS:
|
case MOUNT_AFS:
|
||||||
return "afs" ;
|
return "afs" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_CD9660
|
#ifdef MOUNT_CD9660
|
||||||
case MOUNT_CD9660:
|
case MOUNT_CD9660:
|
||||||
return "cd9660" ;
|
return "cd9660" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_UNION
|
#ifdef MOUNT_UNION
|
||||||
case MOUNT_UNION:
|
case MOUNT_UNION:
|
||||||
return "union" ;
|
return "union" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_DEVFS
|
#ifdef MOUNT_DEVFS
|
||||||
case MOUNT_DEVFS:
|
case MOUNT_DEVFS:
|
||||||
return "devfs" ;
|
return "devfs" ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOUNT_EXT2FS
|
#ifdef MOUNT_EXT2FS
|
||||||
case MOUNT_EXT2FS:
|
case MOUNT_EXT2FS:
|
||||||
return "ext2fs" ;
|
return "ext2fs" ;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_GETMNTINFO */
|
#endif /* MOUNTED_GETMNTINFO */
|
||||||
|
|
||||||
@@ -238,13 +240,13 @@ static char *
|
|||||||
fstype_to_string (t)
|
fstype_to_string (t)
|
||||||
int t;
|
int t;
|
||||||
{
|
{
|
||||||
struct vfs_ent *e;
|
struct vfs_ent *e;
|
||||||
|
|
||||||
e = getvfsbytype (t);
|
e = getvfsbytype (t);
|
||||||
if (!e || !e->vfsent_name)
|
if (!e || !e->vfsent_name)
|
||||||
return "none";
|
return "none";
|
||||||
else
|
else
|
||||||
return e->vfsent_name;
|
return e->vfsent_name;
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_VMOUNT */
|
#endif /* MOUNTED_VMOUNT */
|
||||||
|
|
||||||
@@ -259,386 +261,386 @@ static struct mount_entry *
|
|||||||
read_filesystem_list (need_fs_type, all_fs)
|
read_filesystem_list (need_fs_type, all_fs)
|
||||||
int need_fs_type, all_fs;
|
int need_fs_type, all_fs;
|
||||||
{
|
{
|
||||||
struct mount_entry *mount_list;
|
struct mount_entry *mount_list;
|
||||||
struct mount_entry *me;
|
struct mount_entry *me;
|
||||||
struct mount_entry *mtail;
|
struct mount_entry *mtail;
|
||||||
|
|
||||||
/* Start the list off with a dummy entry. */
|
/* Start the list off with a dummy entry. */
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
mount_list = mtail = me;
|
mount_list = mtail = me;
|
||||||
|
|
||||||
#ifdef MOUNTED_LISTMNTENT
|
#ifdef MOUNTED_LISTMNTENT
|
||||||
{
|
{
|
||||||
struct tabmntent *mntlist, *p;
|
struct tabmntent *mntlist, *p;
|
||||||
struct mntent *mnt;
|
struct mntent *mnt;
|
||||||
struct mount_entry *me;
|
struct mount_entry *me;
|
||||||
|
|
||||||
/* the third and fourth arguments could be used to filter mounts,
|
/* the third and fourth arguments could be used to filter mounts,
|
||||||
but Crays doesn't seem to have any mounts that we want to
|
but Crays doesn't seem to have any mounts that we want to
|
||||||
remove. Specifically, automount create normal NFS mounts.
|
remove. Specifically, automount create normal NFS mounts.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(listmntent(&mntlist, KMTAB, NULL, NULL) < 0)
|
if(listmntent(&mntlist, KMTAB, NULL, NULL) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
p = mntlist;
|
p = mntlist;
|
||||||
while(p){
|
while(p){
|
||||||
mnt = p->ment;
|
mnt = p->ment;
|
||||||
me = (struct mount_entry*) xmalloc(sizeof (struct mount_entry));
|
me = (struct mount_entry*) xmalloc(sizeof (struct mount_entry));
|
||||||
me->me_devname = xstrdup(mnt->mnt_fsname);
|
me->me_devname = xstrdup(mnt->mnt_fsname);
|
||||||
me->me_mountdir = xstrdup(mnt->mnt_dir);
|
me->me_mountdir = xstrdup(mnt->mnt_dir);
|
||||||
me->me_type = xstrdup(mnt->mnt_type);
|
me->me_type = xstrdup(mnt->mnt_type);
|
||||||
me->me_dev = -1;
|
me->me_dev = -1;
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
mtail->me_next = me;
|
mtail->me_next = me;
|
||||||
mtail = me;
|
mtail = me;
|
||||||
p = p->next;
|
p = p->next;
|
||||||
|
}
|
||||||
|
freemntlist(mntlist);
|
||||||
}
|
}
|
||||||
freemntlist(mntlist);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||||
{
|
{
|
||||||
struct mntent *mnt;
|
struct mntent *mnt;
|
||||||
char *table = MOUNTED;
|
char *table = MOUNTED;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *devopt;
|
char *devopt;
|
||||||
|
|
||||||
fp = setmntent (table, "r");
|
fp = setmntent (table, "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while ((mnt = getmntent (fp)))
|
while ((mnt = getmntent (fp)))
|
||||||
{
|
{
|
||||||
if (!all_fs && (!strcmp (mnt->mnt_type, "ignore")
|
if (!all_fs && (!strcmp (mnt->mnt_type, "ignore")
|
||||||
|| !strcmp (mnt->mnt_type, "auto")))
|
|| !strcmp (mnt->mnt_type, "auto")))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
me->me_devname = xstrdup (mnt->mnt_fsname);
|
me->me_devname = xstrdup (mnt->mnt_fsname);
|
||||||
me->me_mountdir = xstrdup (mnt->mnt_dir);
|
me->me_mountdir = xstrdup (mnt->mnt_dir);
|
||||||
me->me_type = xstrdup (mnt->mnt_type);
|
me->me_type = xstrdup (mnt->mnt_type);
|
||||||
devopt = strstr (mnt->mnt_opts, "dev=");
|
devopt = strstr (mnt->mnt_opts, "dev=");
|
||||||
if (devopt)
|
if (devopt)
|
||||||
{
|
{
|
||||||
if (devopt[4] == '0' && (devopt[5] == 'x' || devopt[5] == 'X'))
|
if (devopt[4] == '0' && (devopt[5] == 'x' || devopt[5] == 'X'))
|
||||||
me->me_dev = xatoi (devopt + 6);
|
me->me_dev = xatoi (devopt + 6);
|
||||||
else
|
else
|
||||||
me->me_dev = xatoi (devopt + 4);
|
me->me_dev = xatoi (devopt + 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
|
|
||||||
/* Add to the linked list. */
|
/* Add to the linked list. */
|
||||||
mtail->me_next = me;
|
mtail->me_next = me;
|
||||||
mtail = me;
|
mtail = me;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endmntent (fp) == 0)
|
if (endmntent (fp) == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_GETMNTENT1. */
|
#endif /* MOUNTED_GETMNTENT1. */
|
||||||
|
|
||||||
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
||||||
{
|
{
|
||||||
struct statfs *fsp;
|
struct statfs *fsp;
|
||||||
int entries;
|
int entries;
|
||||||
|
|
||||||
entries = getmntinfo (&fsp, MNT_NOWAIT);
|
entries = getmntinfo (&fsp, MNT_NOWAIT);
|
||||||
if (entries < 0)
|
if (entries < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
while (entries-- > 0)
|
while (entries-- > 0)
|
||||||
{
|
{
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
me->me_devname = xstrdup (fsp->f_mntfromname);
|
me->me_devname = xstrdup (fsp->f_mntfromname);
|
||||||
me->me_mountdir = xstrdup (fsp->f_mntonname);
|
me->me_mountdir = xstrdup (fsp->f_mntonname);
|
||||||
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
||||||
me->me_type = xstrdup (fsp->f_fstypename);
|
me->me_type = xstrdup (fsp->f_fstypename);
|
||||||
#else
|
#else
|
||||||
me->me_type = xstrdup (fstype_to_string (fsp->f_type));
|
me->me_type = xstrdup (fstype_to_string (fsp->f_type));
|
||||||
#endif
|
#endif
|
||||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
|
|
||||||
/* Add to the linked list. */
|
/* Add to the linked list. */
|
||||||
mtail->me_next = me;
|
mtail->me_next = me;
|
||||||
mtail = me;
|
mtail = me;
|
||||||
fsp++;
|
fsp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_GETMNTINFO */
|
#endif /* MOUNTED_GETMNTINFO */
|
||||||
|
|
||||||
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
||||||
{
|
{
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int val;
|
int val;
|
||||||
struct fs_data fsd;
|
struct fs_data fsd;
|
||||||
|
|
||||||
while ((val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
|
while ((val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
|
||||||
(char *) 0)) > 0)
|
(char *) 0)) > 0)
|
||||||
{
|
{
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
me->me_devname = xstrdup (fsd.fd_req.devname);
|
me->me_devname = xstrdup (fsd.fd_req.devname);
|
||||||
me->me_mountdir = xstrdup (fsd.fd_req.path);
|
me->me_mountdir = xstrdup (fsd.fd_req.path);
|
||||||
me->me_type = xstrdup (gt_names[fsd.fd_req.fstype]);
|
me->me_type = xstrdup (gt_names[fsd.fd_req.fstype]);
|
||||||
me->me_dev = fsd.fd_req.dev;
|
me->me_dev = fsd.fd_req.dev;
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
|
|
||||||
/* Add to the linked list. */
|
/* Add to the linked list. */
|
||||||
mtail->me_next = me;
|
mtail->me_next = me;
|
||||||
mtail = me;
|
mtail = me;
|
||||||
}
|
}
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_GETMNT. */
|
#endif /* MOUNTED_GETMNT. */
|
||||||
|
|
||||||
#if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */
|
#if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */
|
||||||
{
|
{
|
||||||
int numsys, counter, bufsize;
|
int numsys, counter, bufsize;
|
||||||
struct statfs *stats;
|
struct statfs *stats;
|
||||||
|
|
||||||
numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
|
numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
|
||||||
if (numsys < 0)
|
if (numsys < 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
bufsize = (1 + numsys) * sizeof (struct statfs);
|
bufsize = (1 + numsys) * sizeof (struct statfs);
|
||||||
stats = (struct statfs *)xmalloc (bufsize);
|
stats = (struct statfs *)xmalloc (bufsize);
|
||||||
numsys = getfsstat (stats, bufsize, MNT_WAIT);
|
numsys = getfsstat (stats, bufsize, MNT_WAIT);
|
||||||
|
|
||||||
|
if (numsys < 0)
|
||||||
|
{
|
||||||
|
free (stats);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (counter = 0; counter < numsys; counter++)
|
||||||
|
{
|
||||||
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
|
me->me_devname = xstrdup (stats[counter].f_mntfromname);
|
||||||
|
me->me_mountdir = xstrdup (stats[counter].f_mntonname);
|
||||||
|
me->me_type = xstrdup (mnt_names[stats[counter].f_type]);
|
||||||
|
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||||
|
me->me_next = NULL;
|
||||||
|
|
||||||
|
/* Add to the linked list. */
|
||||||
|
mtail->me_next = me;
|
||||||
|
mtail = me;
|
||||||
|
}
|
||||||
|
|
||||||
if (numsys < 0)
|
|
||||||
{
|
|
||||||
free (stats);
|
free (stats);
|
||||||
return (NULL);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (counter = 0; counter < numsys; counter++)
|
|
||||||
{
|
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
|
||||||
me->me_devname = xstrdup (stats[counter].f_mntfromname);
|
|
||||||
me->me_mountdir = xstrdup (stats[counter].f_mntonname);
|
|
||||||
me->me_type = xstrdup (mnt_names[stats[counter].f_type]);
|
|
||||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
|
||||||
me->me_next = NULL;
|
|
||||||
|
|
||||||
/* Add to the linked list. */
|
|
||||||
mtail->me_next = me;
|
|
||||||
mtail = me;
|
|
||||||
}
|
|
||||||
|
|
||||||
free (stats);
|
|
||||||
}
|
|
||||||
#endif /* MOUNTED_GETFSSTAT */
|
#endif /* MOUNTED_GETFSSTAT */
|
||||||
|
|
||||||
#if defined (MOUNTED_FREAD) || defined (MOUNTED_FREAD_FSTYP) /* SVR[23]. */
|
#if defined (MOUNTED_FREAD) || defined (MOUNTED_FREAD_FSTYP) /* SVR[23]. */
|
||||||
{
|
{
|
||||||
struct mnttab mnt;
|
struct mnttab mnt;
|
||||||
char *table = "/etc/mnttab";
|
char *table = "/etc/mnttab";
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
fp = fopen (table, "r");
|
fp = fopen (table, "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (fread (&mnt, sizeof mnt, 1, fp) > 0)
|
while (fread (&mnt, sizeof mnt, 1, fp) > 0)
|
||||||
{
|
{
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
#ifdef GETFSTYP /* SVR3. */
|
#ifdef GETFSTYP /* SVR3. */
|
||||||
me->me_devname = xstrdup (mnt.mt_dev);
|
me->me_devname = xstrdup (mnt.mt_dev);
|
||||||
#else
|
#else
|
||||||
me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6);
|
me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6);
|
||||||
strcpy (me->me_devname, "/dev/");
|
strcpy (me->me_devname, "/dev/");
|
||||||
strcpy (me->me_devname + 5, mnt.mt_dev);
|
strcpy (me->me_devname + 5, mnt.mt_dev);
|
||||||
#endif
|
#endif
|
||||||
me->me_mountdir = xstrdup (mnt.mt_filsys);
|
me->me_mountdir = xstrdup (mnt.mt_filsys);
|
||||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||||
me->me_type = xstrdup ("");
|
me->me_type = xstrdup ("");
|
||||||
#ifdef GETFSTYP /* SVR3. */
|
#ifdef GETFSTYP /* SVR3. */
|
||||||
if (need_fs_type)
|
if (need_fs_type)
|
||||||
{
|
{
|
||||||
struct statfs fsd;
|
struct statfs fsd;
|
||||||
char typebuf[FSTYPSZ];
|
char typebuf[FSTYPSZ];
|
||||||
|
|
||||||
if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1
|
if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1
|
||||||
&& sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
|
&& sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
|
||||||
me->me_type = xstrdup (typebuf);
|
me->me_type = xstrdup (typebuf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
|
|
||||||
/* Add to the linked list. */
|
/* Add to the linked list. */
|
||||||
mtail->me_next = me;
|
mtail->me_next = me;
|
||||||
mtail = me;
|
mtail = me;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fclose (fp) == EOF)
|
if (fclose (fp) == EOF)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */
|
#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */
|
||||||
|
|
||||||
#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */
|
#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */
|
||||||
{
|
{
|
||||||
struct mntent **mnttbl=getmnttbl(),**ent;
|
struct mntent **mnttbl=getmnttbl(),**ent;
|
||||||
for (ent=mnttbl;*ent;ent++)
|
for (ent=mnttbl;*ent;ent++)
|
||||||
{
|
{
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
me->me_devname = xstrdup ( (*ent)->mt_resource);
|
me->me_devname = xstrdup ( (*ent)->mt_resource);
|
||||||
me->me_mountdir = xstrdup( (*ent)->mt_directory);
|
me->me_mountdir = xstrdup( (*ent)->mt_directory);
|
||||||
me->me_type = xstrdup ((*ent)->mt_fstype);
|
me->me_type = xstrdup ((*ent)->mt_fstype);
|
||||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
|
|
||||||
/* Add to the linked list. */
|
/* Add to the linked list. */
|
||||||
mtail->me_next = me;
|
mtail->me_next = me;
|
||||||
mtail = me;
|
mtail = me;
|
||||||
}
|
}
|
||||||
endmnttbl();
|
endmnttbl();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
||||||
{
|
{
|
||||||
struct mnttab mnt;
|
struct mnttab mnt;
|
||||||
char *table = MNTTAB;
|
char *table = MNTTAB;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
fp = fopen (table, "r");
|
fp = fopen (table, "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while ((ret = getmntent (fp, &mnt)) == 0)
|
while ((ret = getmntent (fp, &mnt)) == 0)
|
||||||
{
|
{
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
me->me_devname = xstrdup (mnt.mnt_special);
|
me->me_devname = xstrdup (mnt.mnt_special);
|
||||||
me->me_mountdir = xstrdup (mnt.mnt_mountp);
|
me->me_mountdir = xstrdup (mnt.mnt_mountp);
|
||||||
me->me_type = xstrdup (mnt.mnt_fstype);
|
me->me_type = xstrdup (mnt.mnt_fstype);
|
||||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
|
|
||||||
/* Add to the linked list. */
|
/* Add to the linked list. */
|
||||||
mtail->me_next = me;
|
mtail->me_next = me;
|
||||||
mtail = me;
|
mtail = me;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (fclose (fp) == EOF)
|
if (fclose (fp) == EOF)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_GETMNTENT2. */
|
#endif /* MOUNTED_GETMNTENT2. */
|
||||||
|
|
||||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||||
{
|
{
|
||||||
int bufsize;
|
int bufsize;
|
||||||
char *entries, *thisent;
|
char *entries, *thisent;
|
||||||
struct vmount *vmp;
|
struct vmount *vmp;
|
||||||
|
|
||||||
/* Ask how many bytes to allocate for the mounted filesystem info. */
|
/* Ask how many bytes to allocate for the mounted filesystem info. */
|
||||||
mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize);
|
mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize);
|
||||||
entries = xmalloc (bufsize);
|
entries = xmalloc (bufsize);
|
||||||
|
|
||||||
/* Get the list of mounted filesystems. */
|
/* Get the list of mounted filesystems. */
|
||||||
mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
|
mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
|
||||||
|
|
||||||
for (thisent = entries; thisent < entries + bufsize;
|
for (thisent = entries; thisent < entries + bufsize;
|
||||||
thisent += vmp->vmt_length)
|
thisent += vmp->vmt_length)
|
||||||
{
|
{
|
||||||
vmp = (struct vmount *) thisent;
|
vmp = (struct vmount *) thisent;
|
||||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||||
if (vmp->vmt_flags & MNT_REMOTE)
|
if (vmp->vmt_flags & MNT_REMOTE)
|
||||||
{
|
{
|
||||||
char *host, *path;
|
char *host, *path;
|
||||||
|
|
||||||
/* Prepend the remote pathname. */
|
/* Prepend the remote pathname. */
|
||||||
host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off;
|
host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off;
|
||||||
path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off;
|
path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off;
|
||||||
me->me_devname = xmalloc (strlen (host) + strlen (path) + 2);
|
me->me_devname = xmalloc (strlen (host) + strlen (path) + 2);
|
||||||
strcpy (me->me_devname, host);
|
strcpy (me->me_devname, host);
|
||||||
strcat (me->me_devname, ":");
|
strcat (me->me_devname, ":");
|
||||||
strcat (me->me_devname, path);
|
strcat (me->me_devname, path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
me->me_devname = xstrdup (thisent +
|
me->me_devname = xstrdup (thisent +
|
||||||
vmp->vmt_data[VMT_OBJECT].vmt_off);
|
vmp->vmt_data[VMT_OBJECT].vmt_off);
|
||||||
}
|
}
|
||||||
me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
|
me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
|
||||||
me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
|
me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
|
||||||
me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */
|
me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */
|
||||||
me->me_next = NULL;
|
me->me_next = NULL;
|
||||||
|
|
||||||
/* Add to the linked list. */
|
/* Add to the linked list. */
|
||||||
mtail->me_next = me;
|
mtail->me_next = me;
|
||||||
mtail = me;
|
mtail = me;
|
||||||
}
|
}
|
||||||
free (entries);
|
free (entries);
|
||||||
}
|
}
|
||||||
#endif /* MOUNTED_VMOUNT. */
|
#endif /* MOUNTED_VMOUNT. */
|
||||||
|
|
||||||
/* Free the dummy head. */
|
/* Free the dummy head. */
|
||||||
me = mount_list;
|
me = mount_list;
|
||||||
mount_list = mount_list->me_next;
|
mount_list = mount_list->me_next;
|
||||||
free (me);
|
free (me);
|
||||||
return mount_list;
|
return mount_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
glibtop_mountentry *
|
glibtop_mountentry *
|
||||||
glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
|
glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
|
||||||
{
|
{
|
||||||
struct mount_entry *me, *tmp, *next;
|
struct mount_entry *me, *tmp, *next;
|
||||||
glibtop_mountentry *mount_list;
|
glibtop_mountentry *mount_list;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
glibtop_init_r (&server, 0, 0);
|
glibtop_init_r (&server, 0, 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_mountlist));
|
memset (buf, 0, sizeof (glibtop_mountlist));
|
||||||
|
|
||||||
/* Read filesystem list. */
|
/* Read filesystem list. */
|
||||||
|
|
||||||
me = read_filesystem_list (1, all_fs);
|
me = read_filesystem_list (1, all_fs);
|
||||||
|
|
||||||
if (me == NULL)
|
if (me == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Count entries. */
|
/* Count entries. */
|
||||||
|
|
||||||
for (count = 0, tmp = me; tmp; count++, tmp = tmp->me_next)
|
for (count = 0, tmp = me; tmp; count++, tmp = tmp->me_next)
|
||||||
;
|
;
|
||||||
|
|
||||||
buf->size = sizeof (glibtop_mountentry);
|
buf->size = sizeof (glibtop_mountentry);
|
||||||
buf->number = count;
|
buf->number = count;
|
||||||
|
|
||||||
buf->total = buf->number * buf->size;
|
buf->total = buf->number * buf->size;
|
||||||
|
|
||||||
mount_list = glibtop_malloc_r (server, buf->total);
|
mount_list = glibtop_malloc_r (server, buf->total);
|
||||||
|
|
||||||
/* Write data into mount_list. */
|
/* Write data into mount_list. */
|
||||||
|
|
||||||
for (count = 0, tmp = me; tmp; count++, tmp = tmp->me_next) {
|
for (count = 0, tmp = me; tmp; count++, tmp = tmp->me_next) {
|
||||||
strncpy (mount_list [count].devname, tmp->me_devname,
|
strncpy (mount_list [count].devname, tmp->me_devname,
|
||||||
GLIBTOP_MOUNTENTRY_LEN);
|
GLIBTOP_MOUNTENTRY_LEN);
|
||||||
strncpy (mount_list [count].mountdir, tmp->me_mountdir,
|
strncpy (mount_list [count].mountdir, tmp->me_mountdir,
|
||||||
GLIBTOP_MOUNTENTRY_LEN);
|
GLIBTOP_MOUNTENTRY_LEN);
|
||||||
strncpy (mount_list [count].type, tmp->me_type,
|
strncpy (mount_list [count].type, tmp->me_type,
|
||||||
GLIBTOP_MOUNTENTRY_LEN);
|
GLIBTOP_MOUNTENTRY_LEN);
|
||||||
mount_list [count].devname [GLIBTOP_MOUNTENTRY_LEN] = 0;
|
mount_list [count].devname [GLIBTOP_MOUNTENTRY_LEN] = 0;
|
||||||
mount_list [count].mountdir [GLIBTOP_MOUNTENTRY_LEN] = 0;
|
mount_list [count].mountdir [GLIBTOP_MOUNTENTRY_LEN] = 0;
|
||||||
mount_list [count].type [GLIBTOP_MOUNTENTRY_LEN] = 0;
|
mount_list [count].type [GLIBTOP_MOUNTENTRY_LEN] = 0;
|
||||||
mount_list [count].dev = tmp->me_dev;
|
mount_list [count].dev = tmp->me_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free memory. */
|
/* Free memory. */
|
||||||
|
|
||||||
for (count = 0, tmp = me; tmp; count++, tmp = next) {
|
for (count = 0, tmp = me; tmp; count++, tmp = next) {
|
||||||
next = tmp->me_next;
|
next = tmp->me_next;
|
||||||
xfree (tmp->me_devname);
|
xfree (tmp->me_devname);
|
||||||
xfree (tmp->me_mountdir);
|
xfree (tmp->me_mountdir);
|
||||||
xfree (tmp->me_type);
|
xfree (tmp->me_type);
|
||||||
xfree (tmp);
|
xfree (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mount_list;
|
return mount_list;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* mountlist.h -- declarations for list of mounted filesystems
|
/* mountlist.h -- declarations for list of mounted filesystems
|
||||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||||
|
|
||||||
@@ -18,10 +20,10 @@
|
|||||||
/* A mount table entry. */
|
/* A mount table entry. */
|
||||||
struct mount_entry
|
struct mount_entry
|
||||||
{
|
{
|
||||||
char *me_devname; /* Device node pathname, including "/dev/". */
|
char *me_devname; /* Device node pathname, including "/dev/". */
|
||||||
char *me_mountdir; /* Mount point directory pathname. */
|
char *me_mountdir; /* Mount point directory pathname. */
|
||||||
char *me_type; /* "nfs", "4.2", etc. */
|
char *me_type; /* "nfs", "4.2", etc. */
|
||||||
dev_t me_dev; /* Device number of me_mountdir. */
|
dev_t me_dev; /* Device number of me_mountdir. */
|
||||||
struct mount_entry *me_next;
|
struct mount_entry *me_next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -28,65 +30,65 @@
|
|||||||
|
|
||||||
glibtop_init_func_t _glibtop_init_hook_p [] = {
|
glibtop_init_func_t _glibtop_init_hook_p [] = {
|
||||||
#if GLIBTOP_SUID_CPU
|
#if GLIBTOP_SUID_CPU
|
||||||
glibtop_init_cpu_p,
|
glibtop_init_cpu_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_MEM
|
#if GLIBTOP_SUID_MEM
|
||||||
glibtop_init_mem_p,
|
glibtop_init_mem_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_SWAP
|
#if GLIBTOP_SUID_SWAP
|
||||||
glibtop_init_swap_p,
|
glibtop_init_swap_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_UPTIME
|
#if GLIBTOP_SUID_UPTIME
|
||||||
glibtop_init_uptime_p,
|
glibtop_init_uptime_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_LOADAVG
|
#if GLIBTOP_SUID_LOADAVG
|
||||||
glibtop_init_loadavg_p,
|
glibtop_init_loadavg_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_SHM_LIMITS
|
#if GLIBTOP_SUID_SHM_LIMITS
|
||||||
glibtop_init_shm_limits_p,
|
glibtop_init_shm_limits_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_MSG_LIMITS
|
#if GLIBTOP_SUID_MSG_LIMITS
|
||||||
glibtop_init_msg_limits_p,
|
glibtop_init_msg_limits_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_SEM_LIMITS
|
#if GLIBTOP_SUID_SEM_LIMITS
|
||||||
glibtop_init_sem_limits_p,
|
glibtop_init_sem_limits_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROCLIST
|
#if GLIBTOP_SUID_PROCLIST
|
||||||
glibtop_init_proclist_p,
|
glibtop_init_proclist_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_STATE
|
#if GLIBTOP_SUID_PROC_STATE
|
||||||
glibtop_init_proc_state_p,
|
glibtop_init_proc_state_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_UID
|
#if GLIBTOP_SUID_PROC_UID
|
||||||
glibtop_init_proc_uid_p,
|
glibtop_init_proc_uid_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_MEM
|
#if GLIBTOP_SUID_PROC_MEM
|
||||||
glibtop_init_proc_mem_p,
|
glibtop_init_proc_mem_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_TIME
|
#if GLIBTOP_SUID_PROC_TIME
|
||||||
glibtop_init_proc_time_p,
|
glibtop_init_proc_time_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_SIGNAL
|
#if GLIBTOP_SUID_PROC_SIGNAL
|
||||||
glibtop_init_proc_signal_p,
|
glibtop_init_proc_signal_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_KERNEL
|
#if GLIBTOP_SUID_PROC_KERNEL
|
||||||
glibtop_init_proc_kernel_p,
|
glibtop_init_proc_kernel_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_SEGMENT
|
#if GLIBTOP_SUID_PROC_SEGMENT
|
||||||
glibtop_init_proc_segment_p,
|
glibtop_init_proc_segment_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_ARGS
|
#if GLIBTOP_SUID_PROC_ARGS
|
||||||
glibtop_init_proc_args_p,
|
glibtop_init_proc_args_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PROC_MAP
|
#if GLIBTOP_SUID_PROC_MAP
|
||||||
glibtop_init_proc_map_p,
|
glibtop_init_proc_map_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_NETLOAD
|
#if GLIBTOP_SUID_NETLOAD
|
||||||
glibtop_init_netload_p,
|
glibtop_init_netload_p,
|
||||||
#endif
|
#endif
|
||||||
#if GLIBTOP_SUID_PPP
|
#if GLIBTOP_SUID_PPP
|
||||||
glibtop_init_ppp_p,
|
glibtop_init_ppp_p,
|
||||||
#endif
|
#endif
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -33,14 +35,14 @@ void *
|
|||||||
glibtop_malloc_r (glibtop *server, size_t size)
|
glibtop_malloc_r (glibtop *server, size_t size)
|
||||||
{
|
{
|
||||||
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
||||||
return g_malloc0 (size);
|
return g_malloc0 (size);
|
||||||
#else
|
#else
|
||||||
void *buf = malloc (size);
|
void *buf = malloc (size);
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
glibtop_error_io_r (server, "malloc %d bytes", size);
|
glibtop_error_io_r (server, "malloc %d bytes", size);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,15 +50,15 @@ void *
|
|||||||
glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
|
glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
||||||
return g_malloc0 (size * nmemb);
|
return g_malloc0 (size * nmemb);
|
||||||
#else
|
#else
|
||||||
void *buf = calloc (nmemb, size);
|
void *buf = calloc (nmemb, size);
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
glibtop_error_io_r (server, "calloc %d blocks (%d bytes each)",
|
glibtop_error_io_r (server, "calloc %d blocks (%d bytes each)",
|
||||||
nmemb, size);
|
nmemb, size);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,14 +66,14 @@ void *
|
|||||||
glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
|
glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
||||||
return g_realloc (ptr, size);
|
return g_realloc (ptr, size);
|
||||||
#else
|
#else
|
||||||
void *buf = realloc (ptr, size);
|
void *buf = realloc (ptr, size);
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
glibtop_error_io_r (server, "realloc %d bytes", size);
|
glibtop_error_io_r (server, "realloc %d bytes", size);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,9 +81,9 @@ char *
|
|||||||
glibtop_strdup_r (glibtop *server, const char *string)
|
glibtop_strdup_r (glibtop *server, const char *string)
|
||||||
{
|
{
|
||||||
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
||||||
return g_strdup (string);
|
return g_strdup (string);
|
||||||
#else
|
#else
|
||||||
return strcpy (glibtop_malloc_r (server, strlen (string) + 1), string);
|
return strcpy (glibtop_malloc_r (server, strlen (string) + 1), string);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,8 +91,8 @@ void
|
|||||||
glibtop_free_r (glibtop *server, const void *ptr)
|
glibtop_free_r (glibtop *server, const void *ptr)
|
||||||
{
|
{
|
||||||
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
#ifdef LIBGTOP_USE_GLIB_MALLOC
|
||||||
g_free (ptr);
|
g_free (ptr);
|
||||||
#else
|
#else
|
||||||
if (ptr) free ((void *) ptr);
|
if (ptr) free ((void *) ptr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -28,45 +30,45 @@
|
|||||||
void *
|
void *
|
||||||
glibtop_malloc_r (glibtop *server, size_t size)
|
glibtop_malloc_r (glibtop *server, size_t size)
|
||||||
{
|
{
|
||||||
void *buf = malloc (size);
|
void *buf = malloc (size);
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
glibtop_error_io_r (server, "malloc %d bytes", size);
|
glibtop_error_io_r (server, "malloc %d bytes", size);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
|
glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
void *buf = calloc (nmemb, size);
|
void *buf = calloc (nmemb, size);
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
glibtop_error_io_r (server, "calloc %d blocks (%d bytes each)",
|
glibtop_error_io_r (server, "calloc %d blocks (%d bytes each)",
|
||||||
nmemb, size);
|
nmemb, size);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
|
glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
void *buf = realloc (ptr, size);
|
void *buf = realloc (ptr, size);
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
glibtop_error_io_r (server, "realloc %d bytes", size);
|
glibtop_error_io_r (server, "realloc %d bytes", size);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
glibtop_strdup_r (glibtop *server, const char *string)
|
glibtop_strdup_r (glibtop *server, const char *string)
|
||||||
{
|
{
|
||||||
return strcpy (glibtop_malloc_r (server, strlen (string) + 1), string);
|
return strcpy (glibtop_malloc_r (server, strlen (string) + 1), string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_free_r (glibtop *server, const void *ptr)
|
glibtop_free_r (glibtop *server, const void *ptr)
|
||||||
{
|
{
|
||||||
if (ptr) free ((void *) ptr);
|
if (ptr) free ((void *) ptr);
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -35,11 +37,11 @@ static const unsigned long _glibtop_sysdeps_cpu =
|
|||||||
/* nlist structure for kernel access */
|
/* nlist structure for kernel access */
|
||||||
static struct nlist nlst [] = {
|
static struct nlist nlst [] = {
|
||||||
#ifdef __bsdi__
|
#ifdef __bsdi__
|
||||||
{ "_cpustats" },
|
{ "_cpustats" },
|
||||||
#else
|
#else
|
||||||
{ "_cp_time" },
|
{ "_cp_time" },
|
||||||
#endif
|
#endif
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* MIB array for sysctl */
|
/* MIB array for sysctl */
|
||||||
@@ -51,15 +53,15 @@ static int mib [] = { CTL_KERN, KERN_CLOCKRATE };
|
|||||||
int
|
int
|
||||||
glibtop_init_cpu_p (glibtop *server)
|
glibtop_init_cpu_p (glibtop *server)
|
||||||
{
|
{
|
||||||
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
||||||
glibtop_warn_io_r (server, "kvm_nlist (cpu)");
|
glibtop_warn_io_r (server, "kvm_nlist (cpu)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set this only if kvm_nlist () succeeded. */
|
/* Set this only if kvm_nlist () succeeded. */
|
||||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides information about cpu usage. */
|
/* Provides information about cpu usage. */
|
||||||
@@ -67,55 +69,55 @@ glibtop_init_cpu_p (glibtop *server)
|
|||||||
int
|
int
|
||||||
glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||||
{
|
{
|
||||||
long cpts [CPUSTATES];
|
long cpts [CPUSTATES];
|
||||||
/* sysctl vars*/
|
/* sysctl vars*/
|
||||||
struct clockinfo ci;
|
struct clockinfo ci;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_CPU), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_CPU), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_cpu));
|
memset (buf, 0, sizeof (glibtop_cpu));
|
||||||
|
|
||||||
/* If this fails, the nlist may not be valid. */
|
/* If this fails, the nlist may not be valid. */
|
||||||
if (server->sysdeps.cpu == 0)
|
if (server->sysdeps.cpu == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||||
&cpts, sizeof (cpts)) != sizeof (cpts)) {
|
&cpts, sizeof (cpts)) != sizeof (cpts)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (cp_time)");
|
glibtop_warn_io_r (server, "kvm_read (cp_time)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the clockrate data */
|
/* Get the clockrate data */
|
||||||
length = sizeof (struct clockinfo);
|
length = sizeof (struct clockinfo);
|
||||||
if (sysctl (mib, mib_length, &ci, &length, NULL, 0)) {
|
if (sysctl (mib, mib_length, &ci, &length, NULL, 0)) {
|
||||||
glibtop_warn_io_r (server, "sysctl");
|
glibtop_warn_io_r (server, "sysctl");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set user time */
|
/* set user time */
|
||||||
buf->user = cpts [CP_USER];
|
buf->user = cpts [CP_USER];
|
||||||
/* set nice time */
|
/* set nice time */
|
||||||
buf->nice = cpts [CP_NICE];
|
buf->nice = cpts [CP_NICE];
|
||||||
/* set sys time */
|
/* set sys time */
|
||||||
buf->sys = cpts [CP_SYS];
|
buf->sys = cpts [CP_SYS];
|
||||||
/* set idle time */
|
/* set idle time */
|
||||||
buf->idle = cpts [CP_IDLE];
|
buf->idle = cpts [CP_IDLE];
|
||||||
|
|
||||||
/* set frequency */
|
/* set frequency */
|
||||||
/*
|
/*
|
||||||
FIXME -- is hz, tick, profhz or stathz wanted?
|
FIXME -- is hz, tick, profhz or stathz wanted?
|
||||||
buf->frequency = sysctl("kern.clockrate", ...);
|
buf->frequency = sysctl("kern.clockrate", ...);
|
||||||
|
|
||||||
struct clockinfo
|
struct clockinfo
|
||||||
*/
|
*/
|
||||||
buf->frequency = ci.hz;
|
buf->frequency = ci.hz;
|
||||||
/* set total */
|
/* set total */
|
||||||
buf->total = cpts [CP_USER] + cpts [CP_NICE]
|
buf->total = cpts [CP_USER] + cpts [CP_NICE]
|
||||||
+ cpts [CP_SYS] + cpts [CP_IDLE];
|
+ cpts [CP_SYS] + cpts [CP_IDLE];
|
||||||
|
|
||||||
/* Set the flags last. */
|
/* Set the flags last. */
|
||||||
buf->flags = _glibtop_sysdeps_cpu;
|
buf->flags = _glibtop_sysdeps_cpu;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -45,13 +47,13 @@ typedef struct _glibtop_machine glibtop_machine;
|
|||||||
|
|
||||||
struct _glibtop_machine
|
struct _glibtop_machine
|
||||||
{
|
{
|
||||||
uid_t uid, euid;
|
uid_t uid, euid;
|
||||||
gid_t gid, egid;
|
gid_t gid, egid;
|
||||||
|
|
||||||
/* The kernel descriptor, used by kvm_* calls. We keep and re-use
|
/* The kernel descriptor, used by kvm_* calls. We keep and re-use
|
||||||
* it rather than re-getting it for almost all function
|
* it rather than re-getting it for almost all function
|
||||||
* invocations. */
|
* invocations. */
|
||||||
kvm_t *kd;
|
kvm_t *kd;
|
||||||
};
|
};
|
||||||
|
|
||||||
END_LIBGTOP_DECLS
|
END_LIBGTOP_DECLS
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -37,23 +39,23 @@ BEGIN_LIBGTOP_DECLS
|
|||||||
#define UREADOK(ki) (FORCEUREAD || (KI_PROC(ki)->p_flag & P_INMEM))
|
#define UREADOK(ki) (FORCEUREAD || (KI_PROC(ki)->p_flag & P_INMEM))
|
||||||
|
|
||||||
static inline void glibtop_suid_enter (glibtop *server) {
|
static inline void glibtop_suid_enter (glibtop *server) {
|
||||||
setregid (server->_priv->machine.gid,
|
setregid (server->_priv->machine.gid,
|
||||||
server->_priv->machine.egid);
|
server->_priv->machine.egid);
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void glibtop_suid_leave (glibtop *server) {
|
static inline void glibtop_suid_leave (glibtop *server) {
|
||||||
if (setregid (server->_priv->machine.egid,
|
if (setregid (server->_priv->machine.egid,
|
||||||
server->_priv->machine.gid))
|
server->_priv->machine.gid))
|
||||||
_exit (1);
|
_exit (1);
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_init_p (glibtop *server, const unsigned long features,
|
glibtop_init_p (glibtop *server, const unsigned long features,
|
||||||
const unsigned flags);
|
const unsigned 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 long features,
|
||||||
const unsigned flags);
|
const unsigned flags);
|
||||||
|
|
||||||
END_LIBGTOP_DECLS
|
END_LIBGTOP_DECLS
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -32,14 +34,14 @@ glibtop_init_r (glibtop **server,
|
|||||||
const unsigned long features,
|
const unsigned long features,
|
||||||
const unsigned flags)
|
const unsigned flags)
|
||||||
{
|
{
|
||||||
if (*server != NULL)
|
if (*server != NULL)
|
||||||
return *server;
|
return *server;
|
||||||
|
|
||||||
if (glibtop_global_server == NULL) {
|
if (glibtop_global_server == NULL) {
|
||||||
glibtop_global_server = &_glibtop_global_server;
|
glibtop_global_server = &_glibtop_global_server;
|
||||||
glibtop_open (glibtop_global_server, "glibtop",
|
glibtop_open (glibtop_global_server, "glibtop",
|
||||||
features, flags);
|
features, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return *server = glibtop_global_server;
|
return *server = glibtop_global_server;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -35,9 +37,9 @@ static const unsigned long _glibtop_sysdeps_loadavg =
|
|||||||
int
|
int
|
||||||
glibtop_init_loadavg_p (glibtop *server)
|
glibtop_init_loadavg_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
|
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides load averange. */
|
/* Provides load averange. */
|
||||||
@@ -45,20 +47,20 @@ glibtop_init_loadavg_p (glibtop *server)
|
|||||||
int
|
int
|
||||||
glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
|
glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
|
||||||
{
|
{
|
||||||
double ldavg[3];
|
double ldavg[3];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_LOADAVG), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_LOADAVG), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||||
|
|
||||||
getloadavg (ldavg, 3);
|
getloadavg (ldavg, 3);
|
||||||
|
|
||||||
/* fill in the struct */
|
/* fill in the struct */
|
||||||
buf->flags = _glibtop_sysdeps_loadavg;
|
buf->flags = _glibtop_sysdeps_loadavg;
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
buf->loadavg [i] = ldavg [i];
|
buf->loadavg [i] = ldavg [i];
|
||||||
} /* end for */
|
} /* end for */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -58,18 +60,18 @@ static int pageshift; /* log base 2 of the pagesize */
|
|||||||
/* nlist structure for kernel access */
|
/* nlist structure for kernel access */
|
||||||
static struct nlist nlst [] = {
|
static struct nlist nlst [] = {
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
{ "_bufpages" },
|
{ "_bufpages" },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
#else
|
#else
|
||||||
#if defined(__bsdi__)
|
#if defined(__bsdi__)
|
||||||
{ "_bufcachemem" },
|
{ "_bufcachemem" },
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
{ "_bufspace" },
|
{ "_bufspace" },
|
||||||
#else
|
#else
|
||||||
{ "_bufpages" },
|
{ "_bufpages" },
|
||||||
#endif
|
#endif
|
||||||
{ "_cnt" },
|
{ "_cnt" },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,137 +92,137 @@ static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
|
|||||||
int
|
int
|
||||||
glibtop_init_mem_p (glibtop *server)
|
glibtop_init_mem_p (glibtop *server)
|
||||||
{
|
{
|
||||||
register int pagesize;
|
register int pagesize;
|
||||||
|
|
||||||
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
||||||
glibtop_warn_io_r (server, "kvm_nlist (mem)");
|
glibtop_warn_io_r (server, "kvm_nlist (mem)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the page size with "getpagesize" and calculate pageshift
|
/* get the page size with "getpagesize" and calculate pageshift
|
||||||
* from it */
|
* from it */
|
||||||
pagesize = getpagesize ();
|
pagesize = getpagesize ();
|
||||||
pageshift = 0;
|
pageshift = 0;
|
||||||
while (pagesize > 1) {
|
while (pagesize > 1) {
|
||||||
pageshift++;
|
pageshift++;
|
||||||
pagesize >>= 1;
|
pagesize >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we only need the amount of log(2)1024 for our conversion */
|
/* we only need the amount of log(2)1024 for our conversion */
|
||||||
pageshift -= LOG1024;
|
pageshift -= LOG1024;
|
||||||
|
|
||||||
server->sysdeps.mem = _glibtop_sysdeps_mem;
|
server->sysdeps.mem = _glibtop_sysdeps_mem;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
||||||
{
|
{
|
||||||
struct vmtotal vmt;
|
struct vmtotal vmt;
|
||||||
size_t length_vmt;
|
size_t length_vmt;
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
struct uvmexp uvmexp;
|
struct uvmexp uvmexp;
|
||||||
size_t length_uvmexp;
|
size_t length_uvmexp;
|
||||||
#else
|
#else
|
||||||
struct vmmeter vmm;
|
struct vmmeter vmm;
|
||||||
#endif
|
#endif
|
||||||
u_int v_used_count;
|
u_int v_used_count;
|
||||||
u_int v_total_count;
|
u_int v_total_count;
|
||||||
u_int v_free_count;
|
u_int v_free_count;
|
||||||
int bufspace;
|
int bufspace;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MEM), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MEM), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_mem));
|
memset (buf, 0, sizeof (glibtop_mem));
|
||||||
|
|
||||||
if (server->sysdeps.mem == 0)
|
if (server->sysdeps.mem == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* [FIXME: On FreeBSD 2.2.6, sysctl () returns an incorrect
|
/* [FIXME: On FreeBSD 2.2.6, sysctl () returns an incorrect
|
||||||
* value for `vmt.vm'. We use some code from Unix top
|
* value for `vmt.vm'. We use some code from Unix top
|
||||||
* here.] */
|
* here.] */
|
||||||
|
|
||||||
/* Get the data from sysctl */
|
/* Get the data from sysctl */
|
||||||
length_vmt = sizeof (vmt);
|
length_vmt = sizeof (vmt);
|
||||||
if (sysctl (mib, 2, &vmt, &length_vmt, NULL, 0)) {
|
if (sysctl (mib, 2, &vmt, &length_vmt, NULL, 0)) {
|
||||||
glibtop_warn_io_r (server, "sysctl (vmt)");
|
glibtop_warn_io_r (server, "sysctl (vmt)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
length_uvmexp = sizeof (uvmexp);
|
length_uvmexp = sizeof (uvmexp);
|
||||||
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
|
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
|
||||||
glibtop_warn_io_r (server, "sysctl (uvmexp)");
|
glibtop_warn_io_r (server, "sysctl (uvmexp)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* Get the data from kvm_* */
|
/* Get the data from kvm_* */
|
||||||
if (kvm_read (server->_priv->machine.kd, nlst[1].n_value,
|
if (kvm_read (server->_priv->machine.kd, nlst[1].n_value,
|
||||||
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd, nlst[0].n_value,
|
if (kvm_read (server->_priv->machine.kd, nlst[0].n_value,
|
||||||
&bufspace, sizeof (bufspace)) != sizeof (bufspace)) {
|
&bufspace, sizeof (bufspace)) != sizeof (bufspace)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (bufspace)");
|
glibtop_warn_io_r (server, "kvm_read (bufspace)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert memory stats to Kbytes */
|
/* convert memory stats to Kbytes */
|
||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
v_total_count = vmm.v_page_count;
|
v_total_count = vmm.v_page_count;
|
||||||
#else
|
#else
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
v_total_count = uvmexp.reserve_kernel +
|
v_total_count = uvmexp.reserve_kernel +
|
||||||
uvmexp.reserve_pagedaemon +
|
uvmexp.reserve_pagedaemon +
|
||||||
uvmexp.free + uvmexp.wired + uvmexp.active +
|
uvmexp.free + uvmexp.wired + uvmexp.active +
|
||||||
uvmexp.inactive;
|
uvmexp.inactive;
|
||||||
#else
|
#else
|
||||||
v_total_count = vmm.v_kernel_pages +
|
v_total_count = vmm.v_kernel_pages +
|
||||||
vmm.v_free_count + vmm.v_wire_count +
|
vmm.v_free_count + vmm.v_wire_count +
|
||||||
vmm.v_active_count + vmm.v_inactive_count;
|
vmm.v_active_count + vmm.v_inactive_count;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
v_used_count = uvmexp.active + uvmexp.inactive;
|
v_used_count = uvmexp.active + uvmexp.inactive;
|
||||||
v_free_count = uvmexp.free;
|
v_free_count = uvmexp.free;
|
||||||
#else
|
#else
|
||||||
v_used_count = vmm.v_active_count + vmm.v_inactive_count;
|
v_used_count = vmm.v_active_count + vmm.v_inactive_count;
|
||||||
v_free_count = vmm.v_free_count;
|
v_free_count = vmm.v_free_count;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buf->total = (u_int64_t) pagetok (v_total_count) << LOG1024;
|
buf->total = (u_int64_t) pagetok (v_total_count) << LOG1024;
|
||||||
buf->used = (u_int64_t) pagetok (v_used_count) << LOG1024;
|
buf->used = (u_int64_t) pagetok (v_used_count) << LOG1024;
|
||||||
buf->free = (u_int64_t) pagetok (v_free_count) << LOG1024;
|
buf->free = (u_int64_t) pagetok (v_free_count) << LOG1024;
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
buf->cached = (u_int64_t) pagetok (vmm.v_cache_count) << LOG1024;
|
buf->cached = (u_int64_t) pagetok (vmm.v_cache_count) << LOG1024;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
buf->locked = (u_int64_t) pagetok (uvmexp.wired) << LOG1024;
|
buf->locked = (u_int64_t) pagetok (uvmexp.wired) << LOG1024;
|
||||||
#else
|
#else
|
||||||
buf->locked = (u_int64_t) pagetok (vmm.v_wire_count) << LOG1024;
|
buf->locked = (u_int64_t) pagetok (vmm.v_wire_count) << LOG1024;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buf->shared = (u_int64_t) pagetok (vmt.t_rmshr) << LOG1024;
|
buf->shared = (u_int64_t) pagetok (vmt.t_rmshr) << LOG1024;
|
||||||
|
|
||||||
#if __FreeBSD__
|
#if __FreeBSD__
|
||||||
buf->buffer = (u_int64_t) bufspace;
|
buf->buffer = (u_int64_t) bufspace;
|
||||||
#else
|
#else
|
||||||
buf->buffer = (u_int64_t) pagetok (bufspace) << LOG1024;
|
buf->buffer = (u_int64_t) pagetok (bufspace) << LOG1024;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* user */
|
/* user */
|
||||||
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
|
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
|
||||||
|
|
||||||
/* Set the values to return */
|
/* Set the values to return */
|
||||||
buf->flags = _glibtop_sysdeps_mem;
|
buf->flags = _glibtop_sysdeps_mem;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -33,17 +35,17 @@
|
|||||||
int
|
int
|
||||||
glibtop_init_msg_limits_p (glibtop *server)
|
glibtop_init_msg_limits_p (glibtop *server)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
||||||
{
|
{
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_msg_limits));
|
memset (buf, 0, sizeof (glibtop_msg_limits));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -71,8 +73,8 @@ static struct msginfo _msginfo;
|
|||||||
|
|
||||||
/* nlist structure for kernel access */
|
/* nlist structure for kernel access */
|
||||||
static struct nlist nlst [] = {
|
static struct nlist nlst [] = {
|
||||||
{ "_msginfo" },
|
{ "_msginfo" },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Init function. */
|
/* Init function. */
|
||||||
@@ -80,20 +82,20 @@ static struct nlist nlst [] = {
|
|||||||
int
|
int
|
||||||
glibtop_init_msg_limits_p (glibtop *server)
|
glibtop_init_msg_limits_p (glibtop *server)
|
||||||
{
|
{
|
||||||
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
||||||
glibtop_warn_io_r (server, "kvm_nlist (msg_limits)");
|
glibtop_warn_io_r (server, "kvm_nlist (msg_limits)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||||
&_msginfo, sizeof (_msginfo)) != sizeof (_msginfo)) {
|
&_msginfo, sizeof (_msginfo)) != sizeof (_msginfo)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (msginfo)");
|
glibtop_warn_io_r (server, "kvm_read (msginfo)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
|
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides information about sysv ipc limits. */
|
/* Provides information about sysv ipc limits. */
|
||||||
@@ -101,22 +103,22 @@ glibtop_init_msg_limits_p (glibtop *server)
|
|||||||
int
|
int
|
||||||
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
||||||
{
|
{
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_msg_limits));
|
memset (buf, 0, sizeof (glibtop_msg_limits));
|
||||||
|
|
||||||
if (server->sysdeps.msg_limits == 0)
|
if (server->sysdeps.msg_limits == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
buf->msgmax = _msginfo.msgmax;
|
buf->msgmax = _msginfo.msgmax;
|
||||||
buf->msgmni = _msginfo.msgmni;
|
buf->msgmni = _msginfo.msgmni;
|
||||||
buf->msgmnb = _msginfo.msgmnb;
|
buf->msgmnb = _msginfo.msgmnb;
|
||||||
buf->msgtql = _msginfo.msgtql;
|
buf->msgtql = _msginfo.msgtql;
|
||||||
buf->msgssz = _msginfo.msgtql;
|
buf->msgssz = _msginfo.msgtql;
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_msg_limits;
|
buf->flags = _glibtop_sysdeps_msg_limits;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* either a newer BSDI or no BSDI at all. */
|
#endif /* either a newer BSDI or no BSDI at all. */
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -60,7 +62,7 @@ glibtop_init_netinfo_p (glibtop *server)
|
|||||||
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0)
|
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0)
|
||||||
glibtop_error_io_r (server, "kvm_nlist");
|
glibtop_error_io_r (server, "kvm_nlist");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides Network statistics. */
|
/* Provides Network statistics. */
|
||||||
@@ -97,12 +99,12 @@ glibtop_get_netinfo_p (glibtop *server, glibtop_netinfo *buf,
|
|||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd, ifnetaddr, &ifnet,
|
if (kvm_read (server->_priv->machine.kd, ifnetaddr, &ifnet,
|
||||||
sizeof (ifnet)) != sizeof (ifnet))
|
sizeof (ifnet)) != sizeof (ifnet))
|
||||||
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
|
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||||
if (kvm_read (server->_priv->machine.kd, (u_long) ifnet.if_name,
|
if (kvm_read (server->_priv->machine.kd, (u_long) ifnet.if_name,
|
||||||
tname, 16) != 16)
|
tname, 16) != 16)
|
||||||
glibtop_error_io_r (server, "kvm_read (if_name)");
|
glibtop_error_io_r (server, "kvm_read (if_name)");
|
||||||
#else
|
#else
|
||||||
strncpy (tname, ifnet.if_xname, 16);
|
strncpy (tname, ifnet.if_xname, 16);
|
||||||
tname [15] = 0;
|
tname [15] = 0;
|
||||||
@@ -130,39 +132,39 @@ glibtop_get_netinfo_p (glibtop *server, glibtop_netinfo *buf,
|
|||||||
sin = (struct sockaddr_in *)sa;
|
sin = (struct sockaddr_in *)sa;
|
||||||
|
|
||||||
if (ifnet.if_flags & IFF_UP)
|
if (ifnet.if_flags & IFF_UP)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_UP;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_UP;
|
||||||
if (ifnet.if_flags & IFF_BROADCAST)
|
if (ifnet.if_flags & IFF_BROADCAST)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_BROADCAST;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_BROADCAST;
|
||||||
if (ifnet.if_flags & IFF_DEBUG)
|
if (ifnet.if_flags & IFF_DEBUG)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_DEBUG;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_DEBUG;
|
||||||
if (ifnet.if_flags & IFF_LOOPBACK)
|
if (ifnet.if_flags & IFF_LOOPBACK)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LOOPBACK;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_LOOPBACK;
|
||||||
if (ifnet.if_flags & IFF_POINTOPOINT)
|
if (ifnet.if_flags & IFF_POINTOPOINT)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_POINTOPOINT;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_POINTOPOINT;
|
||||||
if (ifnet.if_flags & IFF_RUNNING)
|
if (ifnet.if_flags & IFF_RUNNING)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_RUNNING;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_RUNNING;
|
||||||
if (ifnet.if_flags & IFF_NOARP)
|
if (ifnet.if_flags & IFF_NOARP)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_NOARP;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_NOARP;
|
||||||
if (ifnet.if_flags & IFF_PROMISC)
|
if (ifnet.if_flags & IFF_PROMISC)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_PROMISC;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_PROMISC;
|
||||||
if (ifnet.if_flags & IFF_ALLMULTI)
|
if (ifnet.if_flags & IFF_ALLMULTI)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_ALLMULTI;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_ALLMULTI;
|
||||||
if (ifnet.if_flags & IFF_OACTIVE)
|
if (ifnet.if_flags & IFF_OACTIVE)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_OACTIVE;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_OACTIVE;
|
||||||
if (ifnet.if_flags & IFF_SIMPLEX)
|
if (ifnet.if_flags & IFF_SIMPLEX)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_SIMPLEX;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_SIMPLEX;
|
||||||
if (ifnet.if_flags & IFF_LINK0)
|
if (ifnet.if_flags & IFF_LINK0)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK0;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK0;
|
||||||
if (ifnet.if_flags & IFF_LINK1)
|
if (ifnet.if_flags & IFF_LINK1)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK1;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK1;
|
||||||
if (ifnet.if_flags & IFF_LINK2)
|
if (ifnet.if_flags & IFF_LINK2)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK2;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK2;
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
if (ifnet.if_flags & IFF_ALTPHYS)
|
if (ifnet.if_flags & IFF_ALTPHYS)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_ALTPHYS;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_ALTPHYS;
|
||||||
#endif
|
#endif
|
||||||
if (ifnet.if_flags & IFF_MULTICAST)
|
if (ifnet.if_flags & IFF_MULTICAST)
|
||||||
buf->if_flags |= GLIBTOP_IF_FLAGS_MULTICAST;
|
buf->if_flags |= GLIBTOP_IF_FLAGS_MULTICAST;
|
||||||
|
|
||||||
buf->subnet = htonl (ifaddr.in.ia_subnet);
|
buf->subnet = htonl (ifaddr.in.ia_subnet);
|
||||||
buf->address = sin->sin_addr.s_addr;
|
buf->address = sin->sin_addr.s_addr;
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -66,7 +68,7 @@ glibtop_init_netload_p (glibtop *server)
|
|||||||
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0)
|
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0)
|
||||||
glibtop_error_io_r (server, "kvm_nlist");
|
glibtop_error_io_r (server, "kvm_nlist");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides Network statistics. */
|
/* Provides Network statistics. */
|
||||||
@@ -104,12 +106,12 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
|||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd, ifnetaddr, &ifnet,
|
if (kvm_read (server->_priv->machine.kd, ifnetaddr, &ifnet,
|
||||||
sizeof (ifnet)) != sizeof (ifnet))
|
sizeof (ifnet)) != sizeof (ifnet))
|
||||||
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
|
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||||
if (kvm_read (server->_priv->machine.kd, (u_long) ifnet.if_name,
|
if (kvm_read (server->_priv->machine.kd, (u_long) ifnet.if_name,
|
||||||
tname, 16) != 16)
|
tname, 16) != 16)
|
||||||
glibtop_error_io_r (server, "kvm_read (if_name)");
|
glibtop_error_io_r (server, "kvm_read (if_name)");
|
||||||
#else
|
#else
|
||||||
strncpy (tname, ifnet.if_xname, 16);
|
strncpy (tname, ifnet.if_xname, 16);
|
||||||
tname [15] = 0;
|
tname [15] = 0;
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -31,21 +33,21 @@ void
|
|||||||
glibtop_init_p (glibtop *server, const unsigned long features,
|
glibtop_init_p (glibtop *server, const unsigned long features,
|
||||||
const unsigned flags)
|
const unsigned flags)
|
||||||
{
|
{
|
||||||
glibtop_init_func_t *init_fkt;
|
glibtop_init_func_t *init_fkt;
|
||||||
|
|
||||||
if (server == NULL)
|
if (server == NULL)
|
||||||
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
|
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
|
||||||
|
|
||||||
/* Do the initialization, but only if not already initialized. */
|
/* Do the initialization, but only if not already initialized. */
|
||||||
|
|
||||||
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
|
if ((server->flags & _GLIBTOP_INIT_STATE_SYSDEPS) == 0) {
|
||||||
glibtop_open_p (server, "glibtop", features, flags);
|
glibtop_open_p (server, "glibtop", features, flags);
|
||||||
|
|
||||||
for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
|
for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
|
||||||
(*init_fkt) (server);
|
(*init_fkt) (server);
|
||||||
|
|
||||||
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
|
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -54,45 +56,45 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
|||||||
const unsigned flags)
|
const unsigned flags)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "DEBUG (%d): glibtop_open_p ()\n", getpid ());
|
fprintf (stderr, "DEBUG (%d): glibtop_open_p ()\n", getpid ());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||||
|
|
||||||
server->_priv->machine.uid = getuid ();
|
server->_priv->machine.uid = getuid ();
|
||||||
server->_priv->machine.euid = geteuid ();
|
server->_priv->machine.euid = geteuid ();
|
||||||
server->_priv->machine.gid = getgid ();
|
server->_priv->machine.gid = getgid ();
|
||||||
server->_priv->machine.egid = getegid ();
|
server->_priv->machine.egid = getegid ();
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
server->os_version_code = __FreeBSD_version;
|
server->os_version_code = __FreeBSD_version;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Setup machine-specific data */
|
/* Setup machine-specific data */
|
||||||
server->_priv->machine.kd = kvm_open
|
server->_priv->machine.kd = kvm_open
|
||||||
(NULL, NULL, NULL, O_RDONLY, "kvm_open");
|
(NULL, NULL, NULL, O_RDONLY, "kvm_open");
|
||||||
|
|
||||||
if (server->_priv->machine.kd == NULL)
|
if (server->_priv->machine.kd == NULL)
|
||||||
glibtop_error_io_r (server, "kvm_open");
|
glibtop_error_io_r (server, "kvm_open");
|
||||||
|
|
||||||
/* Drop priviledges. */
|
/* Drop priviledges. */
|
||||||
|
|
||||||
if (setreuid (server->_priv->machine.euid,
|
if (setreuid (server->_priv->machine.euid,
|
||||||
server->_priv->machine.uid))
|
server->_priv->machine.uid))
|
||||||
_exit (1);
|
_exit (1);
|
||||||
|
|
||||||
if (setregid (server->_priv->machine.egid,
|
if (setregid (server->_priv->machine.egid,
|
||||||
server->_priv->machine.gid))
|
server->_priv->machine.gid))
|
||||||
_exit (1);
|
_exit (1);
|
||||||
|
|
||||||
/* !!! END OF SUID ROOT PART !!! */
|
/* !!! END OF SUID ROOT PART !!! */
|
||||||
|
|
||||||
/* Our effective uid is now those of the user invoking the server,
|
/* Our effective uid is now those of the user invoking the server,
|
||||||
* so we do no longer have any priviledges. */
|
* so we do no longer have any priviledges. */
|
||||||
|
|
||||||
/* NOTE: On FreeBSD, we do not need to be suid root, we just need to
|
/* NOTE: On FreeBSD, we do not need to be suid root, we just need to
|
||||||
* be sgid kmem.
|
* be sgid kmem.
|
||||||
*
|
*
|
||||||
* The server will only use setegid() to get back it's priviledges,
|
* The server will only use setegid() to get back it's priviledges,
|
||||||
* so it will fail if it is suid root and not sgid kmem. */
|
* so it will fail if it is suid root and not sgid kmem. */
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -63,9 +65,9 @@ static const unsigned long _glibtop_sysdeps_ppp_acct =
|
|||||||
/* nlist structure for kernel access */
|
/* nlist structure for kernel access */
|
||||||
static struct nlist nlst [] = {
|
static struct nlist nlst [] = {
|
||||||
#ifdef HAVE_I4B
|
#ifdef HAVE_I4B
|
||||||
{ "_i4bisppp_softc" },
|
{ "_i4bisppp_softc" },
|
||||||
#endif
|
#endif
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Init function. */
|
/* Init function. */
|
||||||
@@ -75,17 +77,17 @@ glibtop_init_ppp_p (glibtop *server)
|
|||||||
{
|
{
|
||||||
#ifdef HAVE_I4B
|
#ifdef HAVE_I4B
|
||||||
#ifdef HAVE_I4B_ACCT
|
#ifdef HAVE_I4B_ACCT
|
||||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp |
|
server->sysdeps.ppp = _glibtop_sysdeps_ppp |
|
||||||
_glibtop_sysdeps_ppp_acct;
|
_glibtop_sysdeps_ppp_acct;
|
||||||
#else
|
#else
|
||||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_I4B */
|
#endif /* HAVE_I4B */
|
||||||
|
|
||||||
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0)
|
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0)
|
||||||
glibtop_error_io_r (server, "kvm_nlist");
|
glibtop_error_io_r (server, "kvm_nlist");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides information about ppp usage. */
|
/* Provides information about ppp usage. */
|
||||||
@@ -95,54 +97,54 @@ glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device)
|
|||||||
{
|
{
|
||||||
#ifdef HAVE_I4B
|
#ifdef HAVE_I4B
|
||||||
#ifdef HAVE_I4B_ACCT
|
#ifdef HAVE_I4B_ACCT
|
||||||
struct i4bisppp_softc data;
|
struct i4bisppp_softc data;
|
||||||
#else
|
#else
|
||||||
struct sppp data;
|
struct sppp data;
|
||||||
#endif
|
#endif
|
||||||
int phase;
|
int phase;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PPP), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PPP), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_ppp));
|
memset (buf, 0, sizeof (glibtop_ppp));
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||||
&data, sizeof (data)) != sizeof (data))
|
&data, sizeof (data)) != sizeof (data))
|
||||||
glibtop_error_io_r (server, "kvm_read (i4bisppp_softc)");
|
glibtop_error_io_r (server, "kvm_read (i4bisppp_softc)");
|
||||||
|
|
||||||
#ifdef HAVE_I4B_ACCT
|
#ifdef HAVE_I4B_ACCT
|
||||||
phase = data.sc_if_un.scu_sp.pp_phase;
|
phase = data.sc_if_un.scu_sp.pp_phase;
|
||||||
#else
|
#else
|
||||||
/* FIXME: Which FreeBSD version have this field and
|
/* FIXME: Which FreeBSD version have this field and
|
||||||
* which not. */
|
* which not. */
|
||||||
#if 0
|
#if 0
|
||||||
phase = data.pp_phase;
|
phase = data.pp_phase;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
#ifdef HAVE_I4B_ACCT
|
#ifdef HAVE_I4B_ACCT
|
||||||
case PHASE_DEAD:
|
case PHASE_DEAD:
|
||||||
case PHASE_TERMINATE:
|
case PHASE_TERMINATE:
|
||||||
buf->state = GLIBTOP_PPP_STATE_HANGUP;
|
buf->state = GLIBTOP_PPP_STATE_HANGUP;
|
||||||
break;
|
break;
|
||||||
case PHASE_ESTABLISH:
|
case PHASE_ESTABLISH:
|
||||||
case PHASE_NETWORK:
|
case PHASE_NETWORK:
|
||||||
buf->state = GLIBTOP_PPP_STATE_ONLINE;
|
buf->state = GLIBTOP_PPP_STATE_ONLINE;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
buf->state = GLIBTOP_PPP_STATE_UNKNOWN;
|
buf->state = GLIBTOP_PPP_STATE_UNKNOWN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_ppp;
|
buf->flags = _glibtop_sysdeps_ppp;
|
||||||
|
|
||||||
#ifdef HAVE_I4B_ACCT
|
#ifdef HAVE_I4B_ACCT
|
||||||
buf->bytes_in = data.sc_inb;
|
buf->bytes_in = data.sc_inb;
|
||||||
buf->bytes_out = data.sc_outb;
|
buf->bytes_out = data.sc_outb;
|
||||||
buf->flags |= _glibtop_sysdeps_ppp_acct;
|
buf->flags |= _glibtop_sysdeps_ppp_acct;
|
||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_I4B */
|
#endif /* HAVE_I4B */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -40,9 +42,9 @@ static const unsigned long _glibtop_sysdeps_proc_args =
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_args_p (glibtop *server)
|
glibtop_init_proc_args_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
|
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -50,64 +52,64 @@ glibtop_init_proc_args_p (glibtop *server)
|
|||||||
char **
|
char **
|
||||||
glibtop_get_proc_args_p (glibtop *server, glibtop_array *buf, pid_t pid)
|
glibtop_get_proc_args_p (glibtop *server, glibtop_array *buf, pid_t pid)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
char *retval, **args, **ptr;
|
char *retval, **args, **ptr;
|
||||||
unsigned size = 0, pos = 0;
|
unsigned size = 0, pos = 0;
|
||||||
int max_len = BUFSIZ, count;
|
int max_len = BUFSIZ, count;
|
||||||
|
|
||||||
#ifndef __bsdi__
|
#ifndef __bsdi__
|
||||||
char filename [BUFSIZ];
|
char filename [BUFSIZ];
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_ARGS), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_ARGS), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_args));
|
memset (buf, 0, sizeof (glibtop_proc_args));
|
||||||
|
|
||||||
/* swapper, init, pagedaemon, vmdaemon, update - this doen't work. */
|
/* swapper, init, pagedaemon, vmdaemon, update - this doen't work. */
|
||||||
if (pid < 5) return NULL;
|
if (pid < 5) return NULL;
|
||||||
|
|
||||||
#ifndef __bsdi__
|
#ifndef __bsdi__
|
||||||
sprintf (filename, "/proc/%d/mem", pid);
|
sprintf (filename, "/proc/%d/mem", pid);
|
||||||
if (stat (filename, &statb)) return NULL;
|
if (stat (filename, &statb)) return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glibtop_suid_enter (server);
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
/* Get the process data */
|
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
|
||||||
KERN_PROC_PID, pid, &count);
|
|
||||||
if ((pinfo == NULL) || (count < 1)) {
|
|
||||||
glibtop_suid_leave (server);
|
|
||||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
args = kvm_getargv (server->_priv->machine.kd, pinfo, max_len);
|
|
||||||
if (args == NULL) {
|
|
||||||
glibtop_suid_leave (server);
|
|
||||||
glibtop_warn_io_r (server, "kvm_getargv (%d)", pid);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Get the process data */
|
||||||
|
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||||
|
KERN_PROC_PID, pid, &count);
|
||||||
|
if ((pinfo == NULL) || (count < 1)) {
|
||||||
glibtop_suid_leave (server);
|
glibtop_suid_leave (server);
|
||||||
|
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (ptr = args; *ptr; ptr++)
|
args = kvm_getargv (server->_priv->machine.kd, pinfo, max_len);
|
||||||
size += strlen (*ptr)+1;
|
if (args == NULL) {
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
glibtop_warn_io_r (server, "kvm_getargv (%d)", pid);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
size += 2;
|
glibtop_suid_leave (server);
|
||||||
retval = glibtop_malloc_r (server, size);
|
|
||||||
memset (retval, 0, size);
|
|
||||||
|
|
||||||
for (ptr = args; *ptr; ptr++) {
|
for (ptr = args; *ptr; ptr++)
|
||||||
int len = strlen (*ptr)+1;
|
size += strlen (*ptr)+1;
|
||||||
memcpy (retval+pos, *ptr, len);
|
|
||||||
pos += len;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf->size = pos ? pos-1 : 0;
|
size += 2;
|
||||||
|
retval = glibtop_malloc_r (server, size);
|
||||||
|
memset (retval, 0, size);
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_proc_args;
|
for (ptr = args; *ptr; ptr++) {
|
||||||
|
int len = strlen (*ptr)+1;
|
||||||
|
memcpy (retval+pos, *ptr, len);
|
||||||
|
pos += len;
|
||||||
|
}
|
||||||
|
|
||||||
return retval;
|
buf->size = pos ? pos-1 : 0;
|
||||||
|
|
||||||
|
buf->flags = _glibtop_sysdeps_proc_args;
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -82,99 +84,99 @@ BIT_SHIFT(GLIBTOP_PROCDATA_WCHAN);
|
|||||||
void
|
void
|
||||||
glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
|
glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
|
||||||
{
|
{
|
||||||
char input [BUFSIZ], *tmp;
|
char input [BUFSIZ], *tmp;
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
int nread;
|
int nread;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
glibtop_init_r (&server, 0, 0);
|
glibtop_init_r (&server, 0, 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_procdata));
|
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);
|
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
/* Client is only interested in the flags. */
|
||||||
buf->flags [0] = _glibtop_sysdeps_procdata_0;
|
buf->flags [0] = _glibtop_sysdeps_procdata_0;
|
||||||
buf->flags [1] = _glibtop_sysdeps_procdata_1;
|
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;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -67,11 +69,11 @@ static const unsigned long _glibtop_sysdeps_proc_kernel_wchan =
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_kernel_p (glibtop *server)
|
glibtop_init_proc_kernel_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel_pstats |
|
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel_pstats |
|
||||||
_glibtop_sysdeps_proc_kernel_pcb |
|
_glibtop_sysdeps_proc_kernel_pcb |
|
||||||
_glibtop_sysdeps_proc_kernel_wchan;
|
_glibtop_sysdeps_proc_kernel_wchan;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -79,111 +81,111 @@ glibtop_get_proc_kernel_p (glibtop *server,
|
|||||||
glibtop_proc_kernel *buf,
|
glibtop_proc_kernel *buf,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
struct user *u_addr = (struct user *)USRSTACK;
|
struct user *u_addr = (struct user *)USRSTACK;
|
||||||
struct pstats pstats;
|
struct pstats pstats;
|
||||||
struct pcb pcb;
|
struct pcb pcb;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
char filename [BUFSIZ];
|
char filename [BUFSIZ];
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_KERNEL), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_KERNEL), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||||
|
|
||||||
if (server->sysdeps.proc_time == 0)
|
if (server->sysdeps.proc_time == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* It does not work for the swapper task. */
|
/* It does not work for the swapper task. */
|
||||||
if (pid == 0) return -1;
|
if (pid == 0) return -1;
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||||
KERN_PROC_PID, pid, &count);
|
KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1))
|
if ((pinfo == NULL) || (count != 1))
|
||||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
|
|
||||||
buf->nwchan = (unsigned long) pinfo [0].kp_proc.p_wchan &~ KERNBASE;
|
buf->nwchan = (unsigned long) pinfo [0].kp_proc.p_wchan &~ KERNBASE;
|
||||||
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_NWCHAN);
|
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_NWCHAN);
|
||||||
|
|
||||||
if (pinfo [0].kp_proc.p_wchan && pinfo [0].kp_proc.p_wmesg) {
|
if (pinfo [0].kp_proc.p_wchan && pinfo [0].kp_proc.p_wmesg) {
|
||||||
strncpy (buf->wchan, pinfo [0].kp_eproc.e_wmesg,
|
strncpy (buf->wchan, pinfo [0].kp_eproc.e_wmesg,
|
||||||
sizeof (buf->wchan) - 1);
|
sizeof (buf->wchan) - 1);
|
||||||
buf->wchan [sizeof (buf->wchan) - 1] = 0;
|
buf->wchan [sizeof (buf->wchan) - 1] = 0;
|
||||||
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_WCHAN);
|
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_WCHAN);
|
||||||
} else {
|
} else {
|
||||||
buf->wchan [0] = 0;
|
buf->wchan [0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Taken from `saveuser ()' in `/usr/src/bin/ps/ps.c'. */
|
||||||
|
|
||||||
|
/* [FIXME]: /usr/include/sys/user.h tells me that the user area
|
||||||
|
* may or may not be at the same kernel address in all
|
||||||
|
* processes, but I don't see any way to get that address.
|
||||||
|
* Since `ps' simply uses its own address, I think it's
|
||||||
|
* safe to do this here, too. */
|
||||||
|
|
||||||
|
/* NOTE: You need to mount the /proc filesystem to make
|
||||||
|
* `kvm_uread' work. */
|
||||||
|
|
||||||
|
sprintf (filename, "/proc/%d/mem", (int) pid);
|
||||||
|
if (stat (filename, &statb)) return -1;
|
||||||
|
|
||||||
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
|
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||||
|
kvm_uread (server->_priv->machine.kd, &(pinfo [0]).kp_proc,
|
||||||
|
(unsigned long) &u_addr->u_stats,
|
||||||
|
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* The u-area might be swapped out, and we can't get
|
||||||
|
* at it because we have a crashdump and no swap.
|
||||||
|
* If it's here fill in these fields, otherwise, just
|
||||||
|
* leave them 0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
buf->min_flt = (u_int64_t) pstats.p_ru.ru_minflt;
|
||||||
|
buf->maj_flt = (u_int64_t) pstats.p_ru.ru_majflt;
|
||||||
|
buf->cmin_flt = (u_int64_t) pstats.p_cru.ru_minflt;
|
||||||
|
buf->cmaj_flt = (u_int64_t) pstats.p_cru.ru_majflt;
|
||||||
|
|
||||||
|
buf->flags |= _glibtop_sysdeps_proc_kernel_pstats;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Taken from `saveuser ()' in `/usr/src/bin/ps/ps.c'. */
|
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||||
|
kvm_uread (server->_priv->machine.kd, &(pinfo [0]).kp_proc,
|
||||||
/* [FIXME]: /usr/include/sys/user.h tells me that the user area
|
(unsigned long) &u_addr->u_pcb,
|
||||||
* may or may not be at the same kernel address in all
|
(char *) &pcb, sizeof (pcb)) == sizeof (pcb))
|
||||||
* processes, but I don't see any way to get that address.
|
{
|
||||||
* Since `ps' simply uses its own address, I think it's
|
|
||||||
* safe to do this here, too. */
|
|
||||||
|
|
||||||
/* NOTE: You need to mount the /proc filesystem to make
|
|
||||||
* `kvm_uread' work. */
|
|
||||||
|
|
||||||
sprintf (filename, "/proc/%d/mem", (int) pid);
|
|
||||||
if (stat (filename, &statb)) return -1;
|
|
||||||
|
|
||||||
glibtop_suid_enter (server);
|
|
||||||
|
|
||||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
|
||||||
kvm_uread (server->_priv->machine.kd, &(pinfo [0]).kp_proc,
|
|
||||||
(unsigned long) &u_addr->u_stats,
|
|
||||||
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* The u-area might be swapped out, and we can't get
|
|
||||||
* at it because we have a crashdump and no swap.
|
|
||||||
* If it's here fill in these fields, otherwise, just
|
|
||||||
* leave them 0.
|
|
||||||
*/
|
|
||||||
|
|
||||||
buf->min_flt = (u_int64_t) pstats.p_ru.ru_minflt;
|
|
||||||
buf->maj_flt = (u_int64_t) pstats.p_ru.ru_majflt;
|
|
||||||
buf->cmin_flt = (u_int64_t) pstats.p_cru.ru_minflt;
|
|
||||||
buf->cmaj_flt = (u_int64_t) pstats.p_cru.ru_majflt;
|
|
||||||
|
|
||||||
buf->flags |= _glibtop_sysdeps_proc_kernel_pstats;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
|
||||||
kvm_uread (server->_priv->machine.kd, &(pinfo [0]).kp_proc,
|
|
||||||
(unsigned long) &u_addr->u_pcb,
|
|
||||||
(char *) &pcb, sizeof (pcb)) == sizeof (pcb))
|
|
||||||
{
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#ifndef __alpha__
|
#ifndef __alpha__
|
||||||
#if (__FreeBSD_version >= 300003)
|
#if (__FreeBSD_version >= 300003)
|
||||||
buf->kstk_esp = (u_int64_t) pcb.pcb_esp;
|
buf->kstk_esp = (u_int64_t) pcb.pcb_esp;
|
||||||
buf->kstk_eip = (u_int64_t) pcb.pcb_eip;
|
buf->kstk_eip = (u_int64_t) pcb.pcb_eip;
|
||||||
#else
|
#else
|
||||||
buf->kstk_esp = (u_int64_t) pcb.pcb_ksp;
|
buf->kstk_esp = (u_int64_t) pcb.pcb_ksp;
|
||||||
buf->kstk_eip = (u_int64_t) pcb.pcb_pc;
|
buf->kstk_eip = (u_int64_t) pcb.pcb_pc;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
/*xxx FreeBSD/Alpha? */
|
/*xxx FreeBSD/Alpha? */
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
buf->kstk_esp = (u_int64_t) pcb.pcb_tss.tss_esp0;
|
buf->kstk_esp = (u_int64_t) pcb.pcb_tss.tss_esp0;
|
||||||
#ifdef __bsdi__
|
#ifdef __bsdi__
|
||||||
buf->kstk_eip = (u_int64_t) pcb.pcb_tss.tss_eip;
|
buf->kstk_eip = (u_int64_t) pcb.pcb_tss.tss_eip;
|
||||||
#else
|
#else
|
||||||
buf->kstk_eip = (u_int64_t) pcb.pcb_tss.__tss_eip;
|
buf->kstk_eip = (u_int64_t) pcb.pcb_tss.__tss_eip;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buf->flags |= _glibtop_sysdeps_proc_kernel_pcb;
|
buf->flags |= _glibtop_sysdeps_proc_kernel_pcb;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Taken from `wchan ()' in `/usr/src/bin/ps/print.c'. */
|
/* Taken from `wchan ()' in `/usr/src/bin/ps/print.c'. */
|
||||||
|
|
||||||
glibtop_suid_leave (server);
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -55,51 +57,51 @@ static const unsigned long _glibtop_sysdeps_proclist =
|
|||||||
int
|
int
|
||||||
glibtop_init_proclist_p (glibtop *server)
|
glibtop_init_proclist_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
|
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned *
|
unsigned *
|
||||||
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
||||||
int64_t real_which, int64_t arg)
|
int64_t real_which, int64_t arg)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
unsigned *pids = NULL;
|
unsigned *pids = NULL;
|
||||||
int which, count;
|
int which, count;
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROCLIST), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROCLIST), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proclist));
|
memset (buf, 0, sizeof (glibtop_proclist));
|
||||||
|
|
||||||
which = (int)(real_which & GLIBTOP_KERN_PROC_MASK);
|
which = (int)(real_which & GLIBTOP_KERN_PROC_MASK);
|
||||||
|
|
||||||
/* Get the process data */
|
/* Get the process data */
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd, which, arg, &count);
|
pinfo = kvm_getprocs (server->_priv->machine.kd, which, arg, &count);
|
||||||
if ((pinfo == NULL) || (count < 1)) {
|
if ((pinfo == NULL) || (count < 1)) {
|
||||||
glibtop_warn_io_r (server, "kvm_getprocs (proclist)");
|
glibtop_warn_io_r (server, "kvm_getprocs (proclist)");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
count--;
|
count--;
|
||||||
|
|
||||||
/* Allocate count objects in the pids_chain array
|
/* Allocate count objects in the pids_chain array
|
||||||
* Same as malloc is pids is NULL, which it is. */
|
* Same as malloc is pids is NULL, which it is. */
|
||||||
pids = glibtop_realloc_r (server, pids, count * sizeof (unsigned));
|
pids = glibtop_realloc_r (server, pids, count * sizeof (unsigned));
|
||||||
/* Copy the pids over to this chain */
|
/* Copy the pids over to this chain */
|
||||||
for (i=j=0; i < count; i++) {
|
for (i=j=0; i < count; i++) {
|
||||||
if ((real_which & GLIBTOP_EXCLUDE_IDLE) &&
|
if ((real_which & GLIBTOP_EXCLUDE_IDLE) &&
|
||||||
(pinfo[i].kp_proc.p_stat != SRUN))
|
(pinfo[i].kp_proc.p_stat != SRUN))
|
||||||
continue;
|
continue;
|
||||||
else if ((real_which & GLIBTOP_EXCLUDE_SYSTEM) &&
|
else if ((real_which & GLIBTOP_EXCLUDE_SYSTEM) &&
|
||||||
(pinfo[i].kp_eproc.e_pcred.p_ruid == 0))
|
(pinfo[i].kp_eproc.e_pcred.p_ruid == 0))
|
||||||
continue;
|
continue;
|
||||||
pids [j++] = (unsigned) pinfo[i].kp_proc.p_pid;
|
pids [j++] = (unsigned) pinfo[i].kp_proc.p_pid;
|
||||||
} /* end for */
|
} /* end for */
|
||||||
/* Set the fields in buf */
|
/* Set the fields in buf */
|
||||||
buf->number = j;
|
buf->number = j;
|
||||||
buf->size = sizeof (unsigned);
|
buf->size = sizeof (unsigned);
|
||||||
buf->total = j * sizeof (unsigned);
|
buf->total = j * sizeof (unsigned);
|
||||||
buf->flags = _glibtop_sysdeps_proclist;
|
buf->flags = _glibtop_sysdeps_proclist;
|
||||||
return pids;
|
return pids;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -70,9 +72,9 @@ static const unsigned long _glibtop_sysdeps_map_entry =
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_map_p (glibtop *server)
|
glibtop_init_proc_map_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
|
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -81,189 +83,189 @@ glibtop_map_entry *
|
|||||||
glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
struct vm_map_entry entry, *first;
|
struct vm_map_entry entry, *first;
|
||||||
struct vmspace vmspace;
|
struct vmspace vmspace;
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
struct vnode vnode;
|
struct vnode vnode;
|
||||||
struct inode inode;
|
struct inode inode;
|
||||||
#else
|
#else
|
||||||
struct vm_object object;
|
struct vm_object object;
|
||||||
#endif
|
#endif
|
||||||
glibtop_map_entry *maps;
|
glibtop_map_entry *maps;
|
||||||
#if defined __FreeBSD__
|
#if defined __FreeBSD__
|
||||||
struct vnode vnode;
|
struct vnode vnode;
|
||||||
struct inode inode;
|
struct inode inode;
|
||||||
struct mount mount;
|
struct mount mount;
|
||||||
#endif
|
#endif
|
||||||
int count, i = 0;
|
int count, i = 0;
|
||||||
int update = 0;
|
int update = 0;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MAP), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MAP), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_map));
|
memset (buf, 0, sizeof (glibtop_proc_map));
|
||||||
|
|
||||||
/* It does not work for the swapper task. */
|
/* It does not work for the swapper task. */
|
||||||
if (pid == 0) return NULL;
|
if (pid == 0) return NULL;
|
||||||
|
|
||||||
glibtop_suid_enter (server);
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
/* Get the process data */
|
/* Get the process data */
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||||
KERN_PROC_PID, pid, &count);
|
KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count < 1))
|
if ((pinfo == NULL) || (count < 1))
|
||||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
|
|
||||||
/* Now we get the memory maps. */
|
/* Now we get the memory maps. */
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) pinfo [0].kp_proc.p_vmspace,
|
(unsigned long) pinfo [0].kp_proc.p_vmspace,
|
||||||
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace))
|
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace))
|
||||||
glibtop_error_io_r (server, "kvm_read (vmspace)");
|
glibtop_error_io_r (server, "kvm_read (vmspace)");
|
||||||
|
|
||||||
first = vmspace.vm_map.header.next;
|
first = vmspace.vm_map.header.next;
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) vmspace.vm_map.header.next,
|
(unsigned long) vmspace.vm_map.header.next,
|
||||||
(char *) &entry, sizeof (entry)) != sizeof (entry))
|
(char *) &entry, sizeof (entry)) != sizeof (entry))
|
||||||
|
glibtop_error_io_r (server, "kvm_read (entry)");
|
||||||
|
|
||||||
|
/* Allocate space. */
|
||||||
|
|
||||||
|
buf->number = vmspace.vm_map.nentries;
|
||||||
|
buf->size = sizeof (glibtop_map_entry);
|
||||||
|
|
||||||
|
buf->total = buf->number * buf->size;
|
||||||
|
|
||||||
|
maps = glibtop_malloc_r (server, buf->total);
|
||||||
|
|
||||||
|
memset (maps, 0, buf->total);
|
||||||
|
|
||||||
|
buf->flags = _glibtop_sysdeps_proc_map;
|
||||||
|
|
||||||
|
/* Walk through the `vm_map_entry' list ... */
|
||||||
|
|
||||||
|
/* I tested this a few times with `mmap'; as soon as you write
|
||||||
|
* to the mmap'ed area, the object type changes from OBJT_VNODE
|
||||||
|
* to OBJT_DEFAULT so if seems this really works. */
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (update) {
|
||||||
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
|
(unsigned long) entry.next,
|
||||||
|
&entry, sizeof (entry)) != sizeof (entry))
|
||||||
glibtop_error_io_r (server, "kvm_read (entry)");
|
glibtop_error_io_r (server, "kvm_read (entry)");
|
||||||
|
} else {
|
||||||
/* Allocate space. */
|
update = 1;
|
||||||
|
}
|
||||||
buf->number = vmspace.vm_map.nentries;
|
|
||||||
buf->size = sizeof (glibtop_map_entry);
|
|
||||||
|
|
||||||
buf->total = buf->number * buf->size;
|
|
||||||
|
|
||||||
maps = glibtop_malloc_r (server, buf->total);
|
|
||||||
|
|
||||||
memset (maps, 0, buf->total);
|
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_proc_map;
|
|
||||||
|
|
||||||
/* Walk through the `vm_map_entry' list ... */
|
|
||||||
|
|
||||||
/* I tested this a few times with `mmap'; as soon as you write
|
|
||||||
* to the mmap'ed area, the object type changes from OBJT_VNODE
|
|
||||||
* to OBJT_DEFAULT so if seems this really works. */
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (update) {
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
|
||||||
(unsigned long) entry.next,
|
|
||||||
&entry, sizeof (entry)) != sizeof (entry))
|
|
||||||
glibtop_error_io_r (server, "kvm_read (entry)");
|
|
||||||
} else {
|
|
||||||
update = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#if __FreeBSD__ >= 4
|
#if __FreeBSD__ >= 4
|
||||||
if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
|
if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
|
||||||
continue;
|
continue;
|
||||||
#else
|
#else
|
||||||
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
|
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
if (UVM_ET_ISSUBMAP (&entry))
|
if (UVM_ET_ISSUBMAP (&entry))
|
||||||
continue;
|
continue;
|
||||||
#else
|
#else
|
||||||
if (entry.is_a_map || entry.is_sub_map)
|
if (entry.is_a_map || entry.is_sub_map)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
maps [i].flags = _glibtop_sysdeps_map_entry;
|
maps [i].flags = _glibtop_sysdeps_map_entry;
|
||||||
|
|
||||||
maps [i].start = entry.start;
|
maps [i].start = entry.start;
|
||||||
maps [i].end = entry.end;
|
maps [i].end = entry.end;
|
||||||
maps [i].offset = entry.offset;
|
maps [i].offset = entry.offset;
|
||||||
|
|
||||||
maps [i].perm = 0;
|
maps [i].perm = 0;
|
||||||
|
|
||||||
if (entry.protection & VM_PROT_READ)
|
if (entry.protection & VM_PROT_READ)
|
||||||
maps [i].perm |= GLIBTOP_MAP_PERM_READ;
|
maps [i].perm |= GLIBTOP_MAP_PERM_READ;
|
||||||
if (entry.protection & VM_PROT_WRITE)
|
if (entry.protection & VM_PROT_WRITE)
|
||||||
maps [i].perm |= GLIBTOP_MAP_PERM_WRITE;
|
maps [i].perm |= GLIBTOP_MAP_PERM_WRITE;
|
||||||
if (entry.protection & VM_PROT_EXECUTE)
|
if (entry.protection & VM_PROT_EXECUTE)
|
||||||
maps [i].perm |= GLIBTOP_MAP_PERM_EXECUTE;
|
maps [i].perm |= GLIBTOP_MAP_PERM_EXECUTE;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
if (!entry.object.uvm_obj)
|
if (!entry.object.uvm_obj)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* We're only interested in vnodes */
|
/* We're only interested in vnodes */
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) entry.object.uvm_obj,
|
(unsigned long) entry.object.uvm_obj,
|
||||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!entry.object.vm_object)
|
if (!entry.object.vm_object)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* We're only interested in `vm_object's */
|
/* We're only interested in `vm_object's */
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) entry.object.vm_object,
|
(unsigned long) entry.object.vm_object,
|
||||||
&object, sizeof (object)) != sizeof (object))
|
&object, sizeof (object)) != sizeof (object))
|
||||||
glibtop_error_io_r (server, "kvm_read (object)");
|
glibtop_error_io_r (server, "kvm_read (object)");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||||
!vnode.v_data) continue;
|
!vnode.v_data) continue;
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) vnode.v_data,
|
(unsigned long) vnode.v_data,
|
||||||
&inode, sizeof (inode)) != sizeof (inode))
|
&inode, sizeof (inode)) != sizeof (inode))
|
||||||
glibtop_error_io_r (server, "kvm_read (inode)");
|
glibtop_error_io_r (server, "kvm_read (inode)");
|
||||||
|
|
||||||
maps [i-1].inode = inode.i_number;
|
maps [i-1].inode = inode.i_number;
|
||||||
maps [i-1].device = inode.i_dev;
|
maps [i-1].device = inode.i_dev;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
/* If the object is of type vnode, add its size */
|
/* If the object is of type vnode, add its size */
|
||||||
|
|
||||||
if (object.type != OBJT_VNODE)
|
if (object.type != OBJT_VNODE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!object.handle)
|
if (!object.handle)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) object.handle,
|
(unsigned long) object.handle,
|
||||||
&vnode, sizeof (vnode)) != sizeof (vnode))
|
&vnode, sizeof (vnode)) != sizeof (vnode))
|
||||||
glibtop_error_io_r (server, "kvm_read (vnode)");
|
glibtop_error_io_r (server, "kvm_read (vnode)");
|
||||||
|
|
||||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||||
!vnode.v_data) continue;
|
!vnode.v_data) continue;
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) vnode.v_data,
|
(unsigned long) vnode.v_data,
|
||||||
&inode, sizeof (inode)) != sizeof (inode))
|
&inode, sizeof (inode)) != sizeof (inode))
|
||||||
glibtop_error_io_r (server, "kvm_read (inode)");
|
glibtop_error_io_r (server, "kvm_read (inode)");
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) vnode.v_mount,
|
(unsigned long) vnode.v_mount,
|
||||||
&mount, sizeof (mount)) != sizeof (mount))
|
&mount, sizeof (mount)) != sizeof (mount))
|
||||||
glibtop_error_io_r (server, "kvm_read (mount)");
|
glibtop_error_io_r (server, "kvm_read (mount)");
|
||||||
|
|
||||||
maps [i-1].inode = inode.i_number;
|
maps [i-1].inode = inode.i_number;
|
||||||
maps [i-1].device = inode.i_dev;
|
maps [i-1].device = inode.i_dev;
|
||||||
#endif
|
#endif
|
||||||
} while (entry.next != first);
|
} while (entry.next != first);
|
||||||
|
|
||||||
return maps;
|
return maps;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -84,24 +86,24 @@ static int pageshift; /* log base 2 of the pagesize */
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_mem_p (glibtop *server)
|
glibtop_init_proc_mem_p (glibtop *server)
|
||||||
{
|
{
|
||||||
register int pagesize;
|
register int pagesize;
|
||||||
|
|
||||||
/* get the page size with "getpagesize" and calculate pageshift
|
/* get the page size with "getpagesize" and calculate pageshift
|
||||||
* from it */
|
* from it */
|
||||||
pagesize = getpagesize ();
|
pagesize = getpagesize ();
|
||||||
pageshift = 0;
|
pageshift = 0;
|
||||||
while (pagesize > 1) {
|
while (pagesize > 1) {
|
||||||
pageshift++;
|
pageshift++;
|
||||||
pagesize >>= 1;
|
pagesize >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we only need the amount of log(2)1024 for our conversion */
|
/* we only need the amount of log(2)1024 for our conversion */
|
||||||
pageshift -= LOG1024;
|
pageshift -= LOG1024;
|
||||||
|
|
||||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
|
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
|
||||||
_glibtop_sysdeps_proc_mem_share;
|
_glibtop_sysdeps_proc_mem_share;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -110,155 +112,155 @@ int
|
|||||||
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)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
struct vm_map_entry entry, *first;
|
struct vm_map_entry entry, *first;
|
||||||
struct vmspace *vms, vmspace;
|
struct vmspace *vms, vmspace;
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
struct vnode vnode;
|
struct vnode vnode;
|
||||||
struct inode inode;
|
struct inode inode;
|
||||||
#else
|
#else
|
||||||
struct vm_object object;
|
struct vm_object object;
|
||||||
#endif
|
#endif
|
||||||
struct plimit plimit;
|
struct plimit plimit;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MEM), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MEM), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||||
|
|
||||||
if (server->sysdeps.proc_mem == 0)
|
if (server->sysdeps.proc_mem == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* It does not work for the swapper task. */
|
/* It does not work for the swapper task. */
|
||||||
if (pid == 0) return -1;
|
if (pid == 0) return -1;
|
||||||
|
|
||||||
/* Get the process data */
|
/* Get the process data */
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||||
KERN_PROC_PID, pid, &count);
|
KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count < 1)) {
|
if ((pinfo == NULL) || (count < 1)) {
|
||||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
|
(unsigned long) pinfo [0].kp_proc.p_limit,
|
||||||
|
(char *) &plimit, sizeof (plimit)) != sizeof (plimit)) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (plimit)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf->rss_rlim = (u_int64_t)
|
||||||
|
(plimit.pl_rlimit [RLIMIT_RSS].rlim_cur);
|
||||||
|
|
||||||
|
vms = &pinfo [0].kp_eproc.e_vm;
|
||||||
|
|
||||||
|
buf->vsize = buf->size = (u_int64_t) pagetok
|
||||||
|
(vms->vm_tsize + vms->vm_dsize + vms->vm_ssize) << LOG1024;
|
||||||
|
|
||||||
|
buf->resident = buf->rss = (u_int64_t) pagetok
|
||||||
|
(vms->vm_rssize) << LOG1024;
|
||||||
|
|
||||||
|
/* Now we get the shared memory. */
|
||||||
|
|
||||||
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
|
(unsigned long) pinfo [0].kp_proc.p_vmspace,
|
||||||
|
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (vmspace)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
first = vmspace.vm_map.header.next;
|
||||||
|
|
||||||
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
|
(unsigned long) vmspace.vm_map.header.next,
|
||||||
|
(char *) &entry, sizeof (entry)) != sizeof (entry)) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (entry)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Walk through the `vm_map_entry' list ... */
|
||||||
|
|
||||||
|
/* I tested this a few times with `mmap'; as soon as you write
|
||||||
|
* to the mmap'ed area, the object type changes from OBJT_VNODE
|
||||||
|
* to OBJT_DEFAULT so if seems this really works. */
|
||||||
|
|
||||||
|
while (entry.next != first) {
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) pinfo [0].kp_proc.p_limit,
|
(unsigned long) entry.next,
|
||||||
(char *) &plimit, sizeof (plimit)) != sizeof (plimit)) {
|
&entry, sizeof (entry)) != sizeof (entry)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (plimit)");
|
glibtop_warn_io_r (server, "kvm_read (entry)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->rss_rlim = (u_int64_t)
|
|
||||||
(plimit.pl_rlimit [RLIMIT_RSS].rlim_cur);
|
|
||||||
|
|
||||||
vms = &pinfo [0].kp_eproc.e_vm;
|
|
||||||
|
|
||||||
buf->vsize = buf->size = (u_int64_t) pagetok
|
|
||||||
(vms->vm_tsize + vms->vm_dsize + vms->vm_ssize) << LOG1024;
|
|
||||||
|
|
||||||
buf->resident = buf->rss = (u_int64_t) pagetok
|
|
||||||
(vms->vm_rssize) << LOG1024;
|
|
||||||
|
|
||||||
/* Now we get the shared memory. */
|
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
|
||||||
(unsigned long) pinfo [0].kp_proc.p_vmspace,
|
|
||||||
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (vmspace)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
first = vmspace.vm_map.header.next;
|
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
|
||||||
(unsigned long) vmspace.vm_map.header.next,
|
|
||||||
(char *) &entry, sizeof (entry)) != sizeof (entry)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (entry)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Walk through the `vm_map_entry' list ... */
|
|
||||||
|
|
||||||
/* I tested this a few times with `mmap'; as soon as you write
|
|
||||||
* to the mmap'ed area, the object type changes from OBJT_VNODE
|
|
||||||
* to OBJT_DEFAULT so if seems this really works. */
|
|
||||||
|
|
||||||
while (entry.next != first) {
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
|
||||||
(unsigned long) entry.next,
|
|
||||||
&entry, sizeof (entry)) != sizeof (entry)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (entry)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#if __FreeBSD__ >= 4
|
#if __FreeBSD__ >= 4
|
||||||
if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
|
if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
|
||||||
continue;
|
continue;
|
||||||
#else
|
#else
|
||||||
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
|
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
if (UVM_ET_ISSUBMAP (&entry))
|
if (UVM_ET_ISSUBMAP (&entry))
|
||||||
continue;
|
continue;
|
||||||
#else
|
#else
|
||||||
if (entry.is_a_map || entry.is_sub_map)
|
if (entry.is_a_map || entry.is_sub_map)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
if (!entry.object.uvm_obj)
|
if (!entry.object.uvm_obj)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* We're only interested in vnodes */
|
/* We're only interested in vnodes */
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) entry.object.uvm_obj,
|
(unsigned long) entry.object.uvm_obj,
|
||||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!entry.object.vm_object)
|
if (!entry.object.vm_object)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* We're only interested in `vm_object's */
|
/* We're only interested in `vm_object's */
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) entry.object.vm_object,
|
(unsigned long) entry.object.vm_object,
|
||||||
&object, sizeof (object)) != sizeof (object)) {
|
&object, sizeof (object)) != sizeof (object)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (object)");
|
glibtop_warn_io_r (server, "kvm_read (object)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* If the object is of type vnode, add its size */
|
/* If the object is of type vnode, add its size */
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||||
!vnode.v_data) continue;
|
!vnode.v_data) continue;
|
||||||
|
|
||||||
/* Reference count must be at least two. */
|
/* Reference count must be at least two. */
|
||||||
if (vnode.v_uvm.u_obj.uo_refs <= 1)
|
if (vnode.v_uvm.u_obj.uo_refs <= 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buf->share += pagetok (vnode.v_uvm.u_obj.uo_npages) << LOG1024;
|
buf->share += pagetok (vnode.v_uvm.u_obj.uo_npages) << LOG1024;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
if (object.type != OBJT_VNODE)
|
if (object.type != OBJT_VNODE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buf->share += object.un_pager.vnp.vnp_size;
|
buf->share += object.un_pager.vnp.vnp_size;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_proc_mem |
|
buf->flags = _glibtop_sysdeps_proc_mem |
|
||||||
_glibtop_sysdeps_proc_mem_share;
|
_glibtop_sysdeps_proc_mem_share;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -38,9 +40,9 @@ static const unsigned long _glibtop_sysdeps_proc_segment = 0;
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_segment_p (glibtop *server)
|
glibtop_init_proc_segment_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
|
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -50,37 +52,37 @@ glibtop_get_proc_segment_p (glibtop *server,
|
|||||||
glibtop_proc_segment *buf,
|
glibtop_proc_segment *buf,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_segment));
|
memset (buf, 0, sizeof (glibtop_proc_segment));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Get the process info from the kernel */
|
/* Get the process info from the kernel */
|
||||||
kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, count);
|
kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, count);
|
||||||
if (*count != 1) {
|
if (*count != 1) {
|
||||||
return -1; /* the zeroed-out buffer indicating no data */
|
return -1; /* the zeroed-out buffer indicating no data */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* trs: text resident set size
|
/* trs: text resident set size
|
||||||
pinfo[0]->kp_eproc.e_xrssize;
|
pinfo[0]->kp_eproc.e_xrssize;
|
||||||
*/
|
*/
|
||||||
/* buf->trs = pinfo[0]->kp_eproc.e_xrssize; */
|
/* buf->trs = pinfo[0]->kp_eproc.e_xrssize; */
|
||||||
/* lrs: shared-lib resident set size
|
/* lrs: shared-lib resident set size
|
||||||
? */
|
? */
|
||||||
/* drs: data resident set size
|
/* drs: data resident set size
|
||||||
pinfo[0]->kp_eproc.e_vm.vm_map.vm_dsize;
|
pinfo[0]->kp_eproc.e_vm.vm_map.vm_dsize;
|
||||||
*/
|
*/
|
||||||
/* dt: dirty pages
|
/* dt: dirty pages
|
||||||
*/
|
*/
|
||||||
/* start_code: address of beginning of code segment
|
/* start_code: address of beginning of code segment
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/* end_code: address of end of code segment
|
/* end_code: address of end of code segment
|
||||||
*/
|
*/
|
||||||
/* start_stack: address of the bottom of stack segment
|
/* start_stack: address of the bottom of stack segment
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -42,9 +44,9 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_signal_p (glibtop *server)
|
glibtop_init_proc_signal_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
|
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -52,61 +54,61 @@ glibtop_get_proc_signal_p (glibtop *server,
|
|||||||
glibtop_proc_signal *buf,
|
glibtop_proc_signal *buf,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||||
|
|
||||||
/* It does not work for the swapper task. */
|
/* It does not work for the swapper task. */
|
||||||
if (pid == 0) return -1;
|
if (pid == 0) return -1;
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||||
KERN_PROC_PID, pid, &count);
|
KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1)) {
|
if ((pinfo == NULL) || (count != 1)) {
|
||||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* signal: mask of pending signals.
|
/* signal: mask of pending signals.
|
||||||
* pinfo [0].kp_proc.p_siglist
|
* pinfo [0].kp_proc.p_siglist
|
||||||
*/
|
*/
|
||||||
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
||||||
buf->signal [0] = pinfo [0].kp_proc.p_siglist.__bits[0];
|
buf->signal [0] = pinfo [0].kp_proc.p_siglist.__bits[0];
|
||||||
#else
|
#else
|
||||||
buf->signal [0] = pinfo [0].kp_proc.p_siglist;
|
buf->signal [0] = pinfo [0].kp_proc.p_siglist;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* blocked: mask of blocked signals.
|
/* blocked: mask of blocked signals.
|
||||||
* pinfo [0].kp_proc.p_sigmask
|
* pinfo [0].kp_proc.p_sigmask
|
||||||
*/
|
*/
|
||||||
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
||||||
buf->blocked [0] = pinfo [0].kp_proc.p_sigmask.__bits[0];
|
buf->blocked [0] = pinfo [0].kp_proc.p_sigmask.__bits[0];
|
||||||
#else
|
#else
|
||||||
buf->blocked [0] = pinfo [0].kp_proc.p_sigmask;
|
buf->blocked [0] = pinfo [0].kp_proc.p_sigmask;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* sigignore: mask of ignored signals.
|
/* sigignore: mask of ignored signals.
|
||||||
* pinfo [0].kp_proc.p_sigignore
|
* pinfo [0].kp_proc.p_sigignore
|
||||||
*/
|
*/
|
||||||
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
||||||
buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore.__bits[0];
|
buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore.__bits[0];
|
||||||
#else
|
#else
|
||||||
buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore;
|
buf->sigignore [0] = pinfo [0].kp_proc.p_sigignore;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* sigcatch: mask of caught signals.
|
/* sigcatch: mask of caught signals.
|
||||||
* pinfo [0].kp_proc.p_sigcatch
|
* pinfo [0].kp_proc.p_sigcatch
|
||||||
*/
|
*/
|
||||||
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
#if (defined(__NetBSD__) && (NSIG > 32)) || (__FreeBSD_version >= 400011)
|
||||||
buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch.__bits[0];
|
buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch.__bits[0];
|
||||||
#else
|
#else
|
||||||
buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch;
|
buf->sigcatch [0] = pinfo [0].kp_proc.p_sigcatch;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998 Joshua Sled
|
/* Copyright (C) 1998 Joshua Sled
|
||||||
@@ -48,10 +50,10 @@ static const unsigned long _glibtop_sysdeps_proc_state_new =
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_state_p (glibtop *server)
|
glibtop_init_proc_state_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
|
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
|
||||||
_glibtop_sysdeps_proc_state_new;
|
_glibtop_sysdeps_proc_state_new;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -61,82 +63,82 @@ glibtop_get_proc_state_p (glibtop *server,
|
|||||||
glibtop_proc_state *buf,
|
glibtop_proc_state *buf,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_STATE), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_STATE), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_state));
|
memset (buf, 0, sizeof (glibtop_proc_state));
|
||||||
|
|
||||||
/* It does not work for the swapper task. */
|
/* It does not work for the swapper task. */
|
||||||
if (pid == 0) return -1;
|
if (pid == 0) return -1;
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||||
KERN_PROC_PID, pid, &count);
|
KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1)) {
|
if ((pinfo == NULL) || (count != 1)) {
|
||||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy (buf->cmd, pinfo [0].kp_proc.p_comm, sizeof (buf->cmd)-1);
|
strncpy (buf->cmd, pinfo [0].kp_proc.p_comm, sizeof (buf->cmd)-1);
|
||||||
buf->cmd [sizeof (buf->cmd)-1] = 0;
|
buf->cmd [sizeof (buf->cmd)-1] = 0;
|
||||||
|
|
||||||
buf->uid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
buf->uid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
||||||
buf->gid = pinfo [0].kp_eproc.e_pcred.p_svgid;
|
buf->gid = pinfo [0].kp_eproc.e_pcred.p_svgid;
|
||||||
|
|
||||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||||
buf->ruid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
buf->ruid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
||||||
buf->rgid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
buf->rgid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set the flags for the data we're about to return*/
|
/* Set the flags for the data we're about to return*/
|
||||||
buf->flags = _glibtop_sysdeps_proc_state |
|
buf->flags = _glibtop_sysdeps_proc_state |
|
||||||
_glibtop_sysdeps_proc_state_new;
|
_glibtop_sysdeps_proc_state_new;
|
||||||
|
|
||||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||||
switch (pinfo [0].kp_proc.p_stat) {
|
switch (pinfo [0].kp_proc.p_stat) {
|
||||||
case SIDL:
|
case SIDL:
|
||||||
buf->state = 0;
|
buf->state = 0;
|
||||||
break;
|
break;
|
||||||
case SRUN:
|
case SRUN:
|
||||||
buf->state = GLIBTOP_PROCESS_RUNNING;
|
buf->state = GLIBTOP_PROCESS_RUNNING;
|
||||||
break;
|
break;
|
||||||
case SSLEEP:
|
case SSLEEP:
|
||||||
buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
|
buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
|
||||||
break;
|
break;
|
||||||
case SSTOP:
|
case SSTOP:
|
||||||
buf->state = GLIBTOP_PROCESS_STOPPED;
|
buf->state = GLIBTOP_PROCESS_STOPPED;
|
||||||
break;
|
break;
|
||||||
case SZOMB:
|
case SZOMB:
|
||||||
buf->state = GLIBTOP_PROCESS_ZOMBIE;
|
buf->state = GLIBTOP_PROCESS_ZOMBIE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
switch (pinfo [0].kp_proc.p_stat) {
|
switch (pinfo [0].kp_proc.p_stat) {
|
||||||
case SIDL:
|
case SIDL:
|
||||||
buf->state = 'S';
|
buf->state = 'S';
|
||||||
break;
|
break;
|
||||||
case SRUN:
|
case SRUN:
|
||||||
buf->state = 'R';
|
buf->state = 'R';
|
||||||
break;
|
break;
|
||||||
case SSLEEP:
|
case SSLEEP:
|
||||||
buf->state = 'S';
|
buf->state = 'S';
|
||||||
break;
|
break;
|
||||||
case SSTOP:
|
case SSTOP:
|
||||||
buf->state = 'T';
|
buf->state = 'T';
|
||||||
break;
|
break;
|
||||||
case SZOMB:
|
case SZOMB:
|
||||||
buf->state = 'Z';
|
buf->state = 'Z';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buf->flags |= (1L << GLIBTOP_PROC_STATE_STATE);
|
buf->flags |= (1L << GLIBTOP_PROC_STATE_STATE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -46,10 +48,10 @@ static const unsigned long _glibtop_sysdeps_proc_time_user =
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_time_p (glibtop *server)
|
glibtop_init_proc_time_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
|
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
|
||||||
_glibtop_sysdeps_proc_time_user;
|
_glibtop_sysdeps_proc_time_user;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Taken from /usr/src/sys/kern/kern_resource.c */
|
/* Taken from /usr/src/sys/kern/kern_resource.c */
|
||||||
@@ -66,57 +68,57 @@ calcru(p, up, sp, ip)
|
|||||||
struct timeval *sp;
|
struct timeval *sp;
|
||||||
struct timeval *ip;
|
struct timeval *ip;
|
||||||
{
|
{
|
||||||
quad_t totusec;
|
quad_t totusec;
|
||||||
u_quad_t u, st, ut, it, tot;
|
u_quad_t u, st, ut, it, tot;
|
||||||
#if (__FreeBSD_version < 300003)
|
#if (__FreeBSD_version < 300003)
|
||||||
long sec, usec;
|
long sec, usec;
|
||||||
#endif
|
#endif
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
st = p->p_sticks;
|
st = p->p_sticks;
|
||||||
ut = p->p_uticks;
|
ut = p->p_uticks;
|
||||||
it = p->p_iticks;
|
it = p->p_iticks;
|
||||||
|
|
||||||
tot = st + ut + it;
|
tot = st + ut + it;
|
||||||
if (tot == 0) {
|
if (tot == 0) {
|
||||||
st = 1;
|
st = 1;
|
||||||
tot = 1;
|
tot = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
|
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
|
||||||
|
|
||||||
/* This was changed from a `struct timeval' into a `u_int64_t'
|
/* This was changed from a `struct timeval' into a `u_int64_t'
|
||||||
* on FreeBSD 3.0 and renamed p_rtime -> p_runtime.
|
* on FreeBSD 3.0 and renamed p_rtime -> p_runtime.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
totusec = (u_quad_t) p->p_runtime;
|
totusec = (u_quad_t) p->p_runtime;
|
||||||
#else
|
#else
|
||||||
sec = p->p_rtime.tv_sec;
|
sec = p->p_rtime.tv_sec;
|
||||||
usec = p->p_rtime.tv_usec;
|
usec = p->p_rtime.tv_usec;
|
||||||
|
|
||||||
totusec = (quad_t)sec * 1000000 + usec;
|
totusec = (quad_t)sec * 1000000 + usec;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (totusec < 0) {
|
if (totusec < 0) {
|
||||||
/* XXX no %qd in kernel. Truncate. */
|
/* XXX no %qd in kernel. Truncate. */
|
||||||
fprintf (stderr, "calcru: negative time: %ld usec\n",
|
fprintf (stderr, "calcru: negative time: %ld usec\n",
|
||||||
(long)totusec);
|
(long)totusec);
|
||||||
totusec = 0;
|
totusec = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u = totusec;
|
u = totusec;
|
||||||
st = (u * st) / tot;
|
st = (u * st) / tot;
|
||||||
sp->tv_sec = st / 1000000;
|
sp->tv_sec = st / 1000000;
|
||||||
sp->tv_usec = st % 1000000;
|
sp->tv_usec = st % 1000000;
|
||||||
ut = (u * ut) / tot;
|
ut = (u * ut) / tot;
|
||||||
up->tv_sec = ut / 1000000;
|
up->tv_sec = ut / 1000000;
|
||||||
up->tv_usec = ut % 1000000;
|
up->tv_usec = ut % 1000000;
|
||||||
if (ip != NULL) {
|
if (ip != NULL) {
|
||||||
it = (u * it) / tot;
|
it = (u * it) / tot;
|
||||||
ip->tv_sec = it / 1000000;
|
ip->tv_sec = it / 1000000;
|
||||||
ip->tv_usec = it % 1000000;
|
ip->tv_usec = it % 1000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -125,110 +127,110 @@ int
|
|||||||
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 kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
register struct rusage *rup;
|
register struct rusage *rup;
|
||||||
#else
|
#else
|
||||||
struct user *u_addr = (struct user *)USRSTACK;
|
struct user *u_addr = (struct user *)USRSTACK;
|
||||||
#endif
|
#endif
|
||||||
struct pstats pstats;
|
struct pstats pstats;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
char filename [BUFSIZ];
|
char filename [BUFSIZ];
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||||
|
|
||||||
/* It does not work for the swapper task. */
|
/* It does not work for the swapper task. */
|
||||||
if (pid == 0) return -1;
|
if (pid == 0) return -1;
|
||||||
|
|
||||||
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||||
if (server->sysdeps.proc_time == 0)
|
if (server->sysdeps.proc_time == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifndef __bsdi__
|
#ifndef __bsdi__
|
||||||
sprintf (filename, "/proc/%d/mem", (int) pid);
|
sprintf (filename, "/proc/%d/mem", (int) pid);
|
||||||
if (stat (filename, &statb)) return -1;
|
if (stat (filename, &statb)) return -1;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||||
KERN_PROC_PID, pid, &count);
|
KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1))
|
if ((pinfo == NULL) || (count != 1))
|
||||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
|
|
||||||
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
|
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
|
||||||
buf->rtime = pinfo [0].kp_proc.p_runtime;
|
buf->rtime = pinfo [0].kp_proc.p_runtime;
|
||||||
#else
|
#else
|
||||||
buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
|
buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buf->frequency = 1000000;
|
buf->frequency = 1000000;
|
||||||
buf->flags = _glibtop_sysdeps_proc_time;
|
buf->flags = _glibtop_sysdeps_proc_time;
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
glibtop_suid_enter (server);
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) pinfo [0].kp_proc.p_stats,
|
(unsigned long) pinfo [0].kp_proc.p_stats,
|
||||||
&pstats, sizeof (pstats)) != sizeof (pstats)) {
|
&pstats, sizeof (pstats)) != sizeof (pstats)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (pstats)");
|
glibtop_warn_io_r (server, "kvm_read (pstats)");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
|
rup = &pstats.p_ru;
|
||||||
|
calcru(&(pinfo [0]).kp_proc,
|
||||||
|
&rup->ru_utime, &rup->ru_stime, NULL);
|
||||||
|
|
||||||
|
buf->utime = tv2sec (pstats.p_ru.ru_utime);
|
||||||
|
buf->stime = tv2sec (pstats.p_ru.ru_stime);
|
||||||
|
|
||||||
|
buf->cutime = tv2sec (pstats.p_cru.ru_utime);
|
||||||
|
buf->cstime = tv2sec (pstats.p_cru.ru_stime);
|
||||||
|
|
||||||
|
buf->start_time = (u_int64_t) pstats.p_start.tv_sec;
|
||||||
|
|
||||||
|
buf->flags |= _glibtop_sysdeps_proc_time_user;
|
||||||
|
#else
|
||||||
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
|
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||||
|
kvm_uread (server->_priv->machine.kd, &(pinfo [0]).kp_proc,
|
||||||
|
(unsigned long) &u_addr->u_stats,
|
||||||
|
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
|
||||||
|
{
|
||||||
|
/* This is taken form the kernel source code of
|
||||||
|
* FreeBSD 2.2.6. */
|
||||||
|
|
||||||
|
/* Well, we just do the same getrusage () does ... */
|
||||||
|
|
||||||
|
register struct rusage *rup;
|
||||||
|
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
|
rup = &pstats.p_ru;
|
||||||
|
calcru(&(pinfo [0]).kp_proc,
|
||||||
|
&rup->ru_utime, &rup->ru_stime, NULL);
|
||||||
|
|
||||||
|
buf->utime = tv2sec (pstats.p_ru.ru_utime);
|
||||||
|
buf->stime = tv2sec (pstats.p_ru.ru_stime);
|
||||||
|
|
||||||
|
buf->cutime = tv2sec (pstats.p_cru.ru_utime);
|
||||||
|
buf->cstime = tv2sec (pstats.p_cru.ru_stime);
|
||||||
|
|
||||||
|
buf->start_time = tv2sec (pstats.p_start);
|
||||||
|
|
||||||
|
buf->flags = _glibtop_sysdeps_proc_time_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
glibtop_suid_leave (server);
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
rup = &pstats.p_ru;
|
|
||||||
calcru(&(pinfo [0]).kp_proc,
|
|
||||||
&rup->ru_utime, &rup->ru_stime, NULL);
|
|
||||||
|
|
||||||
buf->utime = tv2sec (pstats.p_ru.ru_utime);
|
|
||||||
buf->stime = tv2sec (pstats.p_ru.ru_stime);
|
|
||||||
|
|
||||||
buf->cutime = tv2sec (pstats.p_cru.ru_utime);
|
|
||||||
buf->cstime = tv2sec (pstats.p_cru.ru_stime);
|
|
||||||
|
|
||||||
buf->start_time = (u_int64_t) pstats.p_start.tv_sec;
|
|
||||||
|
|
||||||
buf->flags |= _glibtop_sysdeps_proc_time_user;
|
|
||||||
#else
|
|
||||||
glibtop_suid_enter (server);
|
|
||||||
|
|
||||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
|
||||||
kvm_uread (server->_priv->machine.kd, &(pinfo [0]).kp_proc,
|
|
||||||
(unsigned long) &u_addr->u_stats,
|
|
||||||
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
|
|
||||||
{
|
|
||||||
/* This is taken form the kernel source code of
|
|
||||||
* FreeBSD 2.2.6. */
|
|
||||||
|
|
||||||
/* Well, we just do the same getrusage () does ... */
|
|
||||||
|
|
||||||
register struct rusage *rup;
|
|
||||||
|
|
||||||
glibtop_suid_leave (server);
|
|
||||||
|
|
||||||
rup = &pstats.p_ru;
|
|
||||||
calcru(&(pinfo [0]).kp_proc,
|
|
||||||
&rup->ru_utime, &rup->ru_stime, NULL);
|
|
||||||
|
|
||||||
buf->utime = tv2sec (pstats.p_ru.ru_utime);
|
|
||||||
buf->stime = tv2sec (pstats.p_ru.ru_stime);
|
|
||||||
|
|
||||||
buf->cutime = tv2sec (pstats.p_cru.ru_utime);
|
|
||||||
buf->cstime = tv2sec (pstats.p_cru.ru_stime);
|
|
||||||
|
|
||||||
buf->start_time = tv2sec (pstats.p_start);
|
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_proc_time_user;
|
|
||||||
}
|
|
||||||
|
|
||||||
glibtop_suid_leave (server);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -50,10 +52,10 @@ static const unsigned long _glibtop_sysdeps_proc_uid_groups =
|
|||||||
int
|
int
|
||||||
glibtop_init_proc_uid_p (glibtop *server)
|
glibtop_init_proc_uid_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
|
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
|
||||||
_glibtop_sysdeps_proc_uid_groups;
|
_glibtop_sysdeps_proc_uid_groups;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -62,73 +64,73 @@ int
|
|||||||
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
struct ucred ucred;
|
struct ucred ucred;
|
||||||
void *ucred_ptr;
|
void *ucred_ptr;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_UID), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_UID), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||||
|
|
||||||
/* It does not work for the swapper task. */
|
/* It does not work for the swapper task. */
|
||||||
if (pid == 0) return -1;
|
if (pid == 0) return -1;
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
pinfo = kvm_getprocs (server->_priv->machine.kd,
|
||||||
KERN_PROC_PID, pid, &count);
|
KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1)) {
|
if ((pinfo == NULL) || (count != 1)) {
|
||||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->uid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
buf->uid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
||||||
buf->euid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
buf->euid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
||||||
buf->gid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
buf->gid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
||||||
buf->egid = pinfo [0].kp_eproc.e_pcred.p_svgid;
|
buf->egid = pinfo [0].kp_eproc.e_pcred.p_svgid;
|
||||||
|
|
||||||
buf->ppid = pinfo [0].kp_eproc.e_ppid;
|
buf->ppid = pinfo [0].kp_eproc.e_ppid;
|
||||||
buf->pgrp = pinfo [0].kp_eproc.e_pgid;
|
buf->pgrp = pinfo [0].kp_eproc.e_pgid;
|
||||||
buf->tpgid = pinfo [0].kp_eproc.e_tpgid;
|
buf->tpgid = pinfo [0].kp_eproc.e_tpgid;
|
||||||
|
|
||||||
buf->nice = pinfo [0].kp_proc.p_nice;
|
buf->nice = pinfo [0].kp_proc.p_nice;
|
||||||
buf->priority = pinfo [0].kp_proc.p_priority;
|
buf->priority = pinfo [0].kp_proc.p_priority;
|
||||||
|
|
||||||
/* Set the flags for the data we're about to return*/
|
/* Set the flags for the data we're about to return*/
|
||||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||||
|
|
||||||
/* Use LibGTop conditionals here so we can more easily merge this
|
/* Use LibGTop conditionals here so we can more easily merge this
|
||||||
* code into the LIBGTOP_STABLE_1_0 branch. */
|
* code into the LIBGTOP_STABLE_1_0 branch. */
|
||||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||||
/* This probably also works with other versions, but not yet
|
/* This probably also works with other versions, but not yet
|
||||||
* tested. Please remove the conditional if this is true. */
|
* tested. Please remove the conditional if this is true. */
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
ucred_ptr = (void *) pinfo [0].kp_eproc.e_pcred.pc_ucred;
|
ucred_ptr = (void *) pinfo [0].kp_eproc.e_pcred.pc_ucred;
|
||||||
|
|
||||||
if (ucred_ptr) {
|
if (ucred_ptr) {
|
||||||
if (kvm_read (server->_priv->machine.kd,
|
if (kvm_read (server->_priv->machine.kd,
|
||||||
(unsigned long) ucred_ptr,
|
(unsigned long) ucred_ptr,
|
||||||
&ucred, sizeof (ucred)) != sizeof (ucred)) {
|
&ucred, sizeof (ucred)) != sizeof (ucred)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (ucred)");
|
glibtop_warn_io_r (server, "kvm_read (ucred)");
|
||||||
} else {
|
} else {
|
||||||
int count = (ucred.cr_ngroups < GLIBTOP_MAX_GROUPS) ?
|
int count = (ucred.cr_ngroups < GLIBTOP_MAX_GROUPS) ?
|
||||||
ucred.cr_ngroups : GLIBTOP_MAX_GROUPS;
|
ucred.cr_ngroups : GLIBTOP_MAX_GROUPS;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
buf->groups [i] = ucred.cr_groups [i];
|
buf->groups [i] = ucred.cr_groups [i];
|
||||||
buf->ngroups = count;
|
buf->ngroups = count;
|
||||||
|
|
||||||
buf->flags |= _glibtop_sysdeps_proc_uid_groups;
|
buf->flags |= _glibtop_sysdeps_proc_uid_groups;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -34,17 +36,17 @@ int
|
|||||||
glibtop_init_sem_limits_p (glibtop *server)
|
glibtop_init_sem_limits_p (glibtop *server)
|
||||||
{
|
{
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||||
{
|
{
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -74,8 +76,8 @@ static struct seminfo _seminfo;
|
|||||||
|
|
||||||
/* nlist structure for kernel access */
|
/* nlist structure for kernel access */
|
||||||
static struct nlist nlst [] = {
|
static struct nlist nlst [] = {
|
||||||
{ "_seminfo" },
|
{ "_seminfo" },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Init function. */
|
/* Init function. */
|
||||||
@@ -83,20 +85,20 @@ static struct nlist nlst [] = {
|
|||||||
int
|
int
|
||||||
glibtop_init_sem_limits_p (glibtop *server)
|
glibtop_init_sem_limits_p (glibtop *server)
|
||||||
{
|
{
|
||||||
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
||||||
glibtop_warn_io_r (server, "kvm_nlist (sem_limits)");
|
glibtop_warn_io_r (server, "kvm_nlist (sem_limits)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||||
&_seminfo, sizeof (_seminfo)) != sizeof (_seminfo)) {
|
&_seminfo, sizeof (_seminfo)) != sizeof (_seminfo)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (seminfo)");
|
glibtop_warn_io_r (server, "kvm_read (seminfo)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
|
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides information about sysv sem limits. */
|
/* Provides information about sysv sem limits. */
|
||||||
@@ -104,25 +106,25 @@ glibtop_init_sem_limits_p (glibtop *server)
|
|||||||
int
|
int
|
||||||
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||||
{
|
{
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||||
|
|
||||||
if (server->sysdeps.sem_limits == 0)
|
if (server->sysdeps.sem_limits == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
buf->semmap = _seminfo.semmap;
|
buf->semmap = _seminfo.semmap;
|
||||||
buf->semmni = _seminfo.semmni;
|
buf->semmni = _seminfo.semmni;
|
||||||
buf->semmns = _seminfo.semmns;
|
buf->semmns = _seminfo.semmns;
|
||||||
buf->semmnu = _seminfo.semmnu;
|
buf->semmnu = _seminfo.semmnu;
|
||||||
buf->semmsl = _seminfo.semmsl;
|
buf->semmsl = _seminfo.semmsl;
|
||||||
buf->semopm = _seminfo.semopm;
|
buf->semopm = _seminfo.semopm;
|
||||||
buf->semvmx = _seminfo.semvmx;
|
buf->semvmx = _seminfo.semvmx;
|
||||||
buf->semaem = _seminfo.semaem;
|
buf->semaem = _seminfo.semaem;
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_sem_limits;
|
buf->flags = _glibtop_sysdeps_sem_limits;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* either a newer BSDI or no BSDI at all. */
|
#endif /* either a newer BSDI or no BSDI at all. */
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -34,17 +36,17 @@ int
|
|||||||
glibtop_init_shm_limits_p (glibtop *server)
|
glibtop_init_shm_limits_p (glibtop *server)
|
||||||
{
|
{
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||||
{
|
{
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -72,8 +74,8 @@ static struct shminfo _shminfo;
|
|||||||
|
|
||||||
/* nlist structure for kernel access */
|
/* nlist structure for kernel access */
|
||||||
static struct nlist nlst [] = {
|
static struct nlist nlst [] = {
|
||||||
{ "_shminfo" },
|
{ "_shminfo" },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Init function. */
|
/* Init function. */
|
||||||
@@ -81,20 +83,20 @@ static struct nlist nlst [] = {
|
|||||||
int
|
int
|
||||||
glibtop_init_shm_limits_p (glibtop *server)
|
glibtop_init_shm_limits_p (glibtop *server)
|
||||||
{
|
{
|
||||||
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
if (kvm_nlist (server->_priv->machine.kd, nlst) != 0) {
|
||||||
glibtop_warn_io_r (server, "kvm_nlist (shm_limits)");
|
glibtop_warn_io_r (server, "kvm_nlist (shm_limits)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
if (kvm_read (server->_priv->machine.kd, nlst [0].n_value,
|
||||||
&_shminfo, sizeof (_shminfo)) != sizeof (_shminfo)) {
|
&_shminfo, sizeof (_shminfo)) != sizeof (_shminfo)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (shminfo)");
|
glibtop_warn_io_r (server, "kvm_read (shminfo)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
|
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides information about sysv ipc limits. */
|
/* Provides information about sysv ipc limits. */
|
||||||
@@ -102,22 +104,22 @@ glibtop_init_shm_limits_p (glibtop *server)
|
|||||||
int
|
int
|
||||||
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||||
{
|
{
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||||
|
|
||||||
if (server->sysdeps.shm_limits == 0)
|
if (server->sysdeps.shm_limits == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
buf->shmmax = _shminfo.shmmax;
|
buf->shmmax = _shminfo.shmmax;
|
||||||
buf->shmmin = _shminfo.shmmin;
|
buf->shmmin = _shminfo.shmmin;
|
||||||
buf->shmmni = _shminfo.shmmni;
|
buf->shmmni = _shminfo.shmmni;
|
||||||
buf->shmseg = _shminfo.shmseg;
|
buf->shmseg = _shminfo.shmseg;
|
||||||
buf->shmall = _shminfo.shmall;
|
buf->shmall = _shminfo.shmall;
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_shm_limits;
|
buf->flags = _glibtop_sysdeps_shm_limits;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* either a newer BSDI or no BSDI at all. */
|
#endif /* either a newer BSDI or no BSDI at all. */
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -50,22 +52,22 @@ static const unsigned long _glibtop_sysdeps_swap =
|
|||||||
|
|
||||||
#if defined(__bsdi__)
|
#if defined(__bsdi__)
|
||||||
static struct nlist nlst [] = {
|
static struct nlist nlst [] = {
|
||||||
{ "_swapstats" }, /* general swap info */
|
{ "_swapstats" }, /* general swap info */
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
#elif __FreeBSD__ < 4
|
#elif __FreeBSD__ < 4
|
||||||
static struct nlist nlst [] = {
|
static struct nlist nlst [] = {
|
||||||
#define VM_SWAPLIST 0
|
#define VM_SWAPLIST 0
|
||||||
{ "_swaplist" },/* list of free swap areas */
|
{ "_swaplist" },/* list of free swap areas */
|
||||||
#define VM_SWDEVT 1
|
#define VM_SWDEVT 1
|
||||||
{ "_swdevt" }, /* list of swap devices and sizes */
|
{ "_swdevt" }, /* list of swap devices and sizes */
|
||||||
#define VM_NSWAP 2
|
#define VM_NSWAP 2
|
||||||
{ "_nswap" }, /* size of largest swap device */
|
{ "_nswap" }, /* size of largest swap device */
|
||||||
#define VM_NSWDEV 3
|
#define VM_NSWDEV 3
|
||||||
{ "_nswdev" }, /* number of swap devices */
|
{ "_nswdev" }, /* number of swap devices */
|
||||||
#define VM_DMMAX 4
|
#define VM_DMMAX 4
|
||||||
{ "_dmmax" }, /* maximum size of a swap block */
|
{ "_dmmax" }, /* maximum size of a swap block */
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -85,8 +87,8 @@ static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
|
|||||||
#else
|
#else
|
||||||
/* nlist structure for kernel access */
|
/* nlist structure for kernel access */
|
||||||
static struct nlist nlst2 [] = {
|
static struct nlist nlst2 [] = {
|
||||||
{ "_cnt" },
|
{ "_cnt" },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -97,30 +99,30 @@ glibtop_init_swap_p (glibtop *server)
|
|||||||
{
|
{
|
||||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||||
#if __FreeBSD__ < 4 || defined(__bsdi__)
|
#if __FreeBSD__ < 4 || defined(__bsdi__)
|
||||||
if (kvm_nlist (server->machine.kd, nlst) != 0) {
|
if (kvm_nlist (server->machine.kd, nlst) != 0) {
|
||||||
glibtop_warn_io_r (server, "kvm_nlist (swap)");
|
glibtop_warn_io_r (server, "kvm_nlist (swap)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct kvm_swap dummy;
|
struct kvm_swap dummy;
|
||||||
|
|
||||||
if (kvm_getswapinfo (server->machine.kd, &dummy, 1, 0) != 0) {
|
if (kvm_getswapinfo (server->machine.kd, &dummy, 1, 0) != 0) {
|
||||||
glibtop_warn_io_r (server, "kvm_swap (swap)");
|
glibtop_warn_io_r (server, "kvm_swap (swap)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||||
if (kvm_nlist (server->machine.kd, nlst2) != 0) {
|
if (kvm_nlist (server->machine.kd, nlst2) != 0) {
|
||||||
glibtop_warn_io_r (server, "kvm_nlist (cnt)");
|
glibtop_warn_io_r (server, "kvm_nlist (cnt)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
server->sysdeps.swap = _glibtop_sysdeps_swap;
|
server->sysdeps.swap = _glibtop_sysdeps_swap;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides information about swap usage. */
|
/* Provides information about swap usage. */
|
||||||
@@ -136,91 +138,91 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
|||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
|
|
||||||
# if __FreeBSD__ < 4
|
# if __FreeBSD__ < 4
|
||||||
char *header;
|
char *header;
|
||||||
int hlen, nswdev, dmmax;
|
int hlen, nswdev, dmmax;
|
||||||
int div, nfree, npfree;
|
int div, nfree, npfree;
|
||||||
struct swdevt *sw;
|
struct swdevt *sw;
|
||||||
long blocksize, *perdev;
|
long blocksize, *perdev;
|
||||||
struct rlist head;
|
struct rlist head;
|
||||||
struct rlisthdr swaplist;
|
struct rlisthdr swaplist;
|
||||||
struct rlist *swapptr;
|
struct rlist *swapptr;
|
||||||
size_t sw_size;
|
size_t sw_size;
|
||||||
u_long ptr;
|
u_long ptr;
|
||||||
# else
|
# else
|
||||||
int nswdev;
|
int nswdev;
|
||||||
struct kvm_swap kvmsw[16];
|
struct kvm_swap kvmsw[16];
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#elif defined(__bsdi__)
|
#elif defined(__bsdi__)
|
||||||
struct swapstats swap;
|
struct swapstats swap;
|
||||||
#elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
struct swapent *swaplist;
|
struct swapent *swaplist;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int nswap, i;
|
int nswap, i;
|
||||||
int avail = 0, inuse = 0;
|
int avail = 0, inuse = 0;
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
struct uvmexp uvmexp;
|
struct uvmexp uvmexp;
|
||||||
size_t length_uvmexp;
|
size_t length_uvmexp;
|
||||||
#else
|
#else
|
||||||
/* To get `pagein' and `pageout'. */
|
/* To get `pagein' and `pageout'. */
|
||||||
struct vmmeter vmm;
|
struct vmmeter vmm;
|
||||||
#endif
|
#endif
|
||||||
static int swappgsin = -1;
|
static int swappgsin = -1;
|
||||||
static int swappgsout = -1;
|
static int swappgsout = -1;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SWAP), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_SWAP), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_swap));
|
memset (buf, 0, sizeof (glibtop_swap));
|
||||||
|
|
||||||
if (server->sysdeps.swap == 0)
|
if (server->sysdeps.swap == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
length_uvmexp = sizeof (uvmexp);
|
length_uvmexp = sizeof (uvmexp);
|
||||||
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
|
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
|
||||||
glibtop_warn_io_r (server, "sysctl (uvmexp)");
|
glibtop_warn_io_r (server, "sysctl (uvmexp)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* This is used to get the `pagein' and `pageout' members. */
|
/* This is used to get the `pagein' and `pageout' members. */
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, nlst2[0].n_value,
|
if (kvm_read (server->machine.kd, nlst2[0].n_value,
|
||||||
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (swappgsin < 0) {
|
if (swappgsin < 0) {
|
||||||
buf->pagein = 0;
|
buf->pagein = 0;
|
||||||
buf->pageout = 0;
|
buf->pageout = 0;
|
||||||
} else {
|
} else {
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
buf->pagein = vmm.v_swappgsin - swappgsin;
|
buf->pagein = vmm.v_swappgsin - swappgsin;
|
||||||
buf->pageout = vmm.v_swappgsout - swappgsout;
|
buf->pageout = vmm.v_swappgsout - swappgsout;
|
||||||
#else
|
#else
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
buf->pagein = uvmexp.swapins - swappgsin;
|
buf->pagein = uvmexp.swapins - swappgsin;
|
||||||
buf->pageout = uvmexp.swapouts - swappgsout;
|
buf->pageout = uvmexp.swapouts - swappgsout;
|
||||||
#else
|
#else
|
||||||
buf->pagein = vmm.v_swpin - swappgsin;
|
buf->pagein = vmm.v_swpin - swappgsin;
|
||||||
buf->pageout = vmm.v_swpout - swappgsout;
|
buf->pageout = vmm.v_swpout - swappgsout;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
swappgsin = vmm.v_swappgsin;
|
swappgsin = vmm.v_swappgsin;
|
||||||
swappgsout = vmm.v_swappgsout;
|
swappgsout = vmm.v_swappgsout;
|
||||||
#else
|
#else
|
||||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||||
swappgsin = uvmexp.swapins;
|
swappgsin = uvmexp.swapins;
|
||||||
swappgsout = uvmexp.swapouts;
|
swappgsout = uvmexp.swapouts;
|
||||||
#else
|
#else
|
||||||
swappgsin = vmm.v_swpin;
|
swappgsin = vmm.v_swpin;
|
||||||
swappgsout = vmm.v_swpout;
|
swappgsout = vmm.v_swpout;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -228,203 +230,203 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
|||||||
|
|
||||||
#if __FreeBSD__ < 4
|
#if __FreeBSD__ < 4
|
||||||
|
|
||||||
/* Size of largest swap device. */
|
/* Size of largest swap device. */
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, nlst[VM_NSWAP].n_value,
|
if (kvm_read (server->machine.kd, nlst[VM_NSWAP].n_value,
|
||||||
&nswap, sizeof (nswap)) != sizeof (nswap)) {
|
&nswap, sizeof (nswap)) != sizeof (nswap)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (nswap)");
|
glibtop_warn_io_r (server, "kvm_read (nswap)");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Number of swap devices. */
|
||||||
|
|
||||||
|
if (kvm_read (server->machine.kd, nlst[VM_NSWDEV].n_value,
|
||||||
|
&nswdev, sizeof (nswdev)) != sizeof (nswdev)) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (nswdev)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Maximum size of a swap block. */
|
||||||
|
|
||||||
|
if (kvm_read (server->machine.kd, nlst[VM_DMMAX].n_value,
|
||||||
|
&dmmax, sizeof (dmmax)) != sizeof (dmmax)) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (dmmax)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List of free swap areas. */
|
||||||
|
|
||||||
|
if (kvm_read (server->machine.kd, nlst[VM_SWAPLIST].n_value,
|
||||||
|
&swaplist, sizeof (swaplist)) != sizeof (swaplist)) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (swaplist)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Kernel offset of list of swap devices and sizes. */
|
||||||
|
|
||||||
|
if (kvm_read (server->machine.kd, nlst[VM_SWDEVT].n_value,
|
||||||
|
&ptr, sizeof (ptr)) != sizeof (ptr)) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (swdevt)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List of swap devices and sizes. */
|
||||||
|
|
||||||
|
sw_size = nswdev * sizeof (*sw);
|
||||||
|
sw = glibtop_malloc_r (server, sw_size);
|
||||||
|
|
||||||
|
if (kvm_read (server->machine.kd, ptr, sw, sw_size) != (ssize_t)sw_size) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (*swdevt)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
perdev = glibtop_malloc (nswdev * sizeof (*perdev));
|
||||||
|
|
||||||
|
/* Count up swap space. */
|
||||||
|
|
||||||
|
nfree = 0;
|
||||||
|
memset (perdev, 0, nswdev * sizeof(*perdev));
|
||||||
|
|
||||||
|
swapptr = swaplist.rlh_list;
|
||||||
|
|
||||||
|
while (swapptr) {
|
||||||
|
int top, bottom, next_block;
|
||||||
|
|
||||||
|
if (kvm_read (server->machine.kd, (int) swapptr, &head,
|
||||||
|
sizeof (struct rlist)) != sizeof (struct rlist)) {
|
||||||
|
glibtop_warn_io_r (server, "kvm_read (swapptr)");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Number of swap devices. */
|
top = head.rl_end;
|
||||||
|
bottom = head.rl_start;
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, nlst[VM_NSWDEV].n_value,
|
nfree += top - bottom + 1;
|
||||||
&nswdev, sizeof (nswdev)) != sizeof (nswdev)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (nswdev)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Maximum size of a swap block. */
|
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, nlst[VM_DMMAX].n_value,
|
|
||||||
&dmmax, sizeof (dmmax)) != sizeof (dmmax)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (dmmax)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* List of free swap areas. */
|
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, nlst[VM_SWAPLIST].n_value,
|
|
||||||
&swaplist, sizeof (swaplist)) != sizeof (swaplist)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (swaplist)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Kernel offset of list of swap devices and sizes. */
|
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, nlst[VM_SWDEVT].n_value,
|
|
||||||
&ptr, sizeof (ptr)) != sizeof (ptr)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (swdevt)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* List of swap devices and sizes. */
|
|
||||||
|
|
||||||
sw_size = nswdev * sizeof (*sw);
|
|
||||||
sw = glibtop_malloc_r (server, sw_size);
|
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, ptr, sw, sw_size) != (ssize_t)sw_size) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (*swdevt)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
perdev = glibtop_malloc (nswdev * sizeof (*perdev));
|
|
||||||
|
|
||||||
/* Count up swap space. */
|
|
||||||
|
|
||||||
nfree = 0;
|
|
||||||
memset (perdev, 0, nswdev * sizeof(*perdev));
|
|
||||||
|
|
||||||
swapptr = swaplist.rlh_list;
|
|
||||||
|
|
||||||
while (swapptr) {
|
|
||||||
int top, bottom, next_block;
|
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, (int) swapptr, &head,
|
|
||||||
sizeof (struct rlist)) != sizeof (struct rlist)) {
|
|
||||||
glibtop_warn_io_r (server, "kvm_read (swapptr)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
top = head.rl_end;
|
|
||||||
bottom = head.rl_start;
|
|
||||||
|
|
||||||
nfree += top - bottom + 1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Swap space is split up among the configured disks.
|
|
||||||
*
|
|
||||||
* For interleaved swap devices, the first dmmax blocks
|
|
||||||
* of swap space some from the first disk, the next dmmax
|
|
||||||
* blocks from the next, and so on up to nswap blocks.
|
|
||||||
*
|
|
||||||
* The list of free space joins adjacent free blocks,
|
|
||||||
* ignoring device boundries. If we want to keep track
|
|
||||||
* of this information per device, we'll just have to
|
|
||||||
* extract it ourselves.
|
|
||||||
*/
|
|
||||||
while (top / dmmax != bottom / dmmax) {
|
|
||||||
next_block = ((bottom + dmmax) / dmmax);
|
|
||||||
perdev[(bottom / dmmax) % nswdev] +=
|
|
||||||
next_block * dmmax - bottom;
|
|
||||||
bottom = next_block * dmmax;
|
|
||||||
}
|
|
||||||
perdev[(bottom / dmmax) % nswdev] +=
|
|
||||||
top - bottom + 1;
|
|
||||||
|
|
||||||
swapptr = head.rl_next;
|
|
||||||
}
|
|
||||||
|
|
||||||
header = getbsize (&hlen, &blocksize);
|
|
||||||
|
|
||||||
div = blocksize / 512;
|
|
||||||
avail = npfree = 0;
|
|
||||||
for (i = 0; i < nswdev; i++) {
|
|
||||||
int xsize, xfree;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Don't report statistics for partitions which have not
|
|
||||||
* yet been activated via swapon(8).
|
|
||||||
*/
|
|
||||||
if (!(sw[i].sw_flags & SW_FREED))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* The first dmmax is never allocated to avoid trashing of
|
|
||||||
* disklabels
|
|
||||||
*/
|
|
||||||
xsize = sw[i].sw_nblks - dmmax;
|
|
||||||
xfree = perdev[i];
|
|
||||||
inuse = xsize - xfree;
|
|
||||||
npfree++;
|
|
||||||
avail += xsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If only one partition has been set up via swapon(8), we don't
|
* Swap space is split up among the configured disks.
|
||||||
* need to bother with totals.
|
*
|
||||||
|
* For interleaved swap devices, the first dmmax blocks
|
||||||
|
* of swap space some from the first disk, the next dmmax
|
||||||
|
* blocks from the next, and so on up to nswap blocks.
|
||||||
|
*
|
||||||
|
* The list of free space joins adjacent free blocks,
|
||||||
|
* ignoring device boundries. If we want to keep track
|
||||||
|
* of this information per device, we'll just have to
|
||||||
|
* extract it ourselves.
|
||||||
*/
|
*/
|
||||||
inuse = avail - nfree;
|
while (top / dmmax != bottom / dmmax) {
|
||||||
|
next_block = ((bottom + dmmax) / dmmax);
|
||||||
|
perdev[(bottom / dmmax) % nswdev] +=
|
||||||
|
next_block * dmmax - bottom;
|
||||||
|
bottom = next_block * dmmax;
|
||||||
|
}
|
||||||
|
perdev[(bottom / dmmax) % nswdev] +=
|
||||||
|
top - bottom + 1;
|
||||||
|
|
||||||
glibtop_free_r (server, sw);
|
swapptr = head.rl_next;
|
||||||
glibtop_free_r (server, perdev);
|
}
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_swap;
|
header = getbsize (&hlen, &blocksize);
|
||||||
|
|
||||||
buf->used = inuse;
|
div = blocksize / 512;
|
||||||
buf->free = avail;
|
avail = npfree = 0;
|
||||||
|
for (i = 0; i < nswdev; i++) {
|
||||||
|
int xsize, xfree;
|
||||||
|
|
||||||
buf->total = inuse + avail;
|
/*
|
||||||
|
* Don't report statistics for partitions which have not
|
||||||
|
* yet been activated via swapon(8).
|
||||||
|
*/
|
||||||
|
if (!(sw[i].sw_flags & SW_FREED))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* The first dmmax is never allocated to avoid trashing of
|
||||||
|
* disklabels
|
||||||
|
*/
|
||||||
|
xsize = sw[i].sw_nblks - dmmax;
|
||||||
|
xfree = perdev[i];
|
||||||
|
inuse = xsize - xfree;
|
||||||
|
npfree++;
|
||||||
|
avail += xsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If only one partition has been set up via swapon(8), we don't
|
||||||
|
* need to bother with totals.
|
||||||
|
*/
|
||||||
|
inuse = avail - nfree;
|
||||||
|
|
||||||
|
glibtop_free_r (server, sw);
|
||||||
|
glibtop_free_r (server, perdev);
|
||||||
|
|
||||||
|
buf->flags = _glibtop_sysdeps_swap;
|
||||||
|
|
||||||
|
buf->used = inuse;
|
||||||
|
buf->free = avail;
|
||||||
|
|
||||||
|
buf->total = inuse + avail;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
nswdev = kvm_getswapinfo(server->machine.kd, kvmsw, 16, 0);
|
nswdev = kvm_getswapinfo(server->machine.kd, kvmsw, 16, 0);
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_swap;
|
buf->flags = _glibtop_sysdeps_swap;
|
||||||
|
|
||||||
buf->used = kvmsw[nswdev].ksw_used;
|
buf->used = kvmsw[nswdev].ksw_used;
|
||||||
buf->total = kvmsw[nswdev].ksw_total;
|
buf->total = kvmsw[nswdev].ksw_total;
|
||||||
|
|
||||||
buf->free = buf->total - buf->used;
|
buf->free = buf->total - buf->used;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__bsdi__)
|
#elif defined(__bsdi__)
|
||||||
|
|
||||||
/* General info about swap devices. */
|
/* General info about swap devices. */
|
||||||
|
|
||||||
if (kvm_read (server->machine.kd, nlst[0].n_value,
|
if (kvm_read (server->machine.kd, nlst[0].n_value,
|
||||||
&swap, sizeof (swap)) != sizeof (swap)) {
|
&swap, sizeof (swap)) != sizeof (swap)) {
|
||||||
glibtop_warn_io_r (server, "kvm_read (swap)");
|
glibtop_warn_io_r (server, "kvm_read (swap)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_swap;
|
buf->flags = _glibtop_sysdeps_swap;
|
||||||
|
|
||||||
buf->used = swap.swap_total - swap.swap_free;
|
buf->used = swap.swap_total - swap.swap_free;
|
||||||
buf->free = swap.swap_free;
|
buf->free = swap.swap_free;
|
||||||
|
|
||||||
buf->total = swap.swap_total;
|
buf->total = swap.swap_total;
|
||||||
|
|
||||||
#elif defined(__NetBSD__)
|
#elif defined(__NetBSD__)
|
||||||
|
|
||||||
nswap = swapctl (SWAP_NSWAP, NULL, 0);
|
nswap = swapctl (SWAP_NSWAP, NULL, 0);
|
||||||
if (nswap < 0) {
|
if (nswap < 0) {
|
||||||
glibtop_warn_io_r (server, "swapctl (SWAP_NSWAP)");
|
glibtop_warn_io_r (server, "swapctl (SWAP_NSWAP)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
swaplist = glibtop_calloc_r (server, nswap, sizeof (struct swapent));
|
swaplist = glibtop_calloc_r (server, nswap, sizeof (struct swapent));
|
||||||
|
|
||||||
if (swapctl (SWAP_STATS, swaplist, nswap) != nswap) {
|
|
||||||
glibtop_warn_io_r (server, "swapctl (SWAP_STATS)");
|
|
||||||
glibtop_free_r (server, swaplist);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < nswap; i++) {
|
|
||||||
avail += swaplist[i].se_nblks;
|
|
||||||
inuse += swaplist[i].se_inuse;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (swapctl (SWAP_STATS, swaplist, nswap) != nswap) {
|
||||||
|
glibtop_warn_io_r (server, "swapctl (SWAP_STATS)");
|
||||||
glibtop_free_r (server, swaplist);
|
glibtop_free_r (server, swaplist);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_swap;
|
for (i = 0; i < nswap; i++) {
|
||||||
|
avail += swaplist[i].se_nblks;
|
||||||
|
inuse += swaplist[i].se_inuse;
|
||||||
|
}
|
||||||
|
|
||||||
buf->used = inuse;
|
glibtop_free_r (server, swaplist);
|
||||||
buf->free = avail;
|
|
||||||
|
|
||||||
buf->total = inuse + avail;
|
buf->flags = _glibtop_sysdeps_swap;
|
||||||
|
|
||||||
|
buf->used = inuse;
|
||||||
|
buf->free = avail;
|
||||||
|
|
||||||
|
buf->total = inuse + avail;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -41,9 +43,9 @@ static const unsigned long _required_cpu_flags =
|
|||||||
int
|
int
|
||||||
glibtop_init_uptime_p (glibtop *server)
|
glibtop_init_uptime_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
|
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides uptime and idle time. */
|
/* Provides uptime and idle time. */
|
||||||
@@ -51,27 +53,27 @@ glibtop_init_uptime_p (glibtop *server)
|
|||||||
int
|
int
|
||||||
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
||||||
{
|
{
|
||||||
glibtop_cpu cpu;
|
glibtop_cpu cpu;
|
||||||
|
|
||||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0);
|
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_uptime));
|
memset (buf, 0, sizeof (glibtop_uptime));
|
||||||
|
|
||||||
/* We simply calculate it from the CPU usage. */
|
/* We simply calculate it from the CPU usage. */
|
||||||
|
|
||||||
glibtop_get_cpu_p (server, &cpu);
|
glibtop_get_cpu_p (server, &cpu);
|
||||||
|
|
||||||
/* Make sure all required fields are present. */
|
/* Make sure all required fields are present. */
|
||||||
|
|
||||||
if ((cpu.flags & _required_cpu_flags) != _required_cpu_flags)
|
if ((cpu.flags & _required_cpu_flags) != _required_cpu_flags)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Calculate values. */
|
/* Calculate values. */
|
||||||
|
|
||||||
buf->uptime = (double) cpu.total / (double) cpu.frequency;
|
buf->uptime = (double) cpu.total / (double) cpu.frequency;
|
||||||
buf->idletime = (double) cpu.idle / (double) cpu.frequency;
|
buf->idletime = (double) cpu.idle / (double) cpu.frequency;
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_uptime;
|
buf->flags = _glibtop_sysdeps_uptime;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -29,5 +31,5 @@ void
|
|||||||
glibtop_open_s (glibtop *server, const char *program_name,
|
glibtop_open_s (glibtop *server, const char *program_name,
|
||||||
const unsigned long features, const unsigned flags)
|
const unsigned long features, const unsigned flags)
|
||||||
{
|
{
|
||||||
server->name = program_name;
|
server->name = program_name;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -44,7 +46,7 @@ static const unsigned long _glibtop_sysdeps_ppp =
|
|||||||
int
|
int
|
||||||
glibtop_init_ppp_s (glibtop *server)
|
glibtop_init_ppp_s (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -52,129 +54,129 @@ glibtop_init_ppp_s (glibtop *server)
|
|||||||
static int
|
static int
|
||||||
get_ISDN_stats (glibtop *server, int *in, int *out)
|
get_ISDN_stats (glibtop *server, int *in, int *out)
|
||||||
{
|
{
|
||||||
unsigned long *isdn_stats, *ptr;
|
unsigned long *isdn_stats, *ptr;
|
||||||
int fd, i;
|
int fd, i;
|
||||||
|
|
||||||
*in = *out = 0;
|
*in = *out = 0;
|
||||||
|
|
||||||
isdn_stats = glibtop_calloc_r (server, ISDN_MAX_CHANNELS * 2,
|
isdn_stats = glibtop_calloc_r (server, ISDN_MAX_CHANNELS * 2,
|
||||||
sizeof (unsigned long));
|
sizeof (unsigned long));
|
||||||
|
|
||||||
fd = open ("/dev/isdninfo", O_RDONLY);
|
fd = open ("/dev/isdninfo", O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
glibtop_free_r (server, isdn_stats);
|
glibtop_free_r (server, isdn_stats);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
|
|
||||||
glibtop_free_r (server, isdn_stats);
|
|
||||||
close (fd);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
|
|
||||||
*in += *ptr++; *out += *ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
|
||||||
glibtop_free_r (server, isdn_stats);
|
glibtop_free_r (server, isdn_stats);
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
return TRUE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
|
||||||
|
*in += *ptr++; *out += *ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
glibtop_free_r (server, isdn_stats);
|
||||||
|
close (fd);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_ISDN_on (glibtop *server, int *online)
|
static int is_ISDN_on (glibtop *server, int *online)
|
||||||
{
|
{
|
||||||
FILE *f = 0;
|
FILE *f = 0;
|
||||||
char buffer [BUFSIZ], *p;
|
char buffer [BUFSIZ], *p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Perhaps I should try to explain this code a little bit.
|
/* Perhaps I should try to explain this code a little bit.
|
||||||
*
|
*
|
||||||
* ------------------------------------------------------------
|
* ------------------------------------------------------------
|
||||||
* This is from the manpage of isdninfo(4):
|
* This is from the manpage of isdninfo(4):
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* /dev/isdninfo is a character device with major number 45
|
* /dev/isdninfo is a character device with major number 45
|
||||||
* and minor number 255. It delivers status information from
|
* and minor number 255. It delivers status information from
|
||||||
* the Linux ISDN subsystem to user level.
|
* the Linux ISDN subsystem to user level.
|
||||||
*
|
*
|
||||||
* DATA FORMAT
|
* DATA FORMAT
|
||||||
* When reading from this device, the current status of the
|
* When reading from this device, the current status of the
|
||||||
* Linux ISDN subsystem is delivered in 6 lines of text. Each
|
* Linux ISDN subsystem is delivered in 6 lines of text. Each
|
||||||
* line starts with a tag string followed by a colon and
|
* line starts with a tag string followed by a colon and
|
||||||
* whitespace. After that the status values are appended sep-
|
* whitespace. After that the status values are appended sep-
|
||||||
* arated by whitespace.
|
* arated by whitespace.
|
||||||
*
|
*
|
||||||
* flags is the tag of line 5. In this line for every driver
|
* flags is the tag of line 5. In this line for every driver
|
||||||
* slot, it's B-Channel status is shown. If no driver
|
* slot, it's B-Channel status is shown. If no driver
|
||||||
* is registered in a slot, a ? is shown. For every
|
* is registered in a slot, a ? is shown. For every
|
||||||
* established B-Channel of the driver, a bit is set
|
* established B-Channel of the driver, a bit is set
|
||||||
* in the shown value. The driver's first channel is
|
* in the shown value. The driver's first channel is
|
||||||
* mapped to bit 0, the second channel to bit 1 and so
|
* mapped to bit 0, the second channel to bit 1 and so
|
||||||
* on.
|
* on.
|
||||||
* ------------------------------------------------------------
|
* ------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* So we open /dev/isdninfo, discard the first four lines of text
|
* So we open /dev/isdninfo, discard the first four lines of text
|
||||||
* and then check whether we have something that is not `0' or `?'
|
* and then check whether we have something that is not `0' or `?'
|
||||||
* in one of the flags fields.
|
* in one of the flags fields.
|
||||||
*
|
*
|
||||||
* Sounds complicated, but I don't see any other way to check whether
|
* Sounds complicated, but I don't see any other way to check whether
|
||||||
* we are connected. Also, this is the method some other ISDN tools
|
* we are connected. Also, this is the method some other ISDN tools
|
||||||
* for Linux use.
|
* for Linux use.
|
||||||
*
|
*
|
||||||
* Martin
|
* Martin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
f = fopen ("/dev/isdninfo", "r");
|
f = fopen ("/dev/isdninfo", "r");
|
||||||
|
|
||||||
if (!f) return FALSE;
|
if (!f) return FALSE;
|
||||||
|
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
if (fgets (buffer, BUFSIZ, f) == NULL) {
|
if (fgets (buffer, BUFSIZ, f) == NULL) {
|
||||||
fclose (f);
|
fclose (f);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp (buffer, "flags:", 6)) {
|
||||||
|
fclose (f);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = buffer+6;
|
||||||
|
|
||||||
|
while (*p) {
|
||||||
|
char *end = p;
|
||||||
|
|
||||||
|
if (isspace (*p)) {
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp (buffer, "flags:", 6)) {
|
for (end = p; *end && !isspace (*end); end++)
|
||||||
fclose (f);
|
;
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = buffer+6;
|
if (*end == 0)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
*end = 0;
|
||||||
|
|
||||||
while (*p) {
|
if (!strcmp (p, "?") || !strcmp (p, "0")) {
|
||||||
char *end = p;
|
p = end+1;
|
||||||
|
continue;
|
||||||
if (isspace (*p)) {
|
|
||||||
p++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (end = p; *end && !isspace (*end); end++)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (*end == 0)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
*end = 0;
|
|
||||||
|
|
||||||
if (!strcmp (p, "?") || !strcmp (p, "0")) {
|
|
||||||
p = end+1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose (f);
|
|
||||||
|
|
||||||
*online = TRUE;
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (f);
|
fclose (f);
|
||||||
|
|
||||||
*online = FALSE;
|
*online = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose (f);
|
||||||
|
|
||||||
|
*online = FALSE;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides PPP/ISDN information. */
|
/* Provides PPP/ISDN information. */
|
||||||
@@ -182,24 +184,24 @@ static int is_ISDN_on (glibtop *server, int *online)
|
|||||||
int
|
int
|
||||||
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
|
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
|
||||||
{
|
{
|
||||||
int in, out, online;
|
int in, out, online;
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PPP, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PPP, 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_ppp));
|
memset (buf, 0, sizeof (glibtop_ppp));
|
||||||
|
|
||||||
if (is_ISDN_on (server, &online)) {
|
if (is_ISDN_on (server, &online)) {
|
||||||
buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
|
buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
|
||||||
GLIBTOP_PPP_STATE_HANGUP;
|
GLIBTOP_PPP_STATE_HANGUP;
|
||||||
buf->flags |= (1L << GLIBTOP_PPP_STATE);
|
buf->flags |= (1L << GLIBTOP_PPP_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_ISDN_stats (server, &in, &out)) {
|
if (get_ISDN_stats (server, &in, &out)) {
|
||||||
buf->bytes_in = in;
|
buf->bytes_in = in;
|
||||||
buf->bytes_out = out;
|
buf->bytes_out = out;
|
||||||
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
|
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
|
||||||
(1L << GLIBTOP_PPP_BYTES_OUT);
|
(1L << GLIBTOP_PPP_BYTES_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
@@ -35,62 +37,62 @@ static glibtop_sysinfo sysinfo;
|
|||||||
static void
|
static void
|
||||||
init_sysinfo (glibtop *server)
|
init_sysinfo (glibtop *server)
|
||||||
{
|
{
|
||||||
char buffer [BUFSIZ];
|
char buffer [BUFSIZ];
|
||||||
static int init = 0;
|
static int init = 0;
|
||||||
glibtop_entry *cpuinfo = NULL;
|
glibtop_entry *cpuinfo = NULL;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if (init) return;
|
if (init) return;
|
||||||
|
|
||||||
init = TRUE;
|
init = TRUE;
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||||
|
|
||||||
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
|
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
|
||||||
|
|
||||||
g_return_if_fail (f = fopen ("/proc/cpuinfo", "r"));
|
g_return_if_fail (f = fopen ("/proc/cpuinfo", "r"));
|
||||||
|
|
||||||
while (fgets (buffer, BUFSIZ, f)) {
|
while (fgets (buffer, BUFSIZ, f)) {
|
||||||
char *p, *start, *key, *value;
|
char *p, *start, *key, *value;
|
||||||
|
|
||||||
if (cpuinfo == NULL) {
|
if (cpuinfo == NULL) {
|
||||||
cpuinfo = &sysinfo.cpuinfo [sysinfo.ncpu++];
|
cpuinfo = &sysinfo.cpuinfo [sysinfo.ncpu++];
|
||||||
|
|
||||||
cpuinfo->labels = g_ptr_array_new ();
|
cpuinfo->labels = g_ptr_array_new ();
|
||||||
|
|
||||||
cpuinfo->values = g_hash_table_new (NULL, NULL);
|
cpuinfo->values = g_hash_table_new (NULL, NULL);
|
||||||
|
|
||||||
if (sysinfo.ncpu > GLIBTOP_NCPU)
|
if (sysinfo.ncpu > GLIBTOP_NCPU)
|
||||||
sysinfo.ncpu = GLIBTOP_NCPU;
|
sysinfo.ncpu = GLIBTOP_NCPU;
|
||||||
}
|
|
||||||
|
|
||||||
p = strchr (buffer, ':');
|
|
||||||
if (!p) continue;
|
|
||||||
|
|
||||||
/* Remove leading spaces from `p'. */
|
|
||||||
*p = '\0'; start = p; p++;
|
|
||||||
while (isspace (*p)) p++;
|
|
||||||
|
|
||||||
/* Remove trailing spaces from `buffer'. */
|
|
||||||
while ((start > buffer) && (*start) && isspace (*start))
|
|
||||||
*start-- = '\0';
|
|
||||||
|
|
||||||
key = g_strdup (buffer);
|
|
||||||
value = g_strdup (p);
|
|
||||||
|
|
||||||
g_ptr_array_add (cpuinfo->labels, key);
|
|
||||||
|
|
||||||
g_hash_table_insert (cpuinfo->values, key, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (f);
|
p = strchr (buffer, ':');
|
||||||
|
if (!p) continue;
|
||||||
|
|
||||||
sysinfo.flags = _glibtop_sysdeps_sysinfo;
|
/* Remove leading spaces from `p'. */
|
||||||
|
*p = '\0'; start = p; p++;
|
||||||
|
while (isspace (*p)) p++;
|
||||||
|
|
||||||
|
/* Remove trailing spaces from `buffer'. */
|
||||||
|
while ((start > buffer) && (*start) && isspace (*start))
|
||||||
|
*start-- = '\0';
|
||||||
|
|
||||||
|
key = g_strdup (buffer);
|
||||||
|
value = g_strdup (p);
|
||||||
|
|
||||||
|
g_ptr_array_add (cpuinfo->labels, key);
|
||||||
|
|
||||||
|
g_hash_table_insert (cpuinfo->values, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose (f);
|
||||||
|
|
||||||
|
sysinfo.flags = _glibtop_sysdeps_sysinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
glibtop_sysinfo *
|
glibtop_sysinfo *
|
||||||
glibtop_get_sysinfo_s (glibtop *server)
|
glibtop_get_sysinfo_s (glibtop *server)
|
||||||
{
|
{
|
||||||
init_sysinfo (server);
|
init_sysinfo (server);
|
||||||
return &sysinfo;
|
return &sysinfo;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/* Copyright (C) 1998-99 Martin Baulig
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user