Added process selection mechanism. It's not included in Solaris 2.5 build,

* proclist.c: Added process selection mechanism. It's not
        included in Solaris 2.5 build, since we first have to decide
        what will be dispatched to daemon.
This commit is contained in:
Drazen Kacar
1999-05-10 05:44:52 +00:00
parent a246a6390f
commit c1649507e9
2 changed files with 89 additions and 6 deletions

View File

@@ -1,3 +1,9 @@
1999-05-10 Drazen Kacar <dave@srce.hr>
* proclist.c: Added process selection mechanism. It's not
included in Solaris 2.5 build, since we first have to decide
what will be dispatched to daemon.
1999-05-10 Drazen Kacar <dave@srce.hr>
There be some useful documentation now. Syncing...

View File

@@ -61,13 +61,44 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
DIR *proc;
struct dirent *entry;
char buffer [BUFSIZ];
unsigned count, total, pid;
unsigned count, total, pid, mask;
unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
unsigned pids_size = 0, pids_offset = 0, new_size;
struct stat statb;
int len, i, ok;
memset (buf, 0, sizeof (glibtop_proclist));
mask = which & ~GLIBTOP_KERN_PROC_MASK;
which &= GLIBTOP_KERN_PROC_MASK;
/* Check if the user wanted only one process */
if(which == GLIBTOP_KERN_PROC_PID)
{
if(mask)
{
struct psinfo psinfo;
if(glibtop_get_proc_data_psinfo_s(server, &psinfo, pid))
return NULL;
if(mask & GLIBTOP_EXCLUDE_IDLE && !psinfo.pr_pctcpu)
return NULL;
if(mask & GLIBTOP_EXCLUDE_SYSTEM && psinfo.pr_flag & SSYS)
return NULL;
if(mask & GLIBTOP_EXCLUDE_NOTTY && psinfo.pr_ttydev == PRNODEV)
return NULL;
}
else
{
sprintf(buffer, "/proc/%d", arg);
if(s_stat(buffer, &statb) < 0)
return NULL;
}
if(!(pids_chain = glibtop_malloc(sizeof(unsigned))))
return NULL;
*pids_chain = pid;
return pids_chain;
}
proc = opendir ("/proc");
if (!proc) return NULL;
@@ -96,13 +127,59 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
#else
pid = (unsigned)atol(entry->d_name);
#endif
sprintf (buffer, "/proc/%d", pid);
#ifdef HAVE_PROCFS_H
/* is it really a directory? */
#ifdef HAVE_PROCFS_H
/* Can we skip it based on the request? Solaris 2.6
has ruid and rgid in struct stat. Solaris 7 has euid
and egid. We'll ignore 2.6 for now */
if(!mask && which == GLIBTOP_KERN_PROC_UID)
{
sprintf (buffer, "/proc/%d", pid);
if (s_stat (buffer, &statb)) continue;
if (!S_ISDIR (statb.st_mode)) continue;
if(statb.st_uid != arg) continue;
}
if(which != GLIBTOP_KERN_PROC_ALL)
{
struct psinfo psinfo;
if(glibtop_get_proc_data_psinfo_s(server, &psinfo, pid))
continue;
if(mask)
{
if(mask & GLIBTOP_EXCLUDE_IDLE && !psinfo.pr_pctcpu)
continue;
if(mask & GLIBTOP_EXCLUDE_SYSTEM && psinfo.pr_flag & SSYS)
continue;
if(mask & GLIBTOP_EXCLUDE_NOTTY &&
psinfo.pr_ttydev == PRNODEV)
continue;
}
switch(which)
{
case GLIBTOP_KERN_PROC_PGRP: if(psinfo.pr_pgid != arg)
continue;
break;
case GLIBTOP_KERN_PROC_SESSION: if(psinfo.pr_sid != arg)
continue;
break;
case GLIBTOP_KERN_PROC_TTY: if(psinfo.pr_ttydev != arg)
continue;
break;
case GLIBTOP_KERN_PROC_UID: if(psinfo.pr_euid != arg)
continue;
break;
case GLIBTOP_KERN_PROC_RUID: if(psinfo.pr_uid != arg)
continue;
break;
default: continue;
}
}
#endif
/* Fine. Now we first try to store it in pids. If this buffer is
* full, we copy it to the pids_chain. */