Read pstatus info from /proc

* glibtop_private.h, procdata.c (glibtop_get_proc_signal_s):
        Read pstatus info from /proc

        * procsignal.c (glibtop_get_proc_signal_s): Implemented
        set of pending and blocked signals. The rest should probably
        be read from /proc/<pid>/sigact, but I'm not sure it's
        worth implementing before thread API comes into place.

        * siglist.c: Added Solaris 7 signals. Someone will gettextize
        it eventually. Besides, signal list should become a pointer
        instead of being fixed field. We need some run time initializations.
        The code is written, but commented out.
This commit is contained in:
Drazen Kacar
1999-05-03 00:03:52 +00:00
parent e1555fc335
commit 0408c86065
4 changed files with 141 additions and 4 deletions

View File

@@ -1,3 +1,18 @@
1999-05-03 Drazen Kacar <dave@srce.hr>
* glibtop_private.h, procdata.c (glibtop_get_proc_signal_s):
Read pstatus info from /proc
* procsignal.c (glibtop_get_proc_signal_s): Implemented
set of pending and blocked signals. The rest should probably
be read from /proc/<pid>/sigact, but I'm not sure it's
worth implementing before thread API comes into place.
* siglist.c: Added Solaris 7 signals. Someone will gettextize
it eventually. Besides, signal list should become a pointer
instead of being fixed field. We need some run time initializations.
The code is written, but commented out.
1999-05-03 Drazen Kacar <dave@srce.hr>
* glibtop_private.h: Ups, forgot to put prototypes in.

View File

@@ -40,9 +40,12 @@ int glibtop_get_proc_data_psinfo_s (glibtop *server, struct psinfo *psinfo, pid_
/* Read /proc/<pid>/usage */
int glibtop_get_proc_data_usage_s (glibtop *server, struct prusage *prusage, pid_t pid);
/* Read /proc<pid>/cred */
/* Read /proc/<pid>/cred */
int glibtop_get_proc_credentials_s(glibtop *, struct prcred *, pid_t);
/* Read /proc/<pid>/status */
glibtop_get_proc_status_s(glibtop *, struct pstatus *, pid_t);
/* Reread kstat chains */
void glibtop_get_kstats(glibtop *);

View File

@@ -24,7 +24,8 @@
#include <glibtop.h>
#include <glibtop/procsignal.h>
static const unsigned long _glibtop_sysdeps_proc_signal = 0;
static const unsigned long _glibtop_sysdeps_proc_signal =
(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1L << GLIBTOP_PROC_SIGNAL_BLOCKED);
/* Init function. */
@@ -40,5 +41,24 @@ void
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
pid_t pid)
{
struct pstatus pstatus;
int size;
memset (buf, 0, sizeof (glibtop_proc_signal));
if(glibtop_get_proc_status_s(server, &pstatus, pid))
return;
if(sizeof(buf->signal) < sizeof(sigset_t))
size = sizeof(buf->signal);
else
size = sizeof(sigset_t);
memcpy(buf->signal, &pstatus.pr_sigpend, size);
memcpy(buf->blocked, &pstatus.pr_lwp.pr_lwphold, size);
/* Technically, most of this is meaningless on a process level,
but this should be a good enough approximation. */
buf->flags = _glibtop_sysdeps_proc_signal;
}

View File

@@ -24,5 +24,104 @@
#include <glibtop.h>
#include <glibtop/signal.h>
const glibtop_signame glibtop_sys_siglist [] =
{ { 0, NULL, NULL } };
static const glibtop_signame glibtop_sys_siglist [] =
{ { 1, "SIGHUP", "Hangup" },
{ 2, "SIGINT", "Interrupt" },
{ 3, "SIGQUIT", "Quit" },
{ 4, "SIGILL", "Illegal instruction" },
{ 5, "SIGTRAP", "Trace or breakpoint trap" },
{ 6, "SIGABRT", "Abort" },
{ 7, "SIGEMT", "Emulation trap" },
{ 8, "SIGFPE", "Arithmetic exception" },
{ 9, "SIGKILL", "Kill" },
{ 10, "SIGBUS", "Bus error" },
{ 11, "SIGSEGV", "Segmentation fault" },
{ 12, "SIGSYS", "Bad system call" },
{ 13, "SIGPIPE", "Broken pipe" },
{ 14, "SIGALRM", "Alarm clock" },
{ 15, "SIGTERM", "Terminate" },
{ 16, "SIGUSR1", "User signal 1" },
{ 17, "SIGUSR2", "User signal 2" },
{ 18, "SIGCHLD", "Child status changed" },
{ 19, "SIGPWR", "Power fail or restart" },
{ 20, "SIGWINCH","Window size change" },
{ 21, "SIGURG", "Urgent socket condition" },
{ 22, "SIGPOLL", "Pollable event" },
{ 23, "SIGSTOP", "Stop (cannot be ignored)" },
{ 24, "SIGTSTP", "User stop requested from tty" },
{ 25, "SIGCONT", "Continue" },
{ 26, "SIGTTIN", "Background tty read attempted" },
{ 27, "SIGTTOU", "Background tty write attempted" },
{ 28, "SIGVTALRM","Virtual timer expired" },
{ 29, "SIGPROF", "Profiling timer expired" },
{ 30, "SIGXCPU", "CPU time limit exceeded" },
{ 31, "SIGXFSZ", "File size limit exceeded" },
{ 32, "SIGWAITING","process' lwps are blocked" },
{ 33, "SIGLWP", "Inter-LWP signal reserved by threads library" },
{ 34, "SIGFREEZE","Check point freeze" },
{ 35, "SIGTHAW", "Check point thaw" },
{ 36, "SIGCANCEL","Cancelation signal reserved by threads library" },
{ 37, "SIGLOST", "Resource lost" },
{ 0, NULL, NULL }
};
/*
* Now, just for the fun of it, let's try to be forward and backward
* compatible. The above list is from Solaris 7. If later releases
* include new signals, binary from the earlier release won't be
* able to get the signal names, but it can get the correct numbers.
* So...
*/
/*
#define MY_PRIVATE_COUNTOF(x) (sizeof(x)/sizeof(x[0]))
glibtop_signame *glibtop_sys_siglist;
static char *unknown = "Unknown";
static glibtop_signame rt_min =
{ 0, "SIGRTMIN", "First (highest-priority) realtime signal" };
static glibtop_signame rt_max =
{ 0, "SIGRTMIN", "Last (lowest-priority) realtime signal" };
static char *rt_desc = "Real time signal %d";
void
glibtop_init_signals(void)
{
int rtmin, rtmax, sigs, to, i;
char *bureq, p;
rtmin = sysconf(_SC_SIGRT_MIN);
rtmax = sysconf(_SC_SIGRT_MAX);
sigs = MY_PRIVATE_COUNTOF(siglist);
glibtop_sys_siglist = (glibtop_signame *)
malloc(rtmax * sizeof(glibtop_signame));
bureq = malloc((rtmax - rtmin - 1) * (strlen(rt_desc) + 4));
to = (sigs <= rtmin) ? sigs : rtmin;
memcpy(glibtop_sys_siglist, siglist, to * sizeof(glibtop_signame));
for(i = sigs; i < rtmin; ++i)
{
glibtop_sys_siglist[i].number = i + 1;
glibtop_sys_siglist[i].name = glibtop_sys_siglist[i].label = unknown;
}
glibtop_sys_siglist[rtmin - 1].number = rtmin;
glibtop_sys_siglist[rtmin - 1].name = rt_min.name;
glibtop_sys_siglist[rtmin - 1].label = rt_min.label;
for(p = bureq, i = rtmin; i < rtmax; ++i)
{
glibtop_sys_siglist[i].number = i + 1;
to = sprintf(p, "%d", i + 1) + 1;
glibtop_sys_siglist[i].name = p;
p += to;
to = sprintf(p, rt_desc, i - rtmin + 2) + 1;
glibtop_sys_siglist[i].label = p;
p += to;
}
glibtop_sys_siglist[rtmax - 1].number = rtmax;
glibtop_sys_siglist[rtmax - 1].name = rt_max.name;
glibtop_sys_siglist[rtmax - 1].label = rt_max.label;
glibtop_sys_siglist[rtmax].number = 0;
glibtop_sys_siglist[rtmax].name = glibtop_sys_siglist[rtmax].label = NULL;
}
*/