pfiles.c revision 0d166b18feda26f6f45f5be1c0c8c5e539b90e6c
/*
* 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
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <dirent.h>
#include <limits.h>
#include <door.h>
#include <libproc.h>
static char *command;
static volatile int interrupt;
static int Fflag;
static void intr(int);
static void dofcntl(struct ps_prochandle *, int, int, int);
static void dosocket(struct ps_prochandle *, int);
static void dotli(struct ps_prochandle *, int);
static void show_files(struct ps_prochandle *);
static void show_fileflags(int);
static void show_door(struct ps_prochandle *, int);
int
{
int retc = 0;
int opt;
int errflg = 0;
struct ps_prochandle *Pr;
command++;
else
/* options */
switch (opt) {
case 'F': /* force grabbing (no O_EXCL) */
Fflag = PGRAB_FORCE;
break;
case 'n':
break;
default:
errflg = 1;
break;
}
}
command);
" (report open files of each process)\n");
" -F: force grabbing of the target process\n");
exit(2);
}
/* catch signals from terminal */
(void) proc_initstdio();
char *arg;
int gret;
(void) proc_flushstdio();
/* get the specified pid and the psinfo struct */
retc++;
if (Pcreate_agent(Pr) == 0) {
(void) printf("%d:\t%.70s\n",
show_files(Pr);
} else {
"%s: cannot control process %d\n",
retc++;
}
} else {
switch (gret) {
case G_SYS:
case G_SELF:
(void) printf(" [system process]\n");
else
break;
default:
retc++;
break;
}
}
}
(void) proc_finistdio();
retc++;
return (retc);
}
/* ARGSUSED */
static void
{
interrupt = 1;
}
/* ------ begin specific code ------ */
static void
{
const char *dev;
char pname[100];
int fd;
char *s;
int ret;
if (nfd == RLIM_INFINITY)
(void) printf(
" Current rlimit: unlimited file descriptors\n");
else
(void) printf(
" Current rlimit: %lu file descriptors\n", nfd);
}
/* in case we are doing this to ourself */
return;
}
/* for each open file --- */
char unknown[12];
/* skip '.' and '..' */
continue;
s = unknown;
perror(s);
continue;
}
case S_IFIFO: s = "S_IFIFO"; break;
case S_IFDIR: s = "S_IFDIR"; break;
case S_IFREG: s = "S_IFREG"; break;
case S_IFLNK: s = "S_IFLNK"; break;
case S_IFSOCK: s = "S_IFSOCK"; break;
case S_IFDOOR: s = "S_IFDOOR"; break;
case S_IFPORT: s = "S_IFPORT"; break;
default:
s = unknown;
(void) sprintf(s, "0x%.4x ",
break;
}
(void) printf(" dev:%lu,%lu",
else
(void) printf(" uid:%d gid:%d",
(void) printf(" size:%lld\n",
continue;
}
(void) printf(" ino:%llu uid:%d gid:%d",
(void) printf(" size:%lld\n",
(void) printf(" rdev:%lu,%lu\n",
else
if (!nflag) {
continue;
/*
* There's no elegant way to determine if a
* character device supports TLI, so we lame
* out and just check a hardcoded list of
* known TLI devices.
*/
int i;
const char *tlidevs[] =
dev++; /* skip past the `:' */
break;
}
}
}
if (offset != -1) {
}
}
}
}
static int
{
int ret;
#ifdef _LP64
struct flock64_32 flock_target;
return (ret);
}
#endif /* _LP64 */
return (ret);
}
/* examine open file with fcntl() */
static void
{
int fileflags;
int fdflags;
(void) printf(" ");
if (fileflags != -1)
(void) printf(" FD_CLOEXEC");
if (isdoor)
} else if (isdoor) {
(void) printf(" ");
}
(void) printf(" %s %s lock set by",
if (sysid)
}
}
}
#ifdef O_PRIV
#else
#endif
static void
show_fileflags(int flags)
{
char buffer[136];
case O_RDONLY:
break;
case O_WRONLY:
break;
case O_RDWR:
break;
default:
break;
}
if (flags & O_NONBLOCK)
#ifdef O_PRIV
#endif
if (flags & O_LARGEFILE)
if (flags & ~(ALL_O_FLAGS))
flags & ~(ALL_O_FLAGS));
}
/* show door info */
static void
{
return;
(void) printf(" door to ");
else
}
/*
* Print out the socket address pointed to by `sa'. `len' is only
* needed for AF_UNIX sockets.
*/
static void
{
char abuf[INET6_ADDRSTRLEN];
const char *p;
default:
return;
case AF_INET:
return;
case AF_INET6:
return;
case AF_UNIX:
/* Null terminate */
(void) printf("\t%s: AF_UNIX %s\n",
}
return;
case AF_IMPLINK: p = "AF_IMPLINK"; break;
case AF_PUP: p = "AF_PUP"; break;
case AF_CHAOS: p = "AF_CHAOS"; break;
case AF_NS: p = "AF_NS"; break;
case AF_NBS: p = "AF_NBS"; break;
case AF_ECMA: p = "AF_ECMA"; break;
case AF_DATAKIT: p = "AF_DATAKIT"; break;
case AF_CCITT: p = "AF_CCITT"; break;
case AF_SNA: p = "AF_SNA"; break;
case AF_DECnet: p = "AF_DECnet"; break;
case AF_DLI: p = "AF_DLI"; break;
case AF_LAT: p = "AF_LAT"; break;
case AF_HYLINK: p = "AF_HYLINK"; break;
case AF_APPLETALK: p = "AF_APPLETALK"; break;
case AF_NIT: p = "AF_NIT"; break;
case AF_802: p = "AF_802"; break;
case AF_OSI: p = "AF_OSI"; break;
case AF_X25: p = "AF_X25"; break;
case AF_OSINET: p = "AF_OSINET"; break;
case AF_GOSIP: p = "AF_GOSIP"; break;
case AF_IPX: p = "AF_IPX"; break;
case AF_ROUTE: p = "AF_ROUTE"; break;
case AF_LINK: p = "AF_LINK"; break;
}
}
static void
{
static const char *types[] = {
};
else
}
#define BUFSIZE 200
static void
{
char buf1[32];
char ipaddr[INET_ADDRSTRLEN];
int i;
struct boolopt {
int level;
int opt;
const char *name;
};
};
struct linger l;
}
vlen = sizeof (l);
l.l_onoff != 0) {
l.l_linger);
}
}
}
vlen = sizeof (nexthop_val);
&vlen) == 0) {
if (vlen > 0) {
ipaddr);
}
}
}
/* the file is a socket */
static void
{
/* A buffer large enough for PATH_MAX size AF_UNIX address */
/ sizeof (long)];
}
/* the file is a TLI endpoint */
static void
{
}