Re: PRO*C and signals

From: Magnus Lonnroth <mloennro_at_se.oracle.com>
Date: Wed, 3 Nov 1993 08:24:28 GMT
Message-ID: <MLOENNRO.93Nov3082429_at_demo1.se.oracle.com>


>>>>> "j" == joseph.m.miklewicz <jmjm_at_cbnewsm.cb.att.com> writes:

  j> Folks,

  j> I am running:

  j> SunOs 4.1.2
  j> Oracle 7.0.12
  j> PRO*C  1.5.6.2.1

  j> I am trying to write a daemon that uses the dbms_alert package to
  j> "distribute" database alerts to our various applications and/or kick off
  j> another "C" process when a database event occurs. The daemon uses the
  j> dbms_alert.register() procedure to register for the events its
  j> interested in an dbms_alert.remove() to unregister when it terminates.   j> It uses dbms_alert.waitany() to wait for the alerts.
  j> I have defined a "hangup" alert which is the event that tells the daemon
  j> to terminate. When I cause this alert the daemon unregisters all of the
  j> alerts and terminates with no problem. 

  j> Where I am having difficulty is when I try to terminate the daemon by
  j> issuing a kill of SIGTERM. This is the most likely way the daemon will
  j> be terminated since it will be started out of /etc/rc.local and will be   j> terminated by shutdown, which issues a SIGTERM.
  j> The code I execute to terminate is the same whether the daemon receives
  j> the "hangup" alert or the SIGTERM. The difference is that when I issue a
  j> SIGTERM a signal handler invokes the unregister function. What happens
  j> in this case is the first REMOVE() call hangs. What I suspect is that
  j> the SIGTERM I send my daemon is somehow affecting the shadow process as
  j> well. Are you allowed to do your own signal handling in PRO*C? I can't
  j> find any references to it in any of the OCI and/or pre-compiler
  j> documentation.

  j> Any info on this topic would be appreciated.

  j> Joe Miklewicz	908-949-3061	jmjm_at_hogpa.att.com
  j> -- 
  j> Joe Miklewicz	908-949-3061	jmjm_at_hogpa.att.com

You are correct in assuming that SIGTERM affects your shadow process. This is explained in one of the first chapters of the Installation and User's Guide for your operating system. At least it should be, I just failed to find it in the newest IUG's for Sun and HP...but it is in the generic Oracle for Unix manual (part no.6054-70-0492):

"..SIGTERM [is] used by the Pipe driver to signal interrupts from  the user side to the Oracle process. This occurs whenever the user  presses the interrupt key (ctrl-C). SIGTERM is not caught by the user  process; it is only caught by Oracle."

SIGCONT is also used by the Pipe driver.

You can add signal-handlers for SIGCLD, SIGPIPE and SIGINT by using the Oracle-provided functions:

int osnsui ( int *handle, void *astp, char *ctx ) int osncui ( int *handle )

osnsui() registers a signal-handler with Oracle, osncui() clears it. *atsp is your signal-handler and *ctx is a parameter passed to it. You may install as many signal-handlers as you like for other signals. These restrictions only apply when you are connected to Oracle, and only when using Pro*C (not OCI).

This is actually pretty tricky to diagnose, since your program will behave unpredictably if you do not register signal-handlers with Oracle. No Ora-errors or return-codes, weird SQLCA etc.

hope this helps,

Magnus Lonnroth
Oracle Sweden Received on Wed Nov 03 1993 - 09:24:28 CET

Original text of this message