Mercurial > illumos > git > illumos-gate
changeset 19287:38e691e46421
12037 ptree zone handling is broken
Reviewed by: John Levon <john.levon@joyent.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Approved by: Dan McDonald <danmcd@joyent.com>
author | Jason King <jason.king@joyent.com> |
---|---|
date | Wed, 27 Nov 2019 09:10:37 -0600 |
parents | c54efc44f3db |
children | 916c020ce15c |
files | usr/src/cmd/ptools/ptree/ptree.c usr/src/lib/libproc/common/libproc.h usr/src/lib/libproc/common/proc_arg.c usr/src/man/man3proc/proc_walk.3proc |
diffstat | 4 files changed, 36 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/ptools/ptree/ptree.c Wed Nov 20 23:48:17 2019 -0700 +++ b/usr/src/cmd/ptools/ptree/ptree.c Wed Nov 27 09:10:37 2019 -0600 @@ -212,7 +212,7 @@ ps = NULL; /* Currently, this can only fail if the 3rd argument is invalid */ - VERIFY0(proc_walk(add_proc, NULL, PR_WALK_PROC)); + VERIFY0(proc_walk(add_proc, NULL, PR_WALK_PROC|PR_WALK_INCLUDE_SYS)); if (proc0 == NULL) proc0 = fakepid0();
--- a/usr/src/lib/libproc/common/libproc.h Wed Nov 20 23:48:17 2019 -0700 +++ b/usr/src/lib/libproc/common/libproc.h Wed Nov 27 09:10:37 2019 -0600 @@ -25,7 +25,7 @@ * * Portions Copyright 2007 Chad Mynhier * Copyright 2012 DEY Storage Systems, Inc. All rights reserved. - * Copyright 2018, Joyent, Inc. + * Copyright 2019 Joyent, Inc. * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright 2019, Carlos Neira <cneirabustos@gmail.com> * Copyright 2019 OmniOS Community Edition (OmniOSce) Association. @@ -464,8 +464,9 @@ typedef int proc_walk_f(psinfo_t *, lwpsinfo_t *, void *); extern int proc_walk(proc_walk_f *, void *, int); -#define PR_WALK_PROC 0 /* walk processes only */ -#define PR_WALK_LWP 1 /* walk all lwps */ +#define PR_WALK_PROC 0 /* walk processes only */ +#define PR_WALK_LWP 1 /* walk all lwps */ +#define PR_WALK_INCLUDE_SYS 0x80000000 /* include SSYS processes */ /* * Determine if an lwp is in a set as returned from proc_arg_xgrab().
--- a/usr/src/lib/libproc/common/proc_arg.c Wed Nov 20 23:48:17 2019 -0700 +++ b/usr/src/lib/libproc/common/proc_arg.c Wed Nov 27 09:10:37 2019 -0600 @@ -21,6 +21,7 @@ /* * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2019 Joyent, Inc. */ #include <sys/types.h> @@ -341,14 +342,14 @@ * The set can include multiple lwpid ranges separated by commas * and has the following syntax: * - * lwp_range[,lwp_range]* + * lwp_range[,lwp_range]* * * where lwp_range is specifed as: * - * -n lwpid <= n - * n-m n <= lwpid <= m - * n- lwpid >= n - * n lwpid == n + * -n lwpid <= n + * n-m n <= lwpid <= m + * n- lwpid >= n + * n lwpid == n */ int proc_lwp_in_set(const char *set, lwpid_t lwpid) @@ -438,6 +439,11 @@ id_t pid; int fd, i; int ret = 0; + boolean_t walk_sys = B_FALSE; + + if ((flag & PR_WALK_INCLUDE_SYS) != 0) + walk_sys = B_TRUE; + flag &= ~PR_WALK_INCLUDE_SYS; if (flag != PR_WALK_PROC && flag != PR_WALK_LWP) { errno = EINVAL; @@ -458,7 +464,7 @@ if (fd < 0) continue; if (read(fd, &psinfo, sizeof (psinfo)) != sizeof (psinfo) || - (psinfo.pr_flag & SSYS)) { + ((psinfo.pr_flag & SSYS) != 0 && !walk_sys)) { (void) close(fd); continue; }
--- a/usr/src/man/man3proc/proc_walk.3proc Wed Nov 20 23:48:17 2019 -0700 +++ b/usr/src/man/man3proc/proc_walk.3proc Wed Nov 27 09:10:37 2019 -0600 @@ -9,9 +9,9 @@ .\" http://www.illumos.org/license/CDDL. .\" .\" -.\" Copyright 2015 Joyent, Inc. +.\" Copyright 2019 Joyent, Inc. .\" -.Dd May 11, 2016 +.Dd December 2, 2019 .Dt PROC_WALK 3PROC .Os .Sh NAME @@ -77,6 +77,21 @@ argument. .El .Pp +In addition, the following values may be combined with one of the above +values of +.Fa flag +with a bitwise-inclusive-OR: +.Bl -tag -width Dv -offset indent +.It Dv PR_WALK_INCLUDE_SYS +Include +.Sy SYS +.Pq system +processes. +Normally +.Sy SYS +processes are skipped during the walk of the process tree. +.El +.Pp The return value of the caller's .Fa func function determines whether or not iteration will continue. @@ -107,7 +122,8 @@ functions. .Bl -tag -width Er .It Er EINVAL -.Fa flag is not one of +.Fa flag +is not one of .Dv PR_WALK_PROC or .Dv PR_WALK_LWP .