fds.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2007 AT&T Knowledge Ventures *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Knowledge Ventures *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
static const char usage[] =
"[-?\n@(#)$Id: fds (AT&T Research) 2006-10-26 $\n]"
"[+NAME?fds - list open file descriptor status]"
"[+DESCRIPTION?\bfds\b lists the status for each open file descriptor. "
"When invoked as a shell builtin it accesses the file descriptors of the "
"calling shell, otherwise it lists the file descriptors passed across "
"\bexec\b(2).]"
"[l:long?List file descriptor details.]"
"[+SEE ALSO?\blogname\b(1), \bwho\b(1), \bgetgroups\b(2)]"
;
#include <cmd.h>
#include <ls.h>
#if defined(S_IFSOCK) && _sys_socket && _hdr_arpa_inet && _hdr_netinet_in && _lib_getsockname && _lib_getsockopt && _lib_inet_ntoa
#else
#endif
#ifndef minor
#define minor(x) (int)((x)&0xff)
#endif
#ifndef major
#endif
int
{
register char* s;
register int i;
register char* m;
register char* x;
int flags;
int details;
#ifdef S_IFSOCK
struct sockaddr_in addr;
int type;
int prot;
char num[32];
#endif
details = 0;
for (;;)
{
{
case 'l':
continue;
case '?':
continue;
case ':':
continue;
}
break;
}
for (i = 0; i <= OPEN_MAX; i++)
/* not open */;
else if (details)
{
m = "--";
else
{
case O_RDONLY:
m = "r-";
break;
case O_WRONLY:
m = "-w";
break;
case O_RDWR:
m = "rw";
break;
default:
m = "??";
break;
}
#ifdef S_IFSOCK
#ifdef SO_TYPE
#else
&& !(type = 0)
#endif
#ifdef SO_PROTOTYPE
#else
&& !(prot = 0)
#endif
)
{
s = 0;
switch (type)
{
case SOCK_DGRAM:
s = "udp";
break;
case SOCK_STREAM:
if (prot == 0)
s = "tcp";
#ifdef IPPROTO_SCTP
else if (prot == IPPROTO_SCTP)
s = "sctp";
#endif
break;
}
if (!s)
sfprintf(sfstdout, "%02d %s%s %s /dev/%s/%s/%d\n", i, m, x, fmtmode(st.st_mode, 0), s, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
}
#endif
else
sfprintf(sfstdout, "%02d %s%s %s /dev/inode/%u/%u\n", i, m, x, fmtmode(st.st_mode, 0), st.st_dev, st.st_ino);
}
else
return 0;
}