home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume23
/
sps2
/
part03
/
selectproc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-08
|
2KB
|
96 lines
# ifndef lint
static char SccsId[] = "@(#)selectproc.c 1.2\t6/15/90" ;
# endif
# include "sps.h"
# include "flags.h"
# ifdef USELOGINUID
# include <pwd.h>
# endif USELOGINUID
/*
** SELECTPROC - Given a process structure, this procedure decides whether
** the process is a candidate for printing.
*/
selectproc ( p, process, thisuid )
register struct process *p ;
register struct process *process ;
int thisuid ;
{
register union flaglist *fp ;
register struct process *pp ;
#ifdef USELOGINUID
char *username ;
struct passwd *pw ;
char *getlogin() ;
struct passwd *getpwnam() ;
#endif USELOGINUID
extern struct flags Flg ;
/* Flg.flg_AZ is an internal flag set if one of flags `A' to `Z'
was specified. If this is not set, a process is listed only
if it or one of its ancestors belongs to the invoking user. */
if ( !Flg.flg_AZ )
{
#ifdef USELOGINUID
thisuid = (username = getlogin())
&& (pw = getpwnam( username )) ? pw->pw_uid : getuid() ;
#endif USELOGINUID
for ( pp = p ; pp > &process[1] ; pp = pp->pr_pptr )
if ( thisuid == pp->pr_p.p_uid )
return ( 1 ) ;
}
if ( Flg.flg_A )
return ( 1 ) ;
if ( Flg.flg_P )
for ( fp = Flg.flg_Plist ; fp->f_pid >= 0 ; fp++ )
if ( fp->f_pid == p->pr_p.p_pid )
return ( 1 ) ;
if ( Flg.flg_U )
for ( pp = p ; pp > &process[1] ; pp = pp->pr_pptr )
for ( fp = Flg.flg_Ulist ; fp->f_uid >= 0 ; fp++ )
if ( fp->f_uid == pp->pr_p.p_uid )
return ( 1 ) ;
switch ( p->pr_p.p_stat )
{
case SRUN :
if ( Flg.flg_B )
# ifdef SUNOS40
/* Ignore the idle processes */
return ( p->pr_p.p_pid != 3
&& p->pr_p.p_pid != 4 ) ;
# else
return ( 1 ) ;
# endif SUNOS40
break ;
case SSLEEP :
if ( Flg.flg_B
&& p->pr_p.p_pri < PZERO && p->pr_p.p_pid > MSPID )
# ifdef SUNOS40
/* Ignore the idle processes */
return ( p->pr_p.p_pid != 3
&& p->pr_p.p_pid != 4 ) ;
# else
return ( 1 ) ;
# endif SUNOS40
case SWAIT :
case SIDL :
if ( Flg.flg_W )
return ( 1 ) ;
break ;
case SSTOP :
if ( Flg.flg_S )
return ( 1 ) ;
break ;
case SZOMB :
if ( Flg.flg_Z )
return ( 1 ) ;
break ;
default :
break ;
}
return ( 0 ) ;
}