Menu

#521 allow fine-grained signal handling setup with COB_SIGNAL_REGIME taking a list

GC 3.x
accepted
nobody
5 - default
5 days ago
5 days ago
No

COB_SIGNAL_REGIME was added by @oguzcankirmemis upon my request, integrated with [r5612] (side story: if using JNI from a thread running in parallel you need to ignore some, as the JVM partially uses signals internally to handle exceptions - and you don't want the COBOL runtime to catch those).

For example you could do the following if you want CTRL+C to be passed as ^C "input" instead of tearing down the runtime - at least on nearly all *nix envs:

trap "" 2
COB_SIGNAL_REGIME_1 ./EXITPROC  # will only ignore sigint

or, not suggested to do:

trap "" 2
COB_SIGNAL_REGIME_2 ./EXITPROC  # will ignore everything, most "hard errrors" will lead to a process end by the system

For the first option noted above: that can also be done in a non-COBOL wrapper (at least the GnuCOBOL side - you may still have to ignore the CTRL+C "outside", which was done by the trap above for the shell):

#include <signal.h>
#include <libcob.h>

signal (SIGINT, SIG_IGN);
cob_setenv ("COB_SIGNAL_REGIME","1");
cob_init();

Since this implementation we also have a TODO comment there:

TODO: consider per-signal value, so additional to the current one a list like 15=1, 2=0, 2 (= handle 15 if no other handler setup, always handle signal 2, don't do anything for other signals)

This would be a useful addition especially for ignoring single signals (so no external call of signal(...,SIG_IGN) is needed).

Related

Bugs: #1256
Commit: [r5612]

Discussion


Log in to post a comment.