I've written a socket program in RPG. Most of the time, it is in state
SELW (socket select()).
I wrote and registered an exit handler, which is executed whenever the
call stack entry is terminated - like so:
0274.00 D goExitHandler S * PROCPTR
INZ(%PADDR(ExitHandler))
...
...
0304.00 * Register exit handler
0305.00 C CALLB 'CEERTX'
0306.00 C PARM goExitHandler
0307.00 C PARM *OMIT
0308.00 C PARM *OMIT
This works fine for SysReq 2 and ENDJOB *IMMED and I can do housekeeping
like closing sockets, streamfiles, whatever.
I would also like to be notified, whenever someone issues ENDJOB
*CNTRLD. I studied the ILE RPG Programming manual (condition handlers
and so forth), but I didn't get any further.
So my basic question is:
How can I register a procedure that gets called on ENDJOB *CNTRLD?
Thanks in advance for any hints and suggestions.
Best regards,
Klaus
There may be a way to register a program/procedure as you desire, or if
not, an alternative/equivalent mechanism. Hopefully others will show how
it's done. If not, this suggestion might be considered a last resort.
Reading the description of socket select(), I see a wait_time parameter.
This would seem to enable a polling technique, whereby whenever control
returns to the program from select(), the current job "end status" could
be retrieved and checked. A couple ways to retrieve it: use RTVJOBA
ENDSTS() in a CL program, or use the QUSRJOBI API.
(Note that if using ILE, a CL ILE module could be created and bound with
RPG in the same program, for better call/return performance.)
--
Karl Hanson
[snip...]
>> So my basic question is:
>> How can I register a procedure that gets called on ENDJOB *CNTRLD?
>>
> There may be a way to register a program/procedure as you desire, or if
> not, an alternative/equivalent mechanism. Hopefully others will show how
> it's done. If not, this suggestion might be considered a last resort.
> Reading the description of socket select(), I see a wait_time parameter.
> This would seem to enable a polling technique, whereby whenever control
> returns to the program from select(), the current job "end status" could
> be retrieved and checked. A couple ways to retrieve it: use RTVJOBA
> ENDSTS() in a CL program, or use the QUSRJOBI API.
>
> (Note that if using ILE, a CL ILE module could be created and bound with
> RPG in the same program, for better call/return performance.)
Karl, many thanks for your help. My program is indeed written in ILE, it
already uses procedures implemented in other modules (RPG, C and CL).
I will give it a try.
Best regards and have a nice weekend,
Klaus
However rather than trying to handle generic ENDJOB OPTION(*CNTRLD)
DELAY(##) requests, there is at least one other perspective to consider.
Why not instead, ensure the system management for termination of that
application should be requested via an /application end request/. That
is, the application itself provides an interface to end its job, by some
command *other* than ENDJOB. For example, consider STRTCPSVR and
ENDTCPSVR. The application TCP server application is started and then
ended, not by ENDJOB, but by a specific command that requests to end
that application; the server which was started previously, also by a
command. The job can be requested by some notification broadcast to
that job, that it should /close up shop/ and end.
After writing this... I checked the docs to clarify my expectation of
the cancel handler, and there is actually a page that says much of the
same as I wrote above. Similar specifically to the paragraph just above
where I suggest creating something like an ENDMYAPP command, one part of
that doc suggests "you can remove your cancel handlers and create" such
a command. I do not agree with removing the handlers part; the code
will still want to handle EndRqs, error cases, and EndJob. Anyhow I see
it also mentions setting up a handler for SIGTERM to directly catch the
*CNTRLD end.
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/concept7.htm
Regards, Chuck
--
All comments provided "as is" with no warranties of any kind
whatsoever and may not represent positions, strategies, nor views of my
employer
This excerpt from
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/cl/endjob.htm
shows that you can define an ILE signal handler (at least in v5r4; I don't
know about earlier releases):
Specifies whether the job ends immediately or in a controlled manner that
lets the application program perform end-of-job processing. In either case,
the system performs certain job cleanup processing.
*CNTRLD: The job ends in a controlled manner. This allows the program
running to perform cleanup (end-of-job processing). When a job being ended
has a signal handling procedure for the asynchronous signal SIGTERM, the
SIGTERM signal is generated for that job. The application has the amount of
time specified on the DELAY parameter to complete cleanup before the job is
ended.
--
George Timms
IBM Rochester
If you decide to use some polling mechanism (such as calling RTVJOBA),
RPG has the %SHTDN builtin function (or SHTDN opcode) that returns '1'
if the job or subsystem is ending controlled.
if %shtdn();
--- do any necessary cleanup
return;
endif;
On Fri, 18 Jan 2008 14:49:41 -0600, Karl Hanson
<kcha...@youess.ibm.com> wrote:
>This would seem to enable a polling technique, whereby whenever control
>returns to the program from select(), the current job "end status" could
>be retrieved and checked. A couple ways to retrieve it: use RTVJOBA
>ENDSTS() in a CL program, or use the QUSRJOBI API.
>
>(Note that if using ILE, a CL ILE module could be created and bound with
>RPG in the same program, for better call/return performance.)
How about the %shtdn BIF (or the SHDTN opcode)?
--
Ken
Opinions expressed are my own and do not necessarily represent the views
of my employer or anyone in their right mind.
wow, lots of helpful people here. :-) Thank you all. :-)
The "listen for SIGTERM" technique seems to do exactly what I want.
The suggestion to implement a command that connects to the socket server
and issues a shutdown request is also well worth considering.
Best regards
Klaus