/* rexx */ /*********************************************************************** Author: Bill Schoen WSCHOEN at KGNVMC, schoen@vnet.ibm.com Title: Shutdown process and unmount file systems for OMVS, prior to an IPL PROPERTY OF IBM COPYRIGHT IBM CORP. 1997,2000 ***********************************************************************/ arg lp tm . if datatype(lp,w)=0 then lp=3 if datatype(tm,w)=0 then tm=10 if syscalls(on)>4 then do say 'Unable to issue system calls' exit 4 end address syscall 'getpid' me=retval 'open /dev/console' o_wronly fd=retval call killall call unmountall mtm_immed return 0 killall: call sendsig sigterm 'SIGTERM' call waitkill if p.0<3 then return call sendsig sigkill 'SIGKILL' call waitkill if p.0<3 then return call say 'The following processes did not terminate:' do i=1 to p.0 pid=p.i.ps_pid if pid=me | pid=1 then iterate state=p.i.ps_state select when state=ps_run then state='RUN' when state=ps_waito then state='K-WAIT' when state=ps_child then state='CHILD' when state=ps_zombie then state='ZOMBIE' when state=ps_fork then state='FORK' when state=ps_sleep then state='SLEEP' when state=ps_waitc then state='C-WAIT' when state=ps_waitf then state='F-WAIT' when state=ps_msgrcv then state='MSGRCV' when state=ps_msgsnd then state='MSGSND' when state=ps_semwt then state='SEM-WT' when state=ps_freeze then state='FREEZE' when state=ps_quiesce then state='QUIESCE' when state=ps_zombie2 then state='ZOMBIE2' when state=ps_pause then state='PAUSE' otherwise end call say right(pid,10) left(state,8) p.i.ps_cmd p.i.ps_path end return sendsig: parse arg sig signm call say 'Attempting to terminate active processes with' signm p.='' 'getpsent p.' do i=1 to p.0 pid=p.i.ps_pid if pid=me | pid=1 then iterate 'kill' pid sig end return waitkill: do j=1 to lp 'sleep' tm 'getpsent p.' if p.0<3 then leave end return unmountall: numeric digits 12 sysnames=-1073741810 cvt=c2x(storage(10,4)) ecvt=c2x(storage(d2x(x2d(cvt)+140),4)) ocvt=c2x(storage(d2x(x2d(ecvt)+240),4)) oext=c2x(storage(d2x(x2d(ocvt)+12),4)) flag=storage(d2x(x2d(oext)+8),1) if bitand(flag,'20'x)='20'x Then do 'pfsctl KERNEL' sysnames 'syslist 400' if retval>1 then do call sysplex return end end parse arg how call say 'Unmounting all file systems' do until didone=0 didone=0 'getmntent m.' do i=1 to m.0 "unmount (m.mnte_fsname.i)" how if retval<>-1 then didone=1 end end m.='' 'getmntent m.' if m.mnte_fsname.1<>'SYSROOT' then do i=1 to m.0 call say 'Unmount failed for' strip(m.mnte_fsname.i) end return sysplex: numeric digits 12 z4='00000000'x 'uname u.' m.='' 'getmntent m.' call say 'Unmounting automounted file systems from' u.u_nodename auto='' do i=1 to m.0 if m.mnte_fstype.i='AUTOMNT' then auto=auto m.mnte_dev.i end f=0 s=0 do i=1 to m.0 st.='' path=m.mnte_path.i || '/..' 'stat (path) st.' if retval=-1 then iterate if wordpos(x2d(st.st_dev),auto)=0 then iterate if u.u_nodename<>m.mnte_sysname.i then iterate "unmount (m.mnte_fsname.i)" mtm_immed if retval=-1 then f=f+1 else s=s+1 end if f>0 | s>0 then call say '---Success:' s ' Failure:' f m.='' f=0 s=0 'getmntent m.' j=0 do i=1 to m.0 cmode=d2c(m.mnte_mode.i,4) if u.u_nodename = m.mnte_sysname.i &, /* this system */ bitand(cmode,'00000010'x)=z4 then /* automove yes */ j=j+1 end if j>0 then call say 'Moving' j 'automovable file systems from' u.u_nodename do i=1 to m.0 cmode=d2c(m.mnte_mode.i,4) if u.u_nodename = m.mnte_sysname.i &, /* this system */ bitand(cmode,'00000010'x)=z4 then /* automove yes */ Do mt.='' mt.mnte_rflags=1 mt.mnte_mode=0 mt.mnte_sysname='*' mt.mnte_fsname=m.mnte_fsname.i 'mount mt.' if retval=-1 then do f=f+1 call err 'Move failed for' strip(m.mnte_fsname.i),, errno,errnojr end else s=s+1 end end if f>0 | s>0 then call say '---Success:' s ' Failure:' f m.='' f=0 s=0 'getmntent m.' j=0 do i=1 to m.0 if u.u_nodename = m.mnte_sysname.i then j=j+1 end if j>0 then call say 'Unmounting' j 'remaining file systems from' u.u_nodename do i=1 to m.0 d=0 k=0 do j=1 to m.0 if m.mnte_dev.j>d & u.u_nodename = m.mnte_sysname.j then do d=m.mnte_dev.j k=j end end if k>0 then do m.mnte_dev.k=0 "unmount (m.mnte_fsname.k)" mtm_immed if retval=-1 then do f=f+1 call err 'Unmount failed for' strip(m.mnte_fsname.k),, errno,errnojr end else s=s+1 end end if f>0 | s>0 then call say '---Success:' s ' Failure:' f return err: parse arg emsg,eerr,ersn call say emsg 'Errno' eerr 'Rsn' ersn err.='' address syscall 'strerror' eerr ersn 'err.' if err.1='' then return call say ' 'err.1 if err.4<>'' then call say ' 'err.2 return say: trace o parse arg msg say msg msg='BPXSTOP:' msg||esc_n 'write (fd) msg' return