/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <libgen.h>
#include <limits.h>
#include <alloca.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <dirent.h>
#include "Pcontrol.h"
static int
{
/*
* Allocate enough space for procfs_path + arg + "/psinfo"
*/
int fd;
} else
/*
* Attempt to open the psinfo file, and return the fd if we can
* confirm this is a regular file provided by /proc.
*/
fd = -1;
}
return (fd);
}
static int
{
#ifdef _BIG_ENDIAN
#else
#endif
int fd;
/*
* Attempt to open the core file, and return the fd if we can confirm
* this is an ELF file of type ET_CORE.
*/
fd = -1;
fd = -1;
if (is_noelf == 0 &&
*perr = G_ISAINVAL;
}
return (fd);
}
/*
* Make the error message precisely match the type of arguments the caller
* wanted to process. This ensures that a tool which only accepts pids does
* not produce an error message saying "no such process or core file 'foo'".
*/
static int
{
return (G_NOPROC);
return (G_NOCORE);
return (G_NOPROCORCORE);
}
static void *
{
char *core;
int fd;
char *slash;
*perr = 0;
if (lwps)
/*
* Check to see if the user has supplied an lwp range. First,
*/
*slash = '\0';
if ((oflag & PR_ARG_PIDS) &&
*slash = '/';
if (proc_lwp_range_valid(*lwps) != 0) {
return (NULL);
}
if (psp) {
return (psp);
} else {
perr));
}
}
}
/*
* Next, try grabbing it as a corefile.
*/
if ((oflag & PR_ARG_CORES) &&
*slash = '/';
if (proc_lwp_range_valid(*lwps) != 0) {
return (NULL);
}
if (psp) {
sizeof (psinfo_t));
return (psp);
} else {
return (Pr);
}
}
}
*slash = '/';
}
if (psp) {
return (psp);
} else {
}
}
/*
* If the read failed, the process may have gone away;
* we continue checking for core files or fail with G_NOPROC
*/
}
if (psp) {
sizeof (psinfo_t));
return (psp);
} else {
return (Pr);
}
}
}
/*
* We were unable to open the corefile. If we have no meaningful
* information, report the (ambiguous) error from open_error().
*/
if (*perr == 0)
return (NULL);
}
struct ps_prochandle *
{
}
struct ps_prochandle *
{
}
{
return (-1);
else
}
const char **lwps)
{
return (-1);
else
}
/*
* Convert psinfo_t.pr_psargs string into itself, replacing unprintable
* characters with space along the way. Stop on a null character.
*/
void
{
int c;
while (n-- != 0 && (c = (*s & UCHAR_MAX)) != '\0') {
if (!isprint(c))
c = ' ';
*s++ = (char)c;
}
*s = '\0';
}
static int
{
if (*range == '-')
*low = 0;
else
return (0);
}
if (*range != '-') {
return (-1);
}
range++;
if (*range == '\0')
else
return (-1);
}
}
return (0);
}
/*
* Determine if the specified lwpid is in the given set of lwpids.
* The set can include multiple lwpid ranges separated by commas
* and has the following syntax:
*
* lwp_range[,lwp_range]*
*
* where lwp_range is specifed as:
*
* -n lwpid <= n
* n-m n <= lwpid <= m
* n- lwpid >= n
* n lwpid == n
*/
int
{
char *comma;
/*
* A NULL set indicates that all LWPs are valid.
*/
return (1);
*comma = '\0';
*comma = ',';
return (0);
}
*comma = ',';
} else {
}
return (1);
}
return (0);
}
int
{
char *comma;
int ret;
return (-1);
*comma = '\0';
*comma = ',';
return (ret);
}
*comma = ',';
} else {
}
}
return (0);
}
/*
* Walk all processes or LWPs in /proc and call func() for each.
* Omit system processes (like process-IDs 0, 2, and 3).
* Stop calling func() if it returns non 0 value and return it.
*/
int
{
char *errptr;
void *buf;
char *ptr;
int bufsz;
int fd, i;
int ret = 0;
return (-1);
}
return (-1);
continue;
continue;
/* PR_WALK_PROC case */
if (fd < 0)
continue;
continue;
}
if (flag == PR_WALK_PROC) {
break;
continue;
}
/* PR_WALK_LWP case */
if (fd < 0)
continue;
sizeof (prheader)) {
continue;
}
ret = -1;
break;
}
continue;
}
/*LINTED ALIGNMENT*/
break;
}
}
}
return (ret);
}