Skip to content

Commit

Permalink
Merge pull request #42 from flightaware/pg_listen_payload
Browse files Browse the repository at this point in the history
pg_listen not passing payload to notifier
  • Loading branch information
resuna authored Feb 9, 2022
2 parents 6e0e153 + af54a6a commit b2c40ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/mac-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
brew install tcl-tk || true
sudo mkdir -p /usr/local
sudo ln -sf /usr/local/opt/tcl-tk/include /usr/local/include/tcl8.6
sudo rm -f /usr/local/lib/libtcl* || true
sudo cp /usr/local/opt/tcl-tk/lib/libtcl* /usr/local/lib
sudo ln -sf /usr/local/opt/tcl-tk/bin/tclsh8.6 /usr/local/bin/tclsh
sudo ln -sf /usr/local/opt/tcl-tk/bin/tclsh8.6 /usr/local/bin/tclsh8.6
Expand Down
27 changes: 19 additions & 8 deletions generic/pgtclId.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,6 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags)
NotifyEvent *event = (NotifyEvent *) evPtr;
Pg_TclNotifies *notifies;
char *callback;
char *svcallback;

/* We classify SQL notifies as Tcl file events. */
if (!(flags & TCL_FILE_EVENTS))
Expand Down Expand Up @@ -1199,18 +1198,30 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags)
if (callback == NULL)
continue; /* nothing to do for this interpreter */

/*
* We have to copy the callback string in case the user executes a
* new pg_listen or pg_on_connection_loss during the callback.
/* Create a Tcl List Object containing the callback with the channel name
* (relname) and the PID of the notifying backend. This will also copy the callback
* string in case the user executes a new pg_listen or pg_on_connection_loss
* during the callback
*/
svcallback = (char *)ckalloc((unsigned)(strlen(callback) + 1));
strcpy(svcallback, callback);
Tcl_Obj *callbackList = Tcl_NewListObj(0, NULL);
Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewStringObj(callback, -1));
if (event->notify) {
Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewStringObj(event->notify->relname, -1));
Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewIntObj(event->notify->be_pid));
/* In case there is a payload, add it to the callback as a
* further element to the list.
*/
if (event->notify->extra[0]) {
Tcl_ListObjAppendElement (NULL, callbackList, Tcl_NewStringObj(event->notify->extra, -1));
}
}

/*
* Execute the callback.
*/
Tcl_IncrRefCount(callbackList);
Tcl_Preserve((ClientData)interp);
if (Tcl_GlobalEval(interp, svcallback) != TCL_OK)
if (Tcl_EvalObjEx(interp, callbackList, TCL_EVAL_GLOBAL) != TCL_OK)
{
if (event->notify)
Tcl_AddErrorInfo(interp, "\n (\"pg_listen\" script)");
Expand All @@ -1219,7 +1230,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags)
Tcl_BackgroundError(interp);
}
Tcl_Release((ClientData)interp);
ckfree(svcallback);
Tcl_DecrRefCount(callbackList);

/*
* Check for the possibility that the callback closed the
Expand Down

0 comments on commit b2c40ed

Please sign in to comment.