2e15b699069d147795f3b4bcdf50aa9d099be9ff
max
  Thu Mar 6 02:31:47 2014 -0800
moving the phoneHome business into cgiApoptosis.c/.h to make it callablefrom cart.c. We need to call it from cart.c as otherwise
cgiApoptosisSetup (originally: phoneHome) will be called after mysql
connections are opened. This leads to "mysql server has gone away" if
any CGI is not faster than the child process forked here. The child will
close all mysql connections of the parent process. With the new setup,
the childi is forked before any mysql connections are opened. Ideally
this would be all done in cheapcgi, but cheapcgi is not in the hg/lib
part of the code.

diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index db83953..2fd1c6d 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -13,30 +13,31 @@
 #include "web.h"
 #include "hdb.h"
 #include "jksql.h"
 #include "jsHelper.h"
 #include "trashDir.h"
 #ifndef GBROWSE
 #include "customFactory.h"
 #include "googleAnalytics.h"
 #include "wikiLink.h"
 #endif /* GBROWSE */
 #include "hgMaf.h"
 #include "hui.h"
 #include "geoMirror.h"
 #include "hubConnect.h"
 #include "trackHub.h"
+#include "cgiApoptosis.h"
 
 static char *sessionVar = "hgsid";	/* Name of cgi variable session is stored in. */
 static char *positionCgiName = "position";
 
 DbConnector cartDefaultConnector = hConnectCart;
 DbDisconnect cartDefaultDisconnector = hDisconnectCart;
 
 static void hashUpdateDynamicVal(struct hash *hash, char *name, void *val)
 /* Val is a dynamically allocated (freeMem-able) entity to put
  * in hash.  Override existing hash item with that name if any.
  * Otherwise make new hash item. */
 {
 struct hashEl *hel = hashLookup(hash, name);
 if (hel == NULL)
     hashAdd(hash, name, val);
@@ -1617,30 +1618,31 @@
 setThemeFromCart(cart);
 htmStartWithHead(stdout, head, titlePlus);
 cartWarnCatcher(doMiddle, cart, htmlVaWarn);
 cartCheckout(&cart);
 cartFooter();
 }
 
 void cartEmptyShell(void (*doMiddle)(struct cart *cart), char *cookieName,
                     char **exclude, struct hash *oldVars)
 /* Get cart and cookies and set up error handling, but don't start writing any
  * html yet. The doMiddleFunction has to call cartHtmlStart(title), and
  * cartHtmlEnd(), as well as writing the body of the HTML.
  * oldVars - those in cart that are overlayed by cgi-vars are
  * put in optional hash oldVars. */
 {
+cgiApoptosisSetup();
 struct cart *cart = cartAndCookie(cookieName, exclude, oldVars);
 setThemeFromCart(cart);
 cartWarnCatcher(doMiddle, cart, cartEarlyWarningHandler);
 cartCheckout(&cart);
 }
 
 void cartHtmlShell(char *title, void (*doMiddle)(struct cart *cart),
                    char *cookieName, char **exclude, struct hash *oldVars)
 /* Load cart from cookie and session cgi variable.  Write web-page
  * preamble, call doMiddle with cart, and write end of web-page.
  * Exclude may be NULL.  If it exists it's a comma-separated list of
  * variables that you don't want to save in the cart between
  * invocations of the cgi-script. */
 {
 cartHtmlShellWithHead("", title, doMiddle, cookieName, exclude, oldVars);