ps: exploit those new <pids> task/threads capabilities
This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
28
ps/parser.c
28
ps/parser.c
@ -31,10 +31,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "../proc/alloc.h"
|
||||
#include "../include/c.h"
|
||||
#include "../include/xalloc.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "c.h"
|
||||
|
||||
#define ARG_GNU 0
|
||||
#define ARG_END 1
|
||||
@ -185,8 +185,8 @@ static const char *parse_list(const char *arg, const char *(*parse_fn)(char *, s
|
||||
int need_item;
|
||||
const char *err; /* error code that could or did happen */
|
||||
/*** prepare to operate ***/
|
||||
node = malloc(sizeof(selection_node));
|
||||
node->u = malloc(strlen(arg)*sizeof(sel_union)); /* waste is insignificant */
|
||||
node = xmalloc(sizeof(selection_node));
|
||||
node->u = xmalloc(strlen(arg)*sizeof(sel_union)); /* waste is insignificant */
|
||||
node->n = 0;
|
||||
buf = strdup(arg);
|
||||
/*** sanity check and count items ***/
|
||||
@ -583,8 +583,8 @@ static const char *parse_bsd_option(void){
|
||||
/* put our tty on a tiny list */
|
||||
{
|
||||
selection_node *node;
|
||||
node = malloc(sizeof(selection_node));
|
||||
node->u = malloc(sizeof(sel_union));
|
||||
node = xmalloc(sizeof(selection_node));
|
||||
node->u = xmalloc(sizeof(sel_union));
|
||||
node->u[0].tty = cached_tty;
|
||||
node->typecode = SEL_TTY;
|
||||
node->n = 1;
|
||||
@ -720,8 +720,8 @@ static const char *parse_bsd_option(void){
|
||||
if(!arg){
|
||||
/* Wow, obsolete BSD syntax. Put our tty on a tiny list. */
|
||||
selection_node *node;
|
||||
node = malloc(sizeof(selection_node));
|
||||
node->u = malloc(sizeof(sel_union));
|
||||
node = xmalloc(sizeof(selection_node));
|
||||
node->u = xmalloc(sizeof(sel_union));
|
||||
node->u[0].tty = cached_tty;
|
||||
node->typecode = SEL_TTY;
|
||||
node->n = 1;
|
||||
@ -1044,16 +1044,16 @@ static const char *parse_trailing_pids(void){
|
||||
argp = ps_argv + thisarg;
|
||||
thisarg = ps_argc - 1; /* we must be at the end now */
|
||||
|
||||
pidnode = malloc(sizeof(selection_node));
|
||||
pidnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
pidnode = xmalloc(sizeof(selection_node));
|
||||
pidnode->u = xmalloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
pidnode->n = 0;
|
||||
|
||||
grpnode = malloc(sizeof(selection_node));
|
||||
grpnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
grpnode = xmalloc(sizeof(selection_node));
|
||||
grpnode->u = xmalloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
grpnode->n = 0;
|
||||
|
||||
sidnode = malloc(sizeof(selection_node));
|
||||
sidnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
sidnode = xmalloc(sizeof(selection_node));
|
||||
sidnode->u = xmalloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
sidnode->n = 0;
|
||||
|
||||
while(i--){
|
||||
|
Reference in New Issue
Block a user