New upstream version 2.3.4

This commit is contained in:
Jan Wagner 2023-10-18 07:29:37 +00:00
parent e7bdd1c6c6
commit de72f6f588
556 changed files with 90432 additions and 53391 deletions

View file

@ -70,6 +70,7 @@ int options = 0; /* bitmask of filter criteria to test against */
#define PCPU 256
#define ELAPSED 512
#define EREG_ARGS 1024
#define EXCLUDE_PROGS 2048
#define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads:
ppid of procs are compared to pid of this proc*/
@ -93,6 +94,9 @@ int rss;
float pcpu;
char *statopts;
char *prog;
char *exclude_progs;
char **exclude_progs_arr = NULL;
char exclude_progs_counter = 0;
char *args;
char *input_filename = NULL;
regex_t re_args;
@ -237,8 +241,9 @@ main (int argc, char **argv)
/* Ignore self */
if ((usepid && mypid == procpid) ||
(!usepid && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino) ||
(ret == -1 && errno == ENOENT))) {
( ((!usepid) && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino)) ||
(ret == -1 && errno == ENOENT))
) {
if (verbose >= 3)
printf("not considering - is myself or gone\n");
continue;
@ -250,7 +255,26 @@ main (int argc, char **argv)
continue;
}
/* filter kernel threads (childs of KTHREAD_PARENT)*/
/* Ignore excluded processes by name */
if(options & EXCLUDE_PROGS) {
int found = 0;
int i = 0;
for(i=0; i < (exclude_progs_counter); i++) {
if(!strcmp(procprog, exclude_progs_arr[i])) {
found = 1;
}
}
if(found == 0) {
resultsum |= EXCLUDE_PROGS;
} else
{
if(verbose >= 3)
printf("excluding - by ignorelist\n");
}
}
/* filter kernel threads (children of KTHREAD_PARENT)*/
/* TODO adapt for other OSes than GNU/Linux
sorry for not doing that, but I've no other OSes to test :-( */
if (kthread_filter == 1) {
@ -409,6 +433,7 @@ process_arguments (int argc, char **argv)
{"input-file", required_argument, 0, CHAR_MAX+2},
{"no-kthreads", required_argument, 0, 'k'},
{"traditional-filter", no_argument, 0, 'T'},
{"exclude-process", required_argument, 0, 'X'},
{0, 0, 0, 0}
};
@ -417,7 +442,7 @@ process_arguments (int argc, char **argv)
strcpy (argv[c], "-t");
while (1) {
c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T",
c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T:X:",
longopts, &option);
if (c == -1 || c == EOF)
@ -490,6 +515,23 @@ process_arguments (int argc, char **argv)
prog);
options |= PROG;
break;
case 'X':
if(exclude_progs)
break;
else
exclude_progs = optarg;
xasprintf (&fmt, _("%s%sexclude progs '%s'"), (fmt ? fmt : ""), (options ? ", " : ""),
exclude_progs);
char *p = strtok(exclude_progs, ",");
while(p){
exclude_progs_arr = realloc(exclude_progs_arr, sizeof(char*) * ++exclude_progs_counter);
exclude_progs_arr[exclude_progs_counter-1] = p;
p = strtok(NULL, ",");
}
options |= EXCLUDE_PROGS;
break;
case 'a': /* args (full path name with args) */
/* TODO: allow this to be passed in with --metric */
if (args)
@ -745,6 +787,8 @@ print_help (void)
printf (" %s\n", _("Only scan for processes with args that contain the regex STRING."));
printf (" %s\n", "-C, --command=COMMAND");
printf (" %s\n", _("Only scan for exact matches of COMMAND (without path)."));
printf (" %s\n", "-X, --exclude-process");
printf (" %s\n", _("Exclude processes which match this comma separated list"));
printf (" %s\n", "-k, --no-kthreads");
printf (" %s\n", _("Only scan for non kernel threads (works on Linux only)."));
@ -786,5 +830,5 @@ print_usage (void)
printf ("%s\n", _("Usage:"));
printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname);
printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n");
printf (" [-C command] [-k] [-t timeout] [-v]\n");
printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n");
}