77 * Portions Copyright (c) 1994, Regents of the University of California
88 *
99 * IDENTIFICATION
10- * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.148 2009/07/21 20:24:51 petere Exp $
10+ * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.149 2009/07/31 20:26:22 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
3535 * If the listenerPID in a matching tuple is ours, we just send a notify
3636 * message to our own front end. If it is not ours, and "notification"
3737 * is not already nonzero, we set notification to our own PID and send a
38- * SIGUSR2 signal to the receiving process (indicated by listenerPID).
38+ * PROCSIG_NOTIFY_INTERRUPT signal to the receiving process (indicated by
39+ * listenerPID).
3940 * BTW: if the signal operation fails, we presume that the listener backend
4041 * crashed without removing this tuple, and remove the tuple for it.
4142 *
42- * 4. Upon receipt of a SIGUSR2 signal, the signal handler can call inbound-
43- * notify processing immediately if this backend is idle (ie, it is
44- * waiting for a frontend command and is not within a transaction block).
45- * Otherwise the handler may only set a flag, which will cause the
43+ * 4. Upon receipt of a PROCSIG_NOTIFY_INTERRUPT signal, the signal handler
44+ * can call inbound- notify processing immediately if this backend is idle
45+ * (ie, it is waiting for a frontend command and is not within a transaction
46+ * block). Otherwise the handler may only set a flag, which will cause the
4647 * processing to occur just before we next go idle.
4748 *
4849 * 5. Inbound-notify processing consists of scanning pg_listener for tuples
9596#include "libpq/pqformat.h"
9697#include "miscadmin.h"
9798#include "storage/ipc.h"
99+ #include "storage/procsignal.h"
98100#include "storage/sinval.h"
99101#include "tcop/tcopprot.h"
100102#include "utils/builtins.h"
@@ -634,12 +636,17 @@ Send_Notify(Relation lRel)
634636
635637 /*
636638 * If someone has already notified this listener, we don't bother
637- * modifying the table, but we do still send a SIGUSR2 signal,
638- * just in case that backend missed the earlier signal for some
639- * reason. It's OK to send the signal first, because the other
640- * guy can't read pg_listener until we unlock it.
639+ * modifying the table, but we do still send a NOTIFY_INTERRUPT
640+ * signal, just in case that backend missed the earlier signal for
641+ * some reason. It's OK to send the signal first, because the
642+ * other guy can't read pg_listener until we unlock it.
643+ *
644+ * Note: we don't have the other guy's BackendId available, so
645+ * this will incur a search of the ProcSignal table. That's
646+ * probably not worth worrying about.
641647 */
642- if (kill (listenerPID , SIGUSR2 ) < 0 )
648+ if (SendProcSignal (listenerPID , PROCSIG_NOTIFY_INTERRUPT ,
649+ InvalidBackendId ) < 0 )
643650 {
644651 /*
645652 * Get rid of pg_listener entry if it refers to a PID that no
@@ -777,24 +784,22 @@ AtSubAbort_Notify(void)
777784}
778785
779786/*
780- * NotifyInterruptHandler
787+ * HandleNotifyInterrupt
781788 *
782- * This is the signal handler for SIGUSR2 .
789+ * This is called when PROCSIG_NOTIFY_INTERRUPT is received .
783790 *
784791 * If we are idle (notifyInterruptEnabled is set), we can safely invoke
785792 * ProcessIncomingNotify directly. Otherwise, just set a flag
786793 * to do it later.
787794 */
788795void
789- NotifyInterruptHandler ( SIGNAL_ARGS )
796+ HandleNotifyInterrupt ( void )
790797{
791- int save_errno = errno ;
792-
793798 /*
794- * Note: this is a SIGNAL HANDLER. You must be very wary what you do
795- * here. Some helpful soul had this routine sprinkled with TPRINTFs, which
796- * would likely lead to corruption of stdio buffers if they were ever
797- * turned on.
799+ * Note: this is called by a SIGNAL HANDLER. You must be very wary what
800+ * you do here. Some helpful soul had this routine sprinkled with
801+ * TPRINTFs, which would likely lead to corruption of stdio buffers if
802+ * they were ever turned on.
798803 */
799804
800805 /* Don't joggle the elbow of proc_exit */
@@ -815,7 +820,7 @@ NotifyInterruptHandler(SIGNAL_ARGS)
815820
816821 /*
817822 * I'm not sure whether some flavors of Unix might allow another
818- * SIGUSR2 occurrence to recursively interrupt this routine. To cope
823+ * SIGUSR1 occurrence to recursively interrupt this routine. To cope
819824 * with the possibility, we do the same sort of dance that
820825 * EnableNotifyInterrupt must do --- see that routine for comments.
821826 */
@@ -831,12 +836,12 @@ NotifyInterruptHandler(SIGNAL_ARGS)
831836 {
832837 /* Here, it is finally safe to do stuff. */
833838 if (Trace_notify )
834- elog (DEBUG1 , "NotifyInterruptHandler : perform async notify" );
839+ elog (DEBUG1 , "HandleNotifyInterrupt : perform async notify" );
835840
836841 ProcessIncomingNotify ();
837842
838843 if (Trace_notify )
839- elog (DEBUG1 , "NotifyInterruptHandler : done" );
844+ elog (DEBUG1 , "HandleNotifyInterrupt : done" );
840845 }
841846 }
842847
@@ -854,8 +859,6 @@ NotifyInterruptHandler(SIGNAL_ARGS)
854859 */
855860 notifyInterruptOccurred = 1 ;
856861 }
857-
858- errno = save_errno ;
859862}
860863
861864/*
@@ -922,8 +925,8 @@ EnableNotifyInterrupt(void)
922925 * a frontend command. Signal handler execution of inbound notifies
923926 * is disabled until the next EnableNotifyInterrupt call.
924927 *
925- * The SIGUSR1 signal handler also needs to call this, so as to
926- * prevent conflicts if one signal interrupts the other. So we
928+ * The PROCSIG_CATCHUP_INTERRUPT signal handler also needs to call this,
929+ * so as to prevent conflicts if one signal interrupts the other. So we
927930 * must return the previous state of the flag.
928931 */
929932bool
@@ -940,8 +943,8 @@ DisableNotifyInterrupt(void)
940943 * ProcessIncomingNotify
941944 *
942945 * Deal with arriving NOTIFYs from other backends.
943- * This is called either directly from the SIGUSR2 signal handler,
944- * or the next time control reaches the outer idle loop.
946+ * This is called either directly from the PROCSIG_NOTIFY_INTERRUPT
947+ * signal handler, or the next time control reaches the outer idle loop.
945948 * Scan pg_listener for arriving notifies, report them to my front end,
946949 * and clear the notification field in pg_listener until next time.
947950 *
@@ -961,7 +964,7 @@ ProcessIncomingNotify(void)
961964 nulls [Natts_pg_listener ];
962965 bool catchup_enabled ;
963966
964- /* Must prevent SIGUSR1 interrupt while I am running */
967+ /* Must prevent catchup interrupt while I am running */
965968 catchup_enabled = DisableCatchupInterrupt ();
966969
967970 if (Trace_notify )
0 commit comments