2002-02-02 04:17:29 +05:30
|
|
|
/*
|
2003-03-18 05:12:00 +05:30
|
|
|
* Copyright 1998-2003 by Albert Cahalan; all rights reserved.
|
2002-02-02 04:17:29 +05:30
|
|
|
* This file may be used subject to the terms and conditions of the
|
|
|
|
* GNU Library General Public License Version 2, or any later version
|
|
|
|
* at your option, as published by the Free Software Foundation.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Ought to have debug print stuff like this:
|
|
|
|
* #define Print(fmt, args...) printf("Debug: " fmt, ## args)
|
|
|
|
*/
|
|
|
|
|
2011-12-28 03:52:43 +05:30
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <stdio.h>
|
2011-12-28 03:52:43 +05:30
|
|
|
#include <stdlib.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <string.h>
|
2011-12-28 03:52:43 +05:30
|
|
|
#include <unistd.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
|
|
|
|
#include <sys/stat.h>
|
2011-12-28 03:52:43 +05:30
|
|
|
#include <sys/types.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2011-11-22 21:06:00 +05:30
|
|
|
#include "../proc/alloc.h"
|
2002-02-02 04:17:29 +05:30
|
|
|
#include "../proc/version.h"
|
|
|
|
|
2011-12-28 03:52:43 +05:30
|
|
|
#include "common.h"
|
|
|
|
|
2002-02-02 04:17:29 +05:30
|
|
|
#define ARG_GNU 0
|
|
|
|
#define ARG_END 1
|
|
|
|
#define ARG_PGRP 2
|
|
|
|
#define ARG_SYSV 3
|
|
|
|
#define ARG_PID 4
|
|
|
|
#define ARG_BSD 5
|
|
|
|
#define ARG_FAIL 6
|
|
|
|
#define ARG_SESS 7
|
|
|
|
|
|
|
|
static int w_count = 0;
|
|
|
|
|
|
|
|
static int ps_argc; /* global argc */
|
|
|
|
static char **ps_argv; /* global argv */
|
|
|
|
static int thisarg; /* index into ps_argv */
|
|
|
|
static char *flagptr; /* current location in ps_argv[thisarg] */
|
|
|
|
static int not_pure_unix = 0; /* set by BSD and GNU options */
|
|
|
|
static int force_bsd = 0; /* set when normal parsing fails */
|
|
|
|
|
2012-01-05 16:41:04 +05:30
|
|
|
#define exclusive(x) if((ps_argc != 2) || strcmp(ps_argv[1],x)) \
|
|
|
|
return _("the option is exclusive: " x)
|
2002-02-02 04:17:29 +05:30
|
|
|
|
|
|
|
/********** utility functions **********/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Both "-Oppid" and "-O ppid" should be legal, though Unix98
|
|
|
|
* does not require it. BSD and Digital Unix allow both.
|
|
|
|
* Return the argument or NULL;
|
|
|
|
*/
|
|
|
|
static const char *get_opt_arg(void){
|
|
|
|
if(*(flagptr+1)){ /* argument is part of ps_argv[thisarg] */
|
|
|
|
not_pure_unix = 1;
|
|
|
|
return flagptr+1;
|
|
|
|
}
|
|
|
|
if(thisarg+2 > ps_argc) return NULL; /* there is nothing left */
|
|
|
|
/* argument follows ps_argv[thisarg] */
|
|
|
|
if(*(ps_argv[thisarg+1]) == '\0') return NULL;
|
|
|
|
return ps_argv[++thisarg];
|
|
|
|
}
|
|
|
|
|
|
|
|
/********** parse lists (of UID, tty, GID, PID...) **********/
|
|
|
|
|
|
|
|
static const char *parse_pid(char *str, sel_union *ret){
|
|
|
|
char *endp;
|
2002-10-01 04:01:21 +05:30
|
|
|
unsigned long num;
|
|
|
|
num = strtoul(str, &endp, 0);
|
2011-10-09 17:22:57 +05:30
|
|
|
if(*endp != '\0') return _("Process ID list syntax error.");
|
|
|
|
if(num<1) return _("Process ID out of range.");
|
|
|
|
if(num > 0x7fffffffUL) return _("Process ID out of range.");
|
2002-02-02 04:17:29 +05:30
|
|
|
ret->pid = num;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *parse_uid(char *str, sel_union *ret){
|
|
|
|
struct passwd *passwd_data;
|
|
|
|
char *endp;
|
|
|
|
unsigned long num;
|
|
|
|
num = strtoul(str, &endp, 0);
|
|
|
|
if(*endp != '\0'){ /* hmmm, try as login name */
|
|
|
|
passwd_data = getpwnam(str);
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!passwd_data) return _("User name does not exist.");
|
2002-02-02 04:17:29 +05:30
|
|
|
num = passwd_data->pw_uid;
|
|
|
|
}
|
2011-10-09 17:22:57 +05:30
|
|
|
if(num > 0xfffffffeUL) return _("User ID out of range.");
|
2002-02-02 04:17:29 +05:30
|
|
|
ret->uid = num;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *parse_gid(char *str, sel_union *ret){
|
|
|
|
struct group *group_data;
|
|
|
|
char *endp;
|
|
|
|
unsigned long num;
|
|
|
|
num = strtoul(str, &endp, 0);
|
|
|
|
if(*endp != '\0'){ /* hmmm, try as login name */
|
|
|
|
group_data = getgrnam(str);
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!group_data) return _("Group name does not exist.");
|
2002-02-02 04:17:29 +05:30
|
|
|
num = group_data->gr_gid;
|
|
|
|
}
|
2011-10-09 17:22:57 +05:30
|
|
|
if(num > 0xfffffffeUL) return _("Group ID out of range.");
|
2002-02-02 04:17:29 +05:30
|
|
|
ret->gid = num;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *parse_cmd(char *str, sel_union *ret){
|
2003-02-18 09:21:03 +05:30
|
|
|
strncpy(ret->cmd, str, sizeof ret->cmd); // strncpy pads to end
|
2011-10-06 21:13:30 +05:30
|
|
|
ret->cmd[sizeof(ret->cmd)-1] = '\0'; // but let's be safe
|
2002-02-02 04:17:29 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *parse_tty(char *str, sel_union *ret){
|
|
|
|
struct stat sbuf;
|
|
|
|
char path[4096];
|
|
|
|
if(str[0]=='/'){
|
|
|
|
if(stat(str, &sbuf) >= 0) goto found_it;
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("TTY could not be found.");;
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
#define lookup(p) \
|
|
|
|
snprintf(path,4096,p,str); \
|
|
|
|
if(stat(path, &sbuf) >= 0) goto found_it
|
|
|
|
|
|
|
|
lookup("/dev/pts/%s"); /* New Unix98 ptys go first */
|
|
|
|
lookup("/dev/%s");
|
|
|
|
lookup("/dev/tty%s");
|
|
|
|
lookup("/dev/pty%s");
|
|
|
|
lookup("/dev/%snsole"); /* "co" means "console", maybe do all VCs too? */
|
|
|
|
if(!strcmp(str,"-")){ /* "-" means no tty (from AIX) */
|
2002-12-03 14:37:59 +05:30
|
|
|
ret->tty = 0; /* processes w/o tty */
|
2002-02-02 04:17:29 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!strcmp(str,"?")){ /* "?" means no tty, which bash eats (Reno BSD?) */
|
2002-12-03 14:37:59 +05:30
|
|
|
ret->tty = 0; /* processes w/o tty */
|
2002-02-02 04:17:29 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!*(str+1) && (stat(str,&sbuf)>=0)){ /* Kludge! Assume bash ate '?'. */
|
2002-12-03 14:37:59 +05:30
|
|
|
ret->tty = 0; /* processes w/o tty */
|
2002-02-02 04:17:29 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#undef lookup
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("TTY could not be found.");;
|
2002-02-02 04:17:29 +05:30
|
|
|
found_it:
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!S_ISCHR(sbuf.st_mode)) return _("List member was not a TTY.");
|
2002-02-02 04:17:29 +05:30
|
|
|
ret->tty = sbuf.st_rdev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used to parse lists in a generic way. (function pointers)
|
|
|
|
*/
|
|
|
|
static const char *parse_list(const char *arg, const char *(*parse_fn)(char *, sel_union *) ){
|
|
|
|
selection_node *node;
|
|
|
|
char *buf; /* temp copy of arg to hack on */
|
|
|
|
char *sep_loc; /* separator location: " \t," */
|
|
|
|
char *walk;
|
|
|
|
int items;
|
|
|
|
int need_item;
|
|
|
|
const char *err; /* error code that could or did happen */
|
|
|
|
/*** prepare to operate ***/
|
2011-12-20 17:26:17 +05:30
|
|
|
node = malloc(sizeof(selection_node));
|
|
|
|
node->u = malloc(strlen(arg)*sizeof(sel_union)); /* waste is insignificant */
|
2002-02-02 04:17:29 +05:30
|
|
|
node->n = 0;
|
2011-12-20 17:26:17 +05:30
|
|
|
buf = strdup(arg);
|
2002-02-02 04:17:29 +05:30
|
|
|
/*** sanity check and count items ***/
|
|
|
|
need_item = 1; /* true */
|
|
|
|
items = 0;
|
|
|
|
walk = buf;
|
2011-10-09 17:22:57 +05:30
|
|
|
err = _("Improper list.");
|
2002-02-02 04:17:29 +05:30
|
|
|
do{
|
|
|
|
switch(*walk){
|
|
|
|
case ' ': case ',': case '\t': case '\0':
|
|
|
|
if(need_item) goto parse_error;
|
|
|
|
need_item=1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(need_item) items++;
|
|
|
|
need_item=0;
|
|
|
|
}
|
|
|
|
} while (*++walk);
|
|
|
|
if(need_item) goto parse_error;
|
|
|
|
node->n = items;
|
|
|
|
/*** actually parse the list ***/
|
|
|
|
walk = buf;
|
|
|
|
while(items--){
|
|
|
|
sep_loc = strpbrk(walk," ,\t");
|
|
|
|
if(sep_loc) *sep_loc = '\0';
|
|
|
|
if(( err=(parse_fn)(walk, node->u+items) )) goto parse_error;
|
|
|
|
walk = sep_loc + 1; /* point to next item, if any */
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
node->next = selection_list;
|
|
|
|
selection_list = node;
|
|
|
|
return NULL;
|
|
|
|
parse_error:
|
|
|
|
free(buf);
|
|
|
|
free(node->u);
|
|
|
|
free(node);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************** parse SysV options, including Unix98 *****************/
|
|
|
|
static const char *parse_sysv_option(void){
|
|
|
|
const char *arg;
|
|
|
|
const char *err;
|
2004-08-18 07:52:13 +05:30
|
|
|
|
2002-02-02 04:17:29 +05:30
|
|
|
flagptr = ps_argv[thisarg];
|
|
|
|
while(*++flagptr){
|
2004-08-18 07:52:13 +05:30
|
|
|
// Find any excuse to ignore stupid Unix98 misfeatures.
|
|
|
|
//
|
|
|
|
// This list of options is ONLY for those defined by the
|
|
|
|
// "IEEE Std 1003.1, 2004 Edition", "ISO/IEC 9945:2003",
|
|
|
|
// or "Version 2 of the Single Unix Specification".
|
2005-01-06 05:47:59 +05:30
|
|
|
//
|
|
|
|
// It may be time to re-think the existance of this list.
|
|
|
|
// In the meantime, please do not add to it. The list is
|
|
|
|
// intended to ONLY contain flags defined by the POSIX and UNIX
|
|
|
|
// standards published by The Open Group, IEEE, and ISO.
|
2006-09-10 11:55:56 +05:30
|
|
|
if(!strchr("aAdefgGlnoptuU", *flagptr)) not_pure_unix = 1; // dude, -Z ain't in POSIX
|
2004-08-18 07:52:13 +05:30
|
|
|
|
2002-02-02 04:17:29 +05:30
|
|
|
switch(*flagptr){
|
|
|
|
case 'A':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-A selects all processes.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
all_processes = 1;
|
|
|
|
break;
|
|
|
|
case 'C': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-C select by process name.\n"); /* Why only HP/UX and us? */
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of command names must follow -C.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_cmd);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_COMM;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'F': /* DYNIX/ptx -f plus sz,rss,psr=ENG between c and stime */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-F does fuller listing\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_modifiers |= FM_F;
|
|
|
|
format_flags |= FF_Uf;
|
|
|
|
unix_f_option = 1; /* does this matter? */
|
|
|
|
break;
|
|
|
|
case 'G': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-G select by RGID (supports names)\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of real groups must follow -G.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_gid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_RGID;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'H': /* another nice HP/UX feature */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-H Process hierarchy (like ASCII art forest option)\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
forest_type = 'u';
|
|
|
|
break;
|
2004-05-05 04:59:40 +05:30
|
|
|
#if 0
|
|
|
|
case 'J': // specify list of job IDs in hex (IRIX) -- like HP "-R" maybe?
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-J select by job ID\n"); // want a JID ("jid") for "-j" too
|
2004-05-05 04:59:40 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of jobs must follow -J.");
|
2004-05-05 04:59:40 +05:30
|
|
|
err=parse_list(arg, parse_jid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_JID;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
#endif
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'L': /* */
|
|
|
|
/* In spite of the insane 2-level thread system, Sun appears to
|
|
|
|
* have made this option Linux-compatible. If a process has N
|
|
|
|
* threads, ps will produce N lines of output. (not N+1 lines)
|
|
|
|
* Zombies are the only exception, with NLWP==0 and 1 output line.
|
|
|
|
* SCO UnixWare uses -L too.
|
|
|
|
*/
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-L Print LWP (thread) info.\n");
|
2003-09-30 09:30:50 +05:30
|
|
|
thread_flags |= TF_U_L;
|
2003-10-07 08:42:50 +05:30
|
|
|
// format_modifiers |= FM_L;
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
2004-05-05 04:59:40 +05:30
|
|
|
case 'M': // typically the SE Linux context
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-M Print security label for Mandatory Access Control.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_modifiers |= FM_M;
|
|
|
|
break;
|
|
|
|
case 'N':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-N negates.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
negate_selection = 1;
|
|
|
|
break;
|
|
|
|
case 'O': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-O is preloaded -o.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Format or sort specification must follow -O.");
|
2002-02-02 04:17:29 +05:30
|
|
|
defer_sf_option(arg, SF_U_O);
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'P': /* SunOS 5 "psr" or unknown HP/UX feature */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-P adds columns of PRM info (HP-UX), PSR (SunOS), or capabilities (IRIX)\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_modifiers |= FM_P;
|
|
|
|
break;
|
2004-05-05 04:59:40 +05:30
|
|
|
#if 0
|
|
|
|
case 'R': // unknown HP/UX feature, like IRIX "-J" maybe?
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-R select by PRM group\n");
|
2004-05-05 04:59:40 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of PRM groups must follow -R.");
|
2004-05-05 04:59:40 +05:30
|
|
|
err=parse_list(arg, parse_prm);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_PRM;
|
|
|
|
return NULL; /* can't have any more options */
|
2002-02-02 04:17:29 +05:30
|
|
|
#endif
|
|
|
|
case 'T':
|
|
|
|
/* IRIX 6.5 docs suggest POSIX threads get shown individually.
|
|
|
|
* This would make -T be like -L, -m, and m. (but an extra column)
|
|
|
|
* Testing (w/ normal processes) shows 1 line/process, not 2.
|
|
|
|
* Also, testing shows PID==SPID for all normal processes.
|
|
|
|
*/
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-T adds strange SPID column (old sproc() threads?)\n");
|
2003-09-30 09:30:50 +05:30
|
|
|
thread_flags |= TF_U_T;
|
2003-10-07 08:42:50 +05:30
|
|
|
// format_modifiers |= FM_T;
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case 'U': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-U select by RUID (supports names).\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2012-01-05 16:41:04 +05:30
|
|
|
if(!arg) return _("List of real users must follow -U.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_uid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_RUID;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'V': /* single */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-V prints version.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
exclusive("-V");
|
|
|
|
display_version();
|
|
|
|
exit(0);
|
2004-05-25 07:43:39 +05:30
|
|
|
// This must be verified against SVR4-MP. (UnixWare or Powermax)
|
|
|
|
// Leave it undocumented until that problem is solved.
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'Z': /* full Mandatory Access Control level info */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-Z shows full MAC info\n");
|
2004-05-05 04:59:40 +05:30
|
|
|
format_modifiers |= FM_M;
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case 'a':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-a select all with a tty, but omit session leaders.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
simple_select |= SS_U_a;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
/* HP-UX and SunOS 5 scheduling info modifier */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-c changes scheduling info.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_modifiers |= FM_c;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-d select all, but omit session leaders.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
simple_select |= SS_U_d;
|
|
|
|
break;
|
|
|
|
case 'e':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-e selects all processes.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
all_processes = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-f does full listing\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_flags |= FF_Uf;
|
|
|
|
unix_f_option = 1; /* does this matter? */
|
|
|
|
break;
|
|
|
|
case 'g': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-g selects by session leader OR by group name\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of session leaders OR effective group names must follow -g.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_pid);
|
|
|
|
if(!err){
|
|
|
|
selection_list->typecode = SEL_SESS;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
}
|
|
|
|
err=parse_list(arg, parse_gid);
|
|
|
|
if(!err){
|
|
|
|
selection_list->typecode = SEL_EGID;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
}
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("List of session leaders OR effective group IDs was invalid.");
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'j':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-j jobs format.\n");
|
2003-10-07 08:42:50 +05:30
|
|
|
/* old Debian used RD_j and Digital uses JFMT */
|
2002-02-02 04:17:29 +05:30
|
|
|
if(sysv_j_format) format_flags |= FF_Uj;
|
|
|
|
else format_modifiers |= FM_j;
|
|
|
|
break;
|
|
|
|
case 'l':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-l long format.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_flags |= FF_Ul;
|
|
|
|
break;
|
|
|
|
case 'm':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-m shows threads.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
/* note that AIX shows 2 lines for a normal process */
|
2003-09-30 09:30:50 +05:30
|
|
|
thread_flags |= TF_U_m;
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case 'n': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-n sets namelist file.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Alternate System.map file must follow -n.");
|
2002-02-02 04:17:29 +05:30
|
|
|
namelist_file = arg;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'o': /* end */
|
|
|
|
/* Unix98 has gross behavior regarding this. From the following: */
|
|
|
|
/* ps -o pid,nice=NICE,tty=TERMINAL,comm */
|
|
|
|
/* The result must be 2 columns: "PID NICE,tty=TERMINAL,comm" */
|
|
|
|
/* Yes, the second column has the name "NICE,tty=TERMINAL,comm" */
|
|
|
|
/* This parser looks for any excuse to ignore that braindamage. */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-o user-defined format.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Format specification must follow -o.");
|
2002-02-02 04:17:29 +05:30
|
|
|
not_pure_unix |= defer_sf_option(arg, SF_U_o);
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'p': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-p select by PID.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of process IDs must follow -p.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_pid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_PID;
|
|
|
|
return NULL; /* can't have any more options */
|
2004-05-05 04:59:40 +05:30
|
|
|
#if 0
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'r':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-r some Digital Unix thing about warnings...\n");
|
|
|
|
trace(" or SCO's option to chroot() for new /proc and /dev.\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("The -r option is reserved.");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 's': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-s Select processes belonging to the sessions given.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of session IDs must follow -s.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_pid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_SESS;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 't': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-t select by tty.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of terminals (pty, tty...) must follow -t.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_tty);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_TTY;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'u': /* end */
|
2012-01-05 16:41:04 +05:30
|
|
|
trace("-u select by user effective ID (supports names).\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of users must follow -u.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_uid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_EUID;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'w':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-w wide output.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
w_count++;
|
|
|
|
break;
|
2004-04-26 06:17:31 +05:30
|
|
|
case 'x': /* behind personality until "ps -ax" habit is uncommon */
|
|
|
|
if(personality & PER_SVR4_x){
|
|
|
|
// Same as -y, but for System V Release 4 MP
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-x works like Sun Solaris & SCO Unixware -y option\n");
|
2004-04-26 06:17:31 +05:30
|
|
|
format_modifiers |= FM_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(personality & PER_HPUX_x){
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-x extends the command line\n");
|
2004-04-26 06:17:31 +05:30
|
|
|
w_count += 2;
|
|
|
|
unix_f_option = 1;
|
|
|
|
break;
|
|
|
|
}
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Must set personality to get -x option.");
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'y': /* Sun's -l hack (also: Irix "lnode" resource control info) */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-y Print lnone info in UID/USER column or do Sun -l hack.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_modifiers |= FM_y;
|
|
|
|
break;
|
2003-09-28 08:15:05 +05:30
|
|
|
#if 0
|
2004-05-05 04:59:40 +05:30
|
|
|
// This must be verified against SVR4-MP (UnixWare or Powermax)
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'z': /* alias of Mandatory Access Control level info */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-z shows aliased MAC info\n");
|
2004-05-05 04:59:40 +05:30
|
|
|
format_modifiers |= FM_M;
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
2005-01-24 09:07:41 +05:30
|
|
|
// Solaris 10 does this
|
|
|
|
case 'z': /* select by zone */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("-z secects by zone\n");
|
2005-01-24 09:07:41 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of zones (contexts, labels, whatever?) must follow -z.");
|
2005-01-24 09:07:41 +05:30
|
|
|
err=parse_list(arg, parse_zone);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_ZONE;
|
|
|
|
return NULL; /* can't have any more options */
|
2003-09-28 08:15:05 +05:30
|
|
|
#endif
|
2002-02-02 04:17:29 +05:30
|
|
|
case '-':
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Embedded '-' among SysV options makes no sense.");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case '\0':
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Please report the \"SysV \\0 can't happen\" bug.");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
default:
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Unsupported SysV option.");
|
2002-02-02 04:17:29 +05:30
|
|
|
} /* switch */
|
|
|
|
} /* while */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************* parse BSD options **********************/
|
|
|
|
static const char *parse_bsd_option(void){
|
|
|
|
const char *arg;
|
|
|
|
const char *err;
|
|
|
|
|
|
|
|
flagptr = ps_argv[thisarg]; /* assume we _have_ a '-' */
|
|
|
|
if(flagptr[0]=='-'){
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!force_bsd) return _("Can't happen! Problem #1.");
|
2002-02-02 04:17:29 +05:30
|
|
|
}else{
|
|
|
|
flagptr--; /* off beginning, will increment before use */
|
|
|
|
if(personality & PER_FORCE_BSD){
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!force_bsd) return _("Can't happen! Problem #2.");
|
2002-02-02 04:17:29 +05:30
|
|
|
}else{
|
2011-10-09 17:22:57 +05:30
|
|
|
if(force_bsd) return _("2nd chance parse failed, not BSD or SysV.");
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*++flagptr){
|
|
|
|
switch(*flagptr){
|
|
|
|
case '0' ... '9': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("0..9 Old BSD-style select by process ID\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=flagptr;
|
|
|
|
err=parse_list(arg, parse_pid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_PID;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
#if 0
|
|
|
|
case 'A':
|
|
|
|
/* maybe this just does a larger malloc() ? */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("A Increases the argument space (Digital Unix)\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Option A is reserved.");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
/* should divide result by 1-(e**(foo*log(bar))) */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("C Use raw CPU time for %%CPU instead of decaying ave\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Option C is reserved.");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
#endif
|
2003-09-20 13:59:55 +05:30
|
|
|
case 'H': // The FreeBSD way (NetBSD:s OpenBSD:k FreeBSD:H -- NIH???)
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("H Print LWP (thread) info.\n"); // was: Use /vmcore as c-dumpfile\n");
|
2003-09-30 09:30:50 +05:30
|
|
|
thread_flags |= TF_B_H;
|
2003-09-20 13:59:55 +05:30
|
|
|
//format_modifiers |= FM_L; // FIXME: determine if we need something like this
|
|
|
|
break;
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'L': /* single */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("L List all format specifiers\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
exclusive("L");
|
|
|
|
print_format_specifiers();
|
|
|
|
exit(0);
|
2004-08-10 08:44:10 +05:30
|
|
|
case 'M': // undocumented for now: these are proliferating!
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("M MacOS X thread display, like AIX/Tru64\n");
|
2004-08-10 08:44:10 +05:30
|
|
|
thread_flags |= TF_B_m;
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case 'N': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("N Specify namelist file\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Alternate System.map file must follow N.");
|
2002-02-02 04:17:29 +05:30
|
|
|
namelist_file = arg;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'O': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("O Like o + defaults, add new columns after PID. Also sort.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Format or sort specification must follow O.");
|
2002-02-02 04:17:29 +05:30
|
|
|
defer_sf_option(arg, SF_B_O);
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
break;
|
|
|
|
case 'S':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("S include dead kids in sum\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
include_dead_children = 1;
|
|
|
|
break;
|
|
|
|
case 'T':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("T Select all processes on this terminal\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
/* put our tty on a tiny list */
|
|
|
|
{
|
|
|
|
selection_node *node;
|
2011-12-20 17:26:17 +05:30
|
|
|
node = malloc(sizeof(selection_node));
|
|
|
|
node->u = malloc(sizeof(sel_union));
|
2002-02-02 04:17:29 +05:30
|
|
|
node->u[0].tty = cached_tty;
|
|
|
|
node->typecode = SEL_TTY;
|
|
|
|
node->n = 1;
|
|
|
|
node->next = selection_list;
|
|
|
|
selection_list = node;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'U': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("U Select processes for specified users.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of users must follow U.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_uid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_EUID;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'V': /* single */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("V show version info\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
exclusive("V");
|
|
|
|
display_version();
|
|
|
|
exit(0);
|
|
|
|
case 'W':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("W N/A get swap info from ... not /dev/drum.\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Obsolete W option not supported. (You have a /dev/drum?)");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case 'X':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("X Old Linux i386 register format\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_flags |= FF_LX;
|
|
|
|
break;
|
2004-03-27 09:25:52 +05:30
|
|
|
case 'Z': /* FreeBSD does MAC like SGI's Irix does it */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("Z Print security label for Mandatory Access Control.\n");
|
2004-03-27 09:25:52 +05:30
|
|
|
format_modifiers |= FM_M;
|
|
|
|
break;
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'a':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("a Select all w/tty, including other users\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
simple_select |= SS_B_a;
|
|
|
|
break;
|
|
|
|
case 'c':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("c true command name\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
bsd_c_option = 1;
|
|
|
|
break;
|
2011-09-12 17:48:23 +05:30
|
|
|
// case 'd':
|
2011-11-07 21:51:41 +05:30
|
|
|
// trace("d FreeBSD-style tree\n");
|
2011-09-12 17:48:23 +05:30
|
|
|
// forest_type = 'f';
|
|
|
|
// break;
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'e':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("e environment\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
bsd_e_option = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("f ASCII art forest\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
forest_type = 'b';
|
|
|
|
break;
|
|
|
|
case 'g':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("g _all_, even group leaders!.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
simple_select |= SS_B_g;
|
|
|
|
break;
|
|
|
|
case 'h':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("h Repeat header... yow.\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
if(header_type) return _("Only one heading option may be specified.");
|
2002-02-02 04:17:29 +05:30
|
|
|
if(personality & PER_BSD_h) header_type = HEAD_MULTI;
|
|
|
|
else header_type = HEAD_NONE;
|
|
|
|
break;
|
|
|
|
case 'j':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("j job control format\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_flags |= FF_Bj;
|
|
|
|
break;
|
2004-04-26 06:17:31 +05:30
|
|
|
case 'k':
|
|
|
|
// OpenBSD: don't hide "kernel threads" -- like the swapper?
|
|
|
|
// trace("k Print LWP (thread) info.\n"); // was: Use /vmcore as c-dumpfile\n");
|
|
|
|
|
|
|
|
// NetBSD, and soon (?) FreeBSD: sort-by-keyword
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("k Specify sorting keywords.\n");
|
2004-04-26 06:17:31 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Long sort specification must follow 'k'.");
|
2004-04-26 06:17:31 +05:30
|
|
|
defer_sf_option(arg, SF_G_sort);
|
|
|
|
return NULL; /* can't have any more options */
|
2002-02-02 04:17:29 +05:30
|
|
|
case 'l':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("l Display long format\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_flags |= FF_Bl;
|
|
|
|
break;
|
|
|
|
case 'm':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("m all threads, sort on mem use, show mem info\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
if(personality & PER_OLD_m){
|
|
|
|
format_flags |= FF_Lm;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(personality & PER_BSD_m){
|
|
|
|
defer_sf_option("pmem", SF_B_m);
|
|
|
|
break;
|
|
|
|
}
|
2003-09-30 09:30:50 +05:30
|
|
|
thread_flags |= TF_B_m;
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case 'n':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("n Numeric output for WCHAN, and USER replaced by UID\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
wchan_is_number = 1;
|
|
|
|
user_is_number = 1;
|
|
|
|
/* TODO add tty_is_number too? */
|
|
|
|
break;
|
|
|
|
case 'o': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("o Specify user-defined format\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Format specification must follow o.");
|
2002-02-02 04:17:29 +05:30
|
|
|
defer_sf_option(arg, SF_B_o);
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'p': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("p Select by process ID\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
arg=get_opt_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of process IDs must follow p.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_pid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_PID;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'r':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("r Select running processes\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
running_only = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("s Display signal format\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_flags |= FF_Bs;
|
|
|
|
break;
|
|
|
|
case 't': /* end */
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("t Select by tty.\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
/* List of terminals (tty, pty...) _should_ follow t. */
|
|
|
|
arg=get_opt_arg();
|
|
|
|
if(!arg){
|
|
|
|
/* Wow, obsolete BSD syntax. Put our tty on a tiny list. */
|
|
|
|
selection_node *node;
|
2011-12-20 17:26:17 +05:30
|
|
|
node = malloc(sizeof(selection_node));
|
|
|
|
node->u = malloc(sizeof(sel_union));
|
2002-02-02 04:17:29 +05:30
|
|
|
node->u[0].tty = cached_tty;
|
|
|
|
node->typecode = SEL_TTY;
|
|
|
|
node->n = 1;
|
|
|
|
node->next = selection_list;
|
|
|
|
selection_list = node;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
err=parse_list(arg, parse_tty);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_TTY;
|
|
|
|
return NULL; /* can't have any more options */
|
|
|
|
case 'u':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("u Display user-oriented\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_flags |= FF_Bu;
|
|
|
|
break;
|
|
|
|
case 'v':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("v Display virtual memory\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
format_flags |= FF_Bv;
|
|
|
|
break;
|
|
|
|
case 'w':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("w wide output\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
w_count++;
|
|
|
|
break;
|
|
|
|
case 'x':
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("x Select processes without controlling ttys\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
simple_select |= SS_B_x;
|
|
|
|
break;
|
|
|
|
case '-':
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Embedded '-' among BSD options makes no sense.");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
case '\0':
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Please report the \"BSD \\0 can't happen\" bug.");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
default:
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Unsupported option (BSD syntax)");
|
2002-02-02 04:17:29 +05:30
|
|
|
} /* switch */
|
|
|
|
} /* while */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************** gnu long options **********************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the argument or NULL
|
|
|
|
*/
|
|
|
|
static const char *grab_gnu_arg(void){
|
|
|
|
switch(*flagptr){ /* argument is part of ps_argv[thisarg] */
|
|
|
|
default:
|
|
|
|
return NULL; /* something bad */
|
|
|
|
case '=': case ':':
|
|
|
|
if(*++flagptr) return flagptr; /* found it */
|
|
|
|
return NULL; /* empty '=' or ':' */
|
|
|
|
case '\0': /* try next argv[] */
|
2002-10-02 06:03:56 +05:30
|
|
|
;
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
if(thisarg+2 > ps_argc) return NULL; /* there is nothing left */
|
|
|
|
/* argument follows ps_argv[thisarg] */
|
|
|
|
if(*(ps_argv[thisarg+1]) == '\0') return NULL;
|
|
|
|
return ps_argv[++thisarg];
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct gnu_table_struct {
|
|
|
|
const char *name; /* long option name */
|
|
|
|
const void *jump; /* See gcc extension info. :-) */
|
|
|
|
} gnu_table_struct;
|
|
|
|
|
|
|
|
static int compare_gnu_table_structs(const void *a, const void *b){
|
2002-10-12 09:55:57 +05:30
|
|
|
return strcmp(((const gnu_table_struct*)a)->name,((const gnu_table_struct*)b)->name);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/* Option arguments are after ':', after '=', or in argv[n+1] */
|
|
|
|
static const char *parse_gnu_option(void){
|
|
|
|
const char *arg;
|
|
|
|
const char *err;
|
|
|
|
char *s;
|
|
|
|
size_t sl;
|
|
|
|
char buf[16];
|
|
|
|
gnu_table_struct findme = { buf, NULL};
|
|
|
|
gnu_table_struct *found;
|
|
|
|
static const gnu_table_struct gnu_table[] = {
|
|
|
|
{"Group", &&case_Group}, /* rgid */
|
|
|
|
{"User", &&case_User}, /* ruid */
|
|
|
|
{"cols", &&case_cols},
|
|
|
|
{"columns", &&case_columns},
|
2002-09-27 19:18:00 +05:30
|
|
|
{"context", &&case_context},
|
2002-02-02 04:17:29 +05:30
|
|
|
{"cumulative", &&case_cumulative},
|
|
|
|
{"deselect", &&case_deselect}, /* -N */
|
|
|
|
{"forest", &&case_forest}, /* f -H */
|
|
|
|
{"format", &&case_format},
|
|
|
|
{"group", &&case_group}, /* egid */
|
|
|
|
{"header", &&case_header},
|
|
|
|
{"headers", &&case_headers},
|
|
|
|
{"heading", &&case_heading},
|
|
|
|
{"headings", &&case_headings},
|
2012-01-02 13:03:34 +05:30
|
|
|
//{"help", &&case_help}, /* now TRANSLATABLE ! */
|
2002-02-02 04:17:29 +05:30
|
|
|
{"info", &&case_info},
|
|
|
|
{"lines", &&case_lines},
|
|
|
|
{"no-header", &&case_no_header},
|
|
|
|
{"no-headers", &&case_no_headers},
|
|
|
|
{"no-heading", &&case_no_heading},
|
|
|
|
{"no-headings", &&case_no_headings},
|
|
|
|
{"noheader", &&case_noheader},
|
|
|
|
{"noheaders", &&case_noheaders},
|
|
|
|
{"noheading", &&case_noheading},
|
|
|
|
{"noheadings", &&case_noheadings},
|
|
|
|
{"pid", &&case_pid},
|
2003-02-09 13:01:11 +05:30
|
|
|
{"ppid", &&case_ppid},
|
2002-02-02 04:17:29 +05:30
|
|
|
{"rows", &&case_rows},
|
|
|
|
{"sid", &&case_sid},
|
|
|
|
{"sort", &&case_sort},
|
|
|
|
{"tty", &&case_tty},
|
|
|
|
{"user", &&case_user}, /* euid */
|
|
|
|
{"version", &&case_version},
|
|
|
|
{"width", &&case_width},
|
|
|
|
};
|
|
|
|
const int gnu_table_count = sizeof(gnu_table)/sizeof(gnu_table_struct);
|
|
|
|
|
|
|
|
s = ps_argv[thisarg]+2;
|
|
|
|
sl = strcspn(s,":=");
|
2011-10-09 17:22:57 +05:30
|
|
|
if(sl > 15) return _("Unknown gnu long option.");
|
2002-02-02 04:17:29 +05:30
|
|
|
strncpy(buf, s, sl);
|
|
|
|
buf[sl] = '\0';
|
|
|
|
flagptr = s+sl;
|
|
|
|
|
|
|
|
found = bsearch(&findme, gnu_table, gnu_table_count,
|
|
|
|
sizeof(gnu_table_struct), compare_gnu_table_structs
|
|
|
|
);
|
|
|
|
|
2012-01-02 13:03:34 +05:30
|
|
|
if(!found) {
|
|
|
|
if (!strcmp(buf, the_word_help))
|
|
|
|
goto case_help;
|
|
|
|
return _("Unknown gnu long option.");
|
|
|
|
}
|
2002-02-02 04:17:29 +05:30
|
|
|
|
|
|
|
goto *(found->jump); /* See gcc extension info. :-) */
|
|
|
|
|
|
|
|
case_Group:
|
|
|
|
trace("--Group\n");
|
|
|
|
arg = grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of real groups must follow --Group.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_gid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_RGID;
|
|
|
|
return NULL;
|
|
|
|
case_User:
|
|
|
|
trace("--User\n");
|
|
|
|
arg = grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of real users must follow --User.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_uid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_RUID;
|
|
|
|
return NULL;
|
|
|
|
case_cols:
|
|
|
|
case_width:
|
|
|
|
case_columns:
|
|
|
|
trace("--cols\n");
|
|
|
|
arg = grab_gnu_arg();
|
|
|
|
if(arg && *arg){
|
|
|
|
long t;
|
|
|
|
char *endptr;
|
|
|
|
t = strtol(arg, &endptr, 0);
|
|
|
|
if(!*endptr && (t>0) && (t<2000000000)){
|
|
|
|
screen_cols = (int)t;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Number of columns must follow --cols, --width, or --columns.");
|
2002-02-02 04:17:29 +05:30
|
|
|
case_cumulative:
|
|
|
|
trace("--cumulative\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
if(s[sl]) return _("Option --cumulative does not take an argument.");
|
2002-02-02 04:17:29 +05:30
|
|
|
include_dead_children = 1;
|
|
|
|
return NULL;
|
|
|
|
case_deselect:
|
|
|
|
trace("--deselect\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
if(s[sl]) return _("Option --deselect does not take an argument.");
|
2002-02-02 04:17:29 +05:30
|
|
|
negate_selection = 1;
|
|
|
|
return NULL;
|
|
|
|
case_no_header:
|
|
|
|
case_no_headers:
|
|
|
|
case_no_heading:
|
|
|
|
case_no_headings:
|
|
|
|
case_noheader:
|
|
|
|
case_noheaders:
|
|
|
|
case_noheading:
|
|
|
|
case_noheadings:
|
|
|
|
trace("--noheaders\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
if(s[sl]) return _("Option --no-heading does not take an argument.");
|
|
|
|
if(header_type) return _("Only one heading option may be specified.");
|
2002-02-02 04:17:29 +05:30
|
|
|
header_type = HEAD_NONE;
|
|
|
|
return NULL;
|
|
|
|
case_header:
|
|
|
|
case_headers:
|
|
|
|
case_heading:
|
|
|
|
case_headings:
|
|
|
|
trace("--headers\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
if(s[sl]) return _("Option --heading does not take an argument.");
|
|
|
|
if(header_type) return _("Only one heading option may be specified.");
|
2002-02-02 04:17:29 +05:30
|
|
|
header_type = HEAD_MULTI;
|
|
|
|
return NULL;
|
|
|
|
case_forest:
|
|
|
|
trace("--forest\n");
|
2011-10-09 17:22:57 +05:30
|
|
|
if(s[sl]) return _("Option --forest does not take an argument.");
|
2002-02-02 04:17:29 +05:30
|
|
|
forest_type = 'g';
|
|
|
|
return NULL;
|
|
|
|
case_format:
|
|
|
|
trace("--format\n");
|
|
|
|
arg=grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Format specification must follow --format.");
|
2002-02-02 04:17:29 +05:30
|
|
|
defer_sf_option(arg, SF_G_format);
|
|
|
|
return NULL;
|
|
|
|
case_group:
|
|
|
|
trace("--group\n");
|
|
|
|
arg = grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of effective groups must follow --group.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_gid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_EGID;
|
|
|
|
return NULL;
|
|
|
|
case_help:
|
|
|
|
trace("--help\n");
|
2011-10-02 16:37:35 +05:30
|
|
|
arg = grab_gnu_arg();
|
2012-01-02 13:03:34 +05:30
|
|
|
do_help(arg, EXIT_SUCCESS);
|
2002-02-02 04:17:29 +05:30
|
|
|
case_info:
|
|
|
|
trace("--info\n");
|
|
|
|
exclusive("--info");
|
|
|
|
self_info();
|
|
|
|
exit(0);
|
|
|
|
return NULL;
|
|
|
|
case_pid:
|
|
|
|
trace("--pid\n");
|
|
|
|
arg = grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of process IDs must follow --pid.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_pid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_PID;
|
|
|
|
return NULL;
|
2003-02-09 13:01:11 +05:30
|
|
|
case_ppid:
|
|
|
|
trace("--ppid\n");
|
|
|
|
arg = grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of process IDs must follow --ppid.");
|
2003-02-09 13:01:11 +05:30
|
|
|
err=parse_list(arg, parse_pid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_PPID;
|
|
|
|
return NULL;
|
2002-02-02 04:17:29 +05:30
|
|
|
case_rows:
|
|
|
|
case_lines:
|
|
|
|
trace("--rows\n");
|
|
|
|
arg = grab_gnu_arg();
|
|
|
|
if(arg && *arg){
|
|
|
|
long t;
|
|
|
|
char *endptr;
|
|
|
|
t = strtol(arg, &endptr, 0);
|
|
|
|
if(!*endptr && (t>0) && (t<2000000000)){
|
|
|
|
screen_rows = (int)t;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Number of rows must follow --rows or --lines.");
|
2002-02-02 04:17:29 +05:30
|
|
|
case_sid:
|
|
|
|
trace("--sid\n");
|
|
|
|
arg = grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Some sid thing(s) must follow --sid.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_pid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_SESS;
|
|
|
|
return NULL;
|
|
|
|
case_sort:
|
|
|
|
trace("--sort\n");
|
|
|
|
arg=grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("Long sort specification must follow --sort.");
|
2002-02-02 04:17:29 +05:30
|
|
|
defer_sf_option(arg, SF_G_sort);
|
|
|
|
return NULL;
|
|
|
|
case_tty:
|
|
|
|
trace("--tty\n");
|
|
|
|
arg = grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of ttys must follow --tty.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_tty);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_TTY;
|
|
|
|
return NULL;
|
|
|
|
case_user:
|
|
|
|
trace("--user\n");
|
|
|
|
arg = grab_gnu_arg();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(!arg) return _("List of effective users must follow --user.");
|
2002-02-02 04:17:29 +05:30
|
|
|
err=parse_list(arg, parse_uid);
|
|
|
|
if(err) return err;
|
|
|
|
selection_list->typecode = SEL_EUID;
|
|
|
|
return NULL;
|
|
|
|
case_version:
|
|
|
|
trace("--version\n");
|
|
|
|
exclusive("--version");
|
|
|
|
display_version();
|
|
|
|
exit(0);
|
|
|
|
return NULL;
|
2002-09-27 19:18:00 +05:30
|
|
|
case_context:
|
|
|
|
trace("--context\n");
|
|
|
|
format_flags |= FF_Fc;
|
|
|
|
return NULL;
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*************** process trailing PIDs **********************/
|
|
|
|
static const char *parse_trailing_pids(void){
|
|
|
|
selection_node *pidnode; /* pid */
|
|
|
|
selection_node *grpnode; /* process group */
|
|
|
|
selection_node *sidnode; /* session */
|
|
|
|
char **argp; /* pointer to pointer to text of PID */
|
|
|
|
const char *err; /* error code that could or did happen */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = ps_argc - thisarg; /* how many trailing PIDs, SIDs, PGRPs?? */
|
|
|
|
argp = ps_argv + thisarg;
|
|
|
|
thisarg = ps_argc - 1; /* we must be at the end now */
|
|
|
|
|
2011-12-20 17:26:17 +05:30
|
|
|
pidnode = malloc(sizeof(selection_node));
|
|
|
|
pidnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
2002-02-02 04:17:29 +05:30
|
|
|
pidnode->n = 0;
|
|
|
|
|
2011-12-20 17:26:17 +05:30
|
|
|
grpnode = malloc(sizeof(selection_node));
|
|
|
|
grpnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
2002-02-02 04:17:29 +05:30
|
|
|
grpnode->n = 0;
|
|
|
|
|
2011-12-20 17:26:17 +05:30
|
|
|
sidnode = malloc(sizeof(selection_node));
|
|
|
|
sidnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
2002-02-02 04:17:29 +05:30
|
|
|
sidnode->n = 0;
|
|
|
|
|
|
|
|
while(i--){
|
|
|
|
char *data;
|
|
|
|
data = *(argp++);
|
|
|
|
switch(*data){
|
|
|
|
default: err = parse_pid( data, pidnode->u + pidnode->n++); break;
|
|
|
|
case '-': err = parse_pid(++data, grpnode->u + grpnode->n++); break;
|
|
|
|
case '+': err = parse_pid(++data, sidnode->u + sidnode->n++); break;
|
|
|
|
}
|
|
|
|
if(err) return err; /* the node gets freed with the list */
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pidnode->n){
|
|
|
|
pidnode->next = selection_list;
|
|
|
|
selection_list = pidnode;
|
|
|
|
selection_list->typecode = SEL_PID;
|
|
|
|
} /* else free both parts */
|
|
|
|
|
|
|
|
if(grpnode->n){
|
|
|
|
grpnode->next = selection_list;
|
|
|
|
selection_list = grpnode;
|
|
|
|
selection_list->typecode = SEL_PGRP;
|
|
|
|
} /* else free both parts */
|
|
|
|
|
|
|
|
if(sidnode->n){
|
|
|
|
sidnode->next = selection_list;
|
|
|
|
selection_list = sidnode;
|
|
|
|
selection_list->typecode = SEL_SESS;
|
|
|
|
} /* else free both parts */
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************** misc stuff ***********/
|
|
|
|
|
|
|
|
static void reset_parser(void){
|
|
|
|
w_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int arg_type(const char *str){
|
|
|
|
int tmp = str[0];
|
|
|
|
if((tmp>='a') && (tmp<='z')) return ARG_BSD;
|
|
|
|
if((tmp>='A') && (tmp<='Z')) return ARG_BSD;
|
|
|
|
if((tmp>='0') && (tmp<='9')) return ARG_PID;
|
|
|
|
if(tmp=='+') return ARG_SESS;
|
|
|
|
if(tmp!='-') return ARG_FAIL;
|
|
|
|
tmp = str[1];
|
|
|
|
if((tmp>='a') && (tmp<='z')) return ARG_SYSV;
|
|
|
|
if((tmp>='A') && (tmp<='Z')) return ARG_SYSV;
|
|
|
|
if((tmp>='0') && (tmp<='9')) return ARG_PGRP;
|
|
|
|
if(tmp!='-') return ARG_FAIL;
|
|
|
|
tmp = str[2];
|
|
|
|
if((tmp>='a') && (tmp<='z')) return ARG_GNU;
|
|
|
|
if((tmp>='A') && (tmp<='Z')) return ARG_GNU;
|
|
|
|
if(tmp=='\0') return ARG_END;
|
|
|
|
return ARG_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First assume sysv, because that is the POSIX and Unix98 standard. */
|
|
|
|
static const char *parse_all_options(void){
|
|
|
|
const char *err = NULL;
|
|
|
|
int at;
|
|
|
|
while(++thisarg < ps_argc){
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("parse_all_options calling arg_type for \"%s\"\n", ps_argv[thisarg]);
|
2002-02-02 04:17:29 +05:30
|
|
|
at = arg_type(ps_argv[thisarg]);
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("ps_argv[thisarg] is %s\n", ps_argv[thisarg]);
|
2002-02-02 04:17:29 +05:30
|
|
|
if(at != ARG_SYSV) not_pure_unix = 1;
|
|
|
|
switch(at){
|
|
|
|
case ARG_GNU:
|
|
|
|
err = parse_gnu_option();
|
|
|
|
break;
|
|
|
|
case ARG_SYSV:
|
|
|
|
if(!force_bsd){ /* else go past case ARG_BSD */
|
|
|
|
err = parse_sysv_option();
|
|
|
|
break;
|
|
|
|
case ARG_BSD:
|
2011-10-09 17:22:57 +05:30
|
|
|
if(force_bsd && !(personality & PER_FORCE_BSD)) return _("way bad");
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
prefer_bsd_defaults = 1;
|
|
|
|
err = parse_bsd_option();
|
|
|
|
break;
|
|
|
|
case ARG_PGRP:
|
|
|
|
case ARG_SESS:
|
|
|
|
case ARG_PID:
|
|
|
|
prefer_bsd_defaults = 1;
|
|
|
|
err = parse_trailing_pids();
|
|
|
|
break;
|
|
|
|
case ARG_END:
|
|
|
|
case ARG_FAIL:
|
2011-11-07 21:51:41 +05:30
|
|
|
trace(" FAIL/END on [%s]\n",ps_argv[thisarg]);
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Garbage option.");
|
2002-02-02 04:17:29 +05:30
|
|
|
break;
|
|
|
|
default:
|
2011-12-17 23:02:47 +05:30
|
|
|
printf(" ? %s\n",ps_argv[thisarg]);
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Something broke.");
|
2002-02-02 04:17:29 +05:30
|
|
|
} /* switch */
|
|
|
|
if(err) return err;
|
|
|
|
} /* while */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void choose_dimensions(void){
|
|
|
|
if(w_count && (screen_cols<132)) screen_cols=132;
|
|
|
|
if(w_count>1) screen_cols=OUTBUF_SIZE;
|
|
|
|
/* perhaps --html and --null should set unlimited width */
|
|
|
|
}
|
|
|
|
|
2003-09-30 09:30:50 +05:30
|
|
|
static const char *thread_option_check(void){
|
2003-10-07 08:42:50 +05:30
|
|
|
if(!thread_flags){
|
|
|
|
thread_flags = TF_show_proc;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(forest_type){
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Thread display conflicts with forest display.");
|
2003-10-07 08:42:50 +05:30
|
|
|
}
|
|
|
|
//thread_flags |= TF_no_forest;
|
2003-09-30 09:30:50 +05:30
|
|
|
|
|
|
|
if((thread_flags&TF_B_H) && (thread_flags&(TF_B_m|TF_U_m)))
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Thread flags conflict; can't use H with m or -m.");
|
2003-09-30 09:30:50 +05:30
|
|
|
if((thread_flags&TF_B_m) && (thread_flags&TF_U_m))
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Thread flags conflict; can't use both m and -m.");
|
2003-09-30 09:30:50 +05:30
|
|
|
if((thread_flags&TF_U_L) && (thread_flags&TF_U_T))
|
2011-10-09 17:22:57 +05:30
|
|
|
return _("Thread flags conflict; can't use both -L and -T.");
|
2003-09-30 09:30:50 +05:30
|
|
|
|
2003-10-07 08:42:50 +05:30
|
|
|
if(thread_flags&TF_B_H) thread_flags |= (TF_show_proc|TF_loose_tasks);
|
|
|
|
if(thread_flags&(TF_B_m|TF_U_m)) thread_flags |= (TF_show_proc|TF_show_task|TF_show_both);
|
|
|
|
|
|
|
|
if(thread_flags&(TF_U_T|TF_U_L)){
|
|
|
|
if(thread_flags&(TF_B_m|TF_U_m|TF_B_H)){
|
|
|
|
// Got a thread style, so format modification is a requirement?
|
|
|
|
// Maybe -T/-L has H thread style though. (sorting interaction?)
|
2011-10-09 17:22:57 +05:30
|
|
|
//return _("Huh? Tell procps@freelists.org what you expected.");
|
2003-10-07 08:42:50 +05:30
|
|
|
thread_flags |= TF_must_use;
|
|
|
|
}else{
|
|
|
|
// using -L/-T thread style, so format from elsewhere is OK
|
|
|
|
thread_flags |= TF_show_task; // or like the H option?
|
|
|
|
//thread_flags |= TF_no_sort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-30 09:30:50 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-02-02 04:17:29 +05:30
|
|
|
int arg_parse(int argc, char *argv[]){
|
|
|
|
const char *err = NULL;
|
|
|
|
const char *err2 = NULL;
|
|
|
|
ps_argc = argc;
|
|
|
|
ps_argv = argv;
|
|
|
|
thisarg = 0;
|
|
|
|
|
|
|
|
if(personality & PER_FORCE_BSD) goto try_bsd;
|
|
|
|
|
|
|
|
err = parse_all_options();
|
|
|
|
if(err) goto try_bsd;
|
2003-09-30 09:30:50 +05:30
|
|
|
err = thread_option_check();
|
|
|
|
if(err) goto try_bsd;
|
2003-10-07 08:42:50 +05:30
|
|
|
err = process_sf_options(!not_pure_unix);
|
|
|
|
if(err) goto try_bsd;
|
2002-02-02 04:17:29 +05:30
|
|
|
err = select_bits_setup();
|
|
|
|
if(err) goto try_bsd;
|
|
|
|
|
|
|
|
choose_dimensions();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
try_bsd:
|
2011-11-07 21:51:41 +05:30
|
|
|
trace("--------- now try BSD ------\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
|
|
|
|
reset_global();
|
|
|
|
reset_parser();
|
|
|
|
reset_sortformat();
|
|
|
|
format_flags = 0;
|
|
|
|
ps_argc = argc;
|
|
|
|
ps_argv = argv;
|
|
|
|
thisarg = 0;
|
|
|
|
/* no need to reset flagptr */
|
|
|
|
not_pure_unix=1;
|
|
|
|
force_bsd=1;
|
|
|
|
prefer_bsd_defaults=1;
|
|
|
|
if(!( (PER_OLD_m|PER_BSD_m) & personality )) /* if default m setting... */
|
|
|
|
personality |= PER_OLD_m; /* Prefer old Linux over true BSD. */
|
|
|
|
/* Do not set PER_FORCE_BSD! It is tested below. */
|
|
|
|
|
|
|
|
err2 = parse_all_options();
|
|
|
|
if(err2) goto total_failure;
|
2003-09-30 09:30:50 +05:30
|
|
|
err2 = thread_option_check();
|
|
|
|
if(err2) goto total_failure;
|
2003-10-07 08:42:50 +05:30
|
|
|
err2 = process_sf_options(!not_pure_unix);
|
|
|
|
if(err2) goto total_failure;
|
2002-02-02 04:17:29 +05:30
|
|
|
err2 = select_bits_setup();
|
|
|
|
if(err2) goto total_failure;
|
|
|
|
|
2003-02-18 09:21:03 +05:30
|
|
|
// Feel a need to patch this out? First of all, read the FAQ.
|
|
|
|
// Second of all, talk to me. Without this warning, people can
|
|
|
|
// get seriously confused. Ask yourself if users would freak out
|
|
|
|
// about "ps -aux" suddenly changing behavior if a user "x" were
|
|
|
|
// added to the system.
|
2004-04-26 06:17:31 +05:30
|
|
|
//
|
|
|
|
// Also, a "-x" option is coming. It's already there in fact,
|
|
|
|
// for some non-default personalities. So "ps -ax" will parse
|
|
|
|
// as SysV options... and you're screwed if you've been patching
|
|
|
|
// out the friendly warning. Cut-over is likely to be in 2005.
|
2011-12-05 21:05:35 +05:30
|
|
|
#ifdef BUILD_WITH_WHINE
|
|
|
|
// Slackware:
|
|
|
|
// IMO, people can change old habits if and when user 'x' comes
|
|
|
|
// along. I still find this warning to be a POLA violation. No
|
|
|
|
// offense... that's the beauty of open source. You've got your
|
|
|
|
// ideas about this, and I have mine, and we're allowed to
|
|
|
|
// disagree. Nothing in the UNIX or POSIX standards requires
|
|
|
|
// this (annoying) warning to be displayed, and we're not
|
|
|
|
// changing the actual behavior of ps in any way. I know of no
|
|
|
|
// other 'ps' that produces this message.
|
2002-02-02 04:17:29 +05:30
|
|
|
if(!(personality & PER_FORCE_BSD))
|
2012-01-04 18:41:53 +05:30
|
|
|
fprintf(stderr, _("Warning: bad ps syntax, perhaps a bogus '-'? See http://gitorious.org/procps/procps/blobs/master/FAQ\n"));
|
2011-12-05 21:05:35 +05:30
|
|
|
#endif
|
2011-06-04 23:10:29 +05:30
|
|
|
// Remember: contact procps@freelists.org
|
2003-02-18 09:21:03 +05:30
|
|
|
// if you should feel tempted. Be damn sure you understand all
|
|
|
|
// the issues. The same goes for other stuff too, BTW. Please ask.
|
|
|
|
// I'm happy to justify various implementation choices.
|
2002-02-02 04:17:29 +05:30
|
|
|
|
|
|
|
choose_dimensions();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
total_failure:
|
|
|
|
reset_parser();
|
2011-10-09 17:22:57 +05:30
|
|
|
if(personality & PER_FORCE_BSD) fprintf(stderr, _("ERROR: %s\n"), err2);
|
|
|
|
else fprintf(stderr, _("ERROR: %s\n"), err);
|
2012-01-02 13:03:34 +05:30
|
|
|
do_help(NULL, EXIT_FAILURE);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|