H DEBUG(*YES) H/TITLE Receive command * * This program should be compiled with the following command: * * CRTBNDRPG * DBGVIEW(*SOURCE) CVTOPT(*DATETIME) USRPRF(*OWNER) * DFTACTGRP(*NO) BNDDIR(Y1BNDDIR QC2LE) ACTGRP(*NEW) * * After compilation, it should be changed to be owned by QSYS. * *===================================================================== * SYNOPSIS: This program is a receiver program for command requests. * When it is invoked within a job, it looks for entries in * a data queue called CMDQ and it invokes each entry as a * command. See the documentation for the SNDCMD command and * the SNDCMDR program for more details. *===================================================================== D/COPY QRPGLESRC,PGMSDS D/COPY QSYSINC/QRPGLESRC,QUSEC * D system PR 10I 0 extproc('system') D * value options(*string) * D qsnddtaq PR Extpgm('QSNDDTAQ') D dtaq 10A Const D dtaqlib 10A Const D dtaqlen 5P 0 Const D data 64512A Const Options(*Varsize) *‚Optional Parameter Group 1 D keylen 3P 0 Const Options(*Nopass) D keydata 256A Const Options(*Nopass:*Varsize) *‚Optional Parameter Group 2 D asyncrqs 10A Const Options(*Nopass) * D qrcvdtaq PR Extpgm('QRCVDTAQ') D dtaq 10A Const D dtaqlib 10A Const D datalen 5P 0 D data 64512A Options(*Varsize) D wait 5P 0 Const *‚Optional Parameter Group 1 D keyorder 2A Const Options(*Nopass) D keylen 3P 0 Const Options(*Nopass) D keydata 256A Options(*Nopass:*Varsize) D senderinfolen 3P 0 Const Options(*Nopass) D senderinfo 32767A Options(*Nopass:*Varsize) *‚Optional Parameter Group 2 D removemessage 10A Const Options(*Nopass) D receiverlen 5P 0 Const Options(*Nopass) D ApiError Like(QUSEC) D Options(*Nopass:*Varsize) * D SenderInfoDS DS D SndInfBytRtn 7P 0 D SndInfBytAvl 7P 0 D SndInfSndJob 10A D SndInfSndUsr 10A D SndInfSndNbr 6A D SndInfCurUsr 10A * D chkobj PR Extpgm('QUSROBJD') D RcvVar 32767A Options(*Varsize) D RcvVarLen 10I 0 Const D Format 8A Const D qObj 20A Const D ObjType 10A Const D ApiError Like(QUSEC) D Options(*Nopass) * D WriteToJobLog PR 10I 0 ExtProc('Qp0zLprintf') D Message@ * Value Options(*String) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) D * Value Options(*String:*Nopass) * D qDtaq DS D Dtaq 10A Inz('CMDQ') D DtaqLib 10A D DataLen S 5P 0 D Data DS D Control 10A D LogCmd N Overlay(Control) D AlwErr N Overlay(Control:*Next) D SndRsp N Overlay(Control:*Next) D Cmd 2000A D Log S Like(Cmd) D Count S 10I 0 D Error S 10I 0 D PSSR_Error S N D First S N * *===================================================================== D main PR Extpgm('RCVCMDR') D P_Dummy 128A * D main PI D P_Dummy 128A *===================================================================== /free Count = 0; Error = 0; PSSR_Error = *off; First = *on; DtaqLib = PSDSPgmLib; //‚Process all the commands in the data queue dou DataLen = 0; //‚Get the data from the data queue qrcvdtaq( Dtaq : DtaqLib : DataLen : Data : 0 : 'EQ' : 6 : PSDSJobNbrC : %size( SenderInfoDS ) : SenderInfoDS ); if %error; exsr *pssr; endif; if DataLen = 0; //‚No commands to process, so leave loop leave; endif; //‚If this is the first command being processed, send a data //‚queue entry back to the sender saying we have control, so //‚it can end tracing (unless we ARE the sender). if First = *on; First = *off; if SndInfSndNbr <> PSDSJobNbrC; qsnddtaq( Dtaq : DtaqLib : 2010 : Data : 6 : SndInfSndNbr ); endif; endif; //‚Log the command in the joblog if requested if LogCmd = *on; Log = '/* Remote command from job ' + %trim( SndInfSndNbr ) + '/' + %trim( SndInfSndUsr ) + '/' + %trim( SndInfSndJob ) + ': ' + %trim( Cmd ) + ' */'; WriteToJobLog( Log ); endif; //‚Execute the command if system( Cmd ) = 0; Count = Count + 1; else; Error = Error + 1; if AlwErr = *off; exsr *pssr; endif; endif; enddo; //‚Send a response to the sender if requested if SndRsp = *on and ( Count > 0 or Error > 0 ); Cmd = %char( Count ) + ' commands completed successfully and ' + %char( Error ) + ' commands failed in job ' + %trim( PSDSJobNbrC ) + '/' + %trim( PSDSJobUser ) + '/' + %trim( PSDSJobName ) + '.'; qsnddtaq( Dtaq : DtaqLib : 2010 : Data : 6 : SndInfSndNbr ); endif; *inlr = *on; return; begsr *pssr; if PSSR_Error = *off; PSSR_Error = *on; Cmd = 'Processing failure in job ' + %trim( PSDSJobNbrC ) + '/' + %trim( PSDSJobUser ) + '/' + %trim( PSDSJobName ) + '.'; qsnddtaq( Dtaq : DtaqLib : 2010 : Data : 6 : SndInfSndNbr ); endif; *inlr = *on; return; endsr; /end-free