/*
* Top users/processes display for Unix
* Version 3
*
* This program may be freely redistributed,
* but this entire comment MUST remain intact.
*
* Copyright (c) 1984, 1989, William LeFebvre, Rice University
* Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
* Copyright (c) 2007-2019, Mark Wong
*/
/*
* This file contains the routines that implement some of the interactive
* mode commands. Note that some of the commands are implemented in-line
* in "main". This is necessary because they change the global state of
* "top" (i.e.: changing the number of processes to display).
*/
#include "os.h"
#include <ctype.h>
#include <signal.h>
#include <errno.h>
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#include <unistd.h>
#include "sigdesc.h" /* generated automatically */
#include "pg_top.h"
#include "boolean.h"
#include "utils.h"
#include "version.h"
#include "machine.h"
#include "help.h"
#include "display.h"
#include "pg.h"
#include "commands.h"
#include "screen.h"
#include "username.h"
extern int errno;
extern char *copyright;
/* imported from screen.c */
extern int overstrike;
extern int max_topn;
/*
* Some of the commands make system calls that could generate errors.
* These errors are collected up in an array of structures for later
* contemplation and display. Such routines return a string containing an
* error message, or NULL if no errors occurred. We need an upper limit on
* the number of errors, so we arbitrarily choose 20.
*/
#define ERRMAX 20
struct errs /* structure for a system-call error */
{
int errnum; /* value of errno (that is, the actual error) */
char *arg; /* argument that caused the error */
};
static struct errs errs[ERRMAX];
static int errcnt;
static char *err_toomany = " too many errors occurred";
static char *err_listem =
" Many errors occurred. Press `e' to display the list of errors.";
char header_index_stats[43] = " I_SCANS I_READS I_FETCHES INDEXRELNAME";
char header_io_stats[64] =
" PID RCHAR WCHAR SYSCR SYSCW READS WRITES CWRITES COMMAND";
char header_statements[46] = " CALLS CALLS% TOTAL_TIME AVG_TIME QUERY";
/* These macros get used to reset and log the errors */
#define ERR_RESET errcnt = 0
#define ERROR(p, e) if (errcnt >= ERRMAX) \
{ \
return(err_toomany); \
} \
else \
{ \
errs[errcnt].arg = (p); \
errs[errcnt++].errnum = (e); \
}
#define BEGIN "BEGIN;"
#define ROLLBACK "ROLLBACK;"
struct cmd cmd_map[] = {
{'\014', cmd_redraw},
{'#', cmd_number},
{' ', cmd_update},
{'?', cmd_help},
{'A', cmd_explain_analyze},
{'c', cmd_cmdline},
#ifdef ENABLE_COLOR
{'C', cmd_color},
#endif /* ENABLE_COLOR */
{'d', cmd_displays},
{'e'