diff --git a/sysdeps/solaris/ChangeLog b/sysdeps/solaris/ChangeLog index b5e09253..3b8b4412 100644 --- a/sysdeps/solaris/ChangeLog +++ b/sysdeps/solaris/ChangeLog @@ -1,3 +1,9 @@ +1999-05-10 Drazen Kacar + + * 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 There be some useful documentation now. Syncing... diff --git a/sysdeps/solaris/proclist.c b/sysdeps/solaris/proclist.c index 11c1176a..de79cf4a 100644 --- a/sysdeps/solaris/proclist.c +++ b/sysdeps/solaris/proclist.c @@ -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; @@ -87,7 +118,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, if (!ok) continue; #else if(entry->d_name[0] == '.') - continue; + continue; #endif /* convert it in a number */ @@ -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? */ - if (s_stat (buffer, &statb)) continue; + /* 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 (!S_ISDIR (statb.st_mode)) continue; + 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. */