[comp.os.vms] F$GETQUI Strangeness + Serious Example

rlb@rtpark.ge.COM (Bob Boyd 8*565-3627 25-Jul-1988 2124) (07/26/88)

Message created @ 25-JUL-1988 21:25:16.11

Below you will find the results of my munging on V5 DCL for a day or 2
If you have a V5 system on which to try this, please follow my suggestions
below and let me know what you discover -- this does not seem like what
it ought to be doing -- I have tried to comment this well enough so that
it is readable.  Please feel free to use it as an example for your own code

The strangeness is that DISPLAY_JOB and DISPLAY_ENTRY behave differently
when privileges are turned on.

When privileges are turned on -- JOB_INACCESSIBLE will return "" instead
of TRUE or FALSE for jobs belonging to a different username.  DISPLAY_JOB
will not return any information other than a very limited set.  DISPLAY_ENTRY
will return ALL of the information -- this seems inconsistent with the
behavior of SHOW QUEUE when a user has OPER & SYSPRV.

Try it-- let me know what your results are
My address is at the end of this message

================================ 8< cut here ================================
$ vfl = f$ver(0+f$trnlnm("debug$dcl"))
$!
$! F$GETQUI example
$!
$! Author: R.L. Boyd, GE Microelectronics Ctr.
$! Date:   25-Jul-1988
$! 
$! to enable debug -- DEFINE DEBUG$DCL 1
$!
$! To test this procedure cut and paste out the following:
$! $ queueA = "SYS$BATCH"	! your favorite batch queue
$! $ queueB = "30Min"		! another queue
$! $ otheruser = "FIELD"	! some username other than your own
$! $ create test.com
$! $DECK
$! $ wait 1:0:0
$! $EOD
$! $ submit test/queue='queueA'/noprint/notify
$! $ submit test/queue='queueB'/noprint/notify
$! $ submit test/queue='queueA'/USER='otheruser'
$! $ submit test/queue='queueB'/USER='otheruser'
$! $ submit test/queue='queueA'/hold/notify
$! $ 
$!Then @ this procedure and see what you get !
$!
$ set noon
$!
$! Set up symbols for everything
$! clear out any old list
$!
$ delete/symbol/global inaccessible_list
$!
$! attempt to elevate privileges -- it may do some good
$!
$ save_privs = f$setprv("oper,world")
$!
$ null = ""
$ b = " "
$ semi = ";"
$ comma = ","
$ say = "write sys$output "
$ hdr_FORMAT = "!15AS !12AS !15AS !8AS!/  !23AS   !23AS   !AS"
$ JOB_FORMAT = "!15AS !12AS !15AS !8AS!/  !23AS   !23AS   !SL"
$!
$ say f$fao(hdr_format,"QUEUE NAME","USERNAME","JOB NAME","PID",-
	"Submitted @","Started @","CPU Time(Clunks)")
$!
$! Add an inaccessible job to the list
$!
$INACC_ADD: subroutine
$   if f$type(inaccessible_list).eqs.null 
$ 	then 
$	  inaccessible_list == job_queue_name+comma+f$str(job_entry)
$ 	else
$	  inaccessible_list == inaccessible_list+-
		semi+job_queue_name+comma+f$string(job_entry)
$	endif !
$endsubroutine
$!
$! Get job info about a particular job -- 2 modes:
$! 	A.	DISPLAY_JOB for ones submitted by this user.
$!	B.	DISPLAY_ENTRY for those submitted by others.
$INFO_GET: subroutine
$ job_user == f$getqui(type,"USERNAME",'control')
$ job_pid  == f$getqui(type,"JOB_PID",'control')
$ job_submit_time == f$getqui(type,"SUBMISSION_TIME",'control')
$ job_name == f$getqui(type,"JOB_NAME",'control') 
$ if job_pid.nes.null 
$ then 
$ job_cputime == f$getjpi(job_pid,"CPUTIM")
$ job_login_time == f$getjpi(job_pid,"LOGINTIM")
$ else
$ job_cputime == 0
$ job_login_time == " "
$ endif
$ if f$ver() then $ show symbol job*
$ exit
$ endsubroutine
$!
$! Use FAO to display the information we got
$!
$INFO_DISPLAY: subroutine
$ say f$fao(job_format,job_queue_name,job_user,job_name,job_pid,-
	job_submit_time,job_login_time,job_cputime)
$ endsubroutine
$!
$! Loop through all of the batch queues to look for executing jobs
$! Then display interesting information about each one.
$!
$ set noon
$!
$! cancel any outstanding $GETQUI context
$!
$ control = ",""freeze_context"""
$ type = "DISPLAY_JOB"
$ TEMP = F$GETQUI("CANCEL_OPERATION")
$ vax_cluster = f$getsyi("vaxcluster")
$ if vax_cluster then $ my_scsnode = f$getsyi("scsnode")
$!
$! Get the next queue name, and establish context for DISPLAY_JOB function
$!
$QUEUE_LOOP:
$ job_queue_name = F$GETQUI("DISPLAY_QUEUE","QUEUE_NAME","*","BATCH")
$!
$! See if we have a name or if we have gotten to the end of the list
$!
$ if job_queue_name .nes.null 
$ then
$!
$! If we're in a cluster then see if it is on the current cpu or not
$! Use FREEZE_CONTEXT to keep it on this queue.
$!
$ if vax_cluster
$ then
$	scsnode = f$getqui("DISPLAY_QUEUE","SCSNODE_NAME",,"FREEZE_CONTEXT")
$	if scsnode.nes.my_scsnode then $ goto QUEUE_LOOP
$ endif
$!
$! Get the next job that is executing in this queue and establish
$! context for subsequent DISPLAY_JOB calls
$!
$JOB_LOOP:
$ job_entry = f$getqui("DISPLAY_JOB","ENTRY_NUMBER",,"EXECUTING_JOBS,ALL_JOBS")
$! save status value 
$ jbc_status = $status
$! Did we encounter an error?
$ if .not.jbc_status then $ goto QUEUE_LOOP
$! 
$! Did we get a good entry ?
$ if job_entry.nes.null
$ then 
$!
$! Use FREEZE_CONTEXT to get the rest of the information about this
$! job.  Then display it.
$!
$ job_inaccessible =f$getqui("DISPLAY_JOB","JOB_INACCESSIBLE",,"freeze_context")
$!
$! For some reason with privileges turned on, this never fails -- even
$! though F$GETQUI will NOT return any job info to speak of.
$!
$ if job_inaccessible 
$ then
$ 	call INACC_ADD
$ else
$ 	call INFO_GET
$! 
$! For some strange reason DISPLAY_JOB even with privs OPER and SYSPRV, etc
$! will not give information on other username jobs.
$! A workaround I discovered is to save them up and use DISPLAY_ENTRY on
$! them at the end.
$!
$	if (f$type(job_pid).eqs."STRING" ) .and. (job_pid.eqs.null)
$	then 
$		call INACC_ADD
$	else
$	 	call INFO_DISPLAY
$	endif
$ endif ! job inaccessible test -- with Privs this never works
$ goto JOB_LOOP
$ endif ! job check
$ goto QUEUE_LOOP
$ endif ! queue check
$ if f$type(inaccessible_list).nes.null
$ then
$  control = "job_entry"
$  type = "DISPLAY_ENTRY"
$  cnt = 0
$INACC_LOOP:
$ in_item = f$element(cnt,semi,inaccessible_list)
$ if in_item.eqs.semi then $ goto EXIT
$ 	cnt = cnt+1
$	if in_item.eqs.null then $ goto INACC_LOOP
$	job_queue_name = f$element(0,comma,in_item)
$	job_entry = f$element(1,comma,in_item)
$	call INFO_GET
$	call INFO_DISPLAY
$ 	goto INACC_LOOP
$ endif ! inaccessible_list
$EXIT:
$ if save_privs.nes.null then $ temp = f$setprv(save_privs)
$ temp = f$ver(vfl)
$ exit ! QUI_EXAMPLE
============================= End of Text to Cut =============================

-----------------------------------------------------------------
 Bob Boyd                     Usenet:    rlb@rtpark.ge.com
 GE Microelectronics Ctr.     Internet:  rlb%rtpark.ge.com@mcnc           
 POB 13049, MS 7T3-01         BitNet:    rlb%rtpark.ge.com@relay.cs.net
 RTP, NC 27709-3049           Voice:     (919)549-3627 
 GE DECnet: RTPARK::RLB       GE DIALCOMM:  8*565-3627  PROFS: MECRLBT(SSAVRNA)