Commit 064568d1 authored by Jiri Popelka's avatar Jiri Popelka

Make the code style consistent across netstat.c

parent aa01f8cc
...@@ -267,32 +267,33 @@ static void prg_cache_add(unsigned long inode, char *name) ...@@ -267,32 +267,33 @@ static void prg_cache_add(unsigned long inode, char *name)
unsigned hi = PRG_HASHIT(inode); unsigned hi = PRG_HASHIT(inode);
struct prg_node **pnp,*pn; struct prg_node **pnp,*pn;
prg_cache_loaded=2; prg_cache_loaded = 2;
for (pnp=prg_hash+hi;(pn=*pnp);pnp=&pn->next) { for (pnp = prg_hash + hi; (pn = *pnp); pnp = &pn->next) {
if (pn->inode==inode) { if (pn->inode == inode) {
/* Some warning should be appropriate here /* Some warning should be appropriate here
as we got multiple processes for one i-node */ as we got multiple processes for one i-node */
return; return;
} }
} }
if (!(*pnp=malloc(sizeof(**pnp)))) if (!(*pnp = malloc(sizeof(**pnp))))
return; return;
pn=*pnp; pn = *pnp;
pn->next=NULL; pn->next = NULL;
pn->inode=inode; pn->inode = inode;
if (strlen(name)>sizeof(pn->name)-1) if (strlen(name) > sizeof(pn->name) - 1)
name[sizeof(pn->name)-1]='\0'; name[sizeof(pn->name) - 1] = '\0';
strcpy(pn->name,name); strcpy(pn->name, name);
} }
static const char *prg_cache_get(unsigned long inode) static const char *prg_cache_get(unsigned long inode)
{ {
unsigned hi=PRG_HASHIT(inode); unsigned hi = PRG_HASHIT(inode);
struct prg_node *pn; struct prg_node *pn;
for (pn=prg_hash[hi];pn;pn=pn->next) for (pn = prg_hash[hi]; pn; pn = pn->next)
if (pn->inode==inode) return(pn->name); if (pn->inode == inode)
return("-"); return (pn->name);
return ("-");
} }
static void prg_cache_clear(void) static void prg_cache_clear(void)
...@@ -300,12 +301,12 @@ static void prg_cache_clear(void) ...@@ -300,12 +301,12 @@ static void prg_cache_clear(void)
struct prg_node **pnp,*pn; struct prg_node **pnp,*pn;
if (prg_cache_loaded == 2) if (prg_cache_loaded == 2)
for (pnp=prg_hash;pnp<prg_hash+PRG_HASH_SIZE;pnp++) for (pnp = prg_hash; pnp < prg_hash + PRG_HASH_SIZE; pnp++)
while ((pn=*pnp)) { while ((pn = *pnp)) {
*pnp=pn->next; *pnp = pn->next;
free(pn); free(pn);
} }
prg_cache_loaded=0; prg_cache_loaded = 0;
} }
static void wait_continous(void) static void wait_continous(void)
...@@ -365,32 +366,32 @@ static int extract_type_2_socket_inode(const char lname[], unsigned long * inode ...@@ -365,32 +366,32 @@ static int extract_type_2_socket_inode(const char lname[], unsigned long * inode
static void prg_cache_load(void) static void prg_cache_load(void)
{ {
char line[LINE_MAX],eacces=0; char line[LINE_MAX], eacces=0;
int procfdlen,fd,cmdllen,lnamelen; int procfdlen, fd, cmdllen, lnamelen;
char lname[30],cmdlbuf[512],finbuf[PROGNAME_WIDTH]; char lname[30], cmdlbuf[512], finbuf[PROGNAME_WIDTH];
unsigned long inode; unsigned long inode;
const char *cs,*cmdlp; const char *cs, *cmdlp;
DIR *dirproc=NULL,*dirfd=NULL; DIR *dirproc = NULL, *dirfd = NULL;
struct dirent *direproc,*direfd; struct dirent *direproc, *direfd;
if (prg_cache_loaded || !flag_prg) return; if (prg_cache_loaded || !flag_prg) return;
prg_cache_loaded=1; prg_cache_loaded = 1;
cmdlbuf[sizeof(cmdlbuf)-1]='\0'; cmdlbuf[sizeof(cmdlbuf) - 1] = '\0';
if (!(dirproc=opendir(PATH_PROC))) goto fail; if (!(dirproc=opendir(PATH_PROC))) goto fail;
while (errno=0,direproc=readdir(dirproc)) { while (errno = 0, direproc = readdir(dirproc)) {
for (cs=direproc->d_name;*cs;cs++) for (cs = direproc->d_name; *cs; cs++)
if (!isdigit(*cs)) if (!isdigit(*cs))
break; break;
if (*cs) if (*cs)
continue; continue;
procfdlen=snprintf(line,sizeof(line),PATH_PROC_X_FD,direproc->d_name); procfdlen = snprintf(line,sizeof(line),PATH_PROC_X_FD,direproc->d_name);
if (procfdlen<=0 || procfdlen>=sizeof(line)-5) if (procfdlen <= 0 || procfdlen >= sizeof(line) - 5)
continue; continue;
errno=0; errno = 0;
dirfd=opendir(line); dirfd = opendir(line);
if (! dirfd) { if (! dirfd) {
if (errno==EACCES) if (errno == EACCES)
eacces=1; eacces = 1;
continue; continue;
} }
line[procfdlen] = '/'; line[procfdlen] = '/';
...@@ -399,12 +400,12 @@ static void prg_cache_load(void) ...@@ -399,12 +400,12 @@ static void prg_cache_load(void)
/* Skip . and .. */ /* Skip . and .. */
if (!isdigit(direfd->d_name[0])) if (!isdigit(direfd->d_name[0]))
continue; continue;
if (procfdlen+1+strlen(direfd->d_name)+1>sizeof(line)) if (procfdlen + 1 + strlen(direfd->d_name) + 1 > sizeof(line))
continue; continue;
memcpy(line + procfdlen - PATH_FD_SUFFl, PATH_FD_SUFF "/", memcpy(line + procfdlen - PATH_FD_SUFFl, PATH_FD_SUFF "/",
PATH_FD_SUFFl+1); PATH_FD_SUFFl + 1);
strcpy(line + procfdlen + 1, direfd->d_name); strcpy(line + procfdlen + 1, direfd->d_name);
lnamelen=readlink(line,lname,sizeof(lname)-1); lnamelen = readlink(line, lname, sizeof(lname) - 1);
if (lnamelen == -1) if (lnamelen == -1)
continue; continue;
lname[lnamelen] = '\0'; /*make it a null-terminated string*/ lname[lnamelen] = '\0'; /*make it a null-terminated string*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment