6696987406845625c252a13b690e0c4d7d9e59fa
max
Thu Mar 26 06:48:48 2015 -0700
This is a go at libifing the CGI startup code. For all CGIs, we need to
call a few basic setup funtions, like UDC config and CGI apoptosis.
(For most CGIs also bottleneck). Instead of adding it to all of our
30+ CGIs, I changed the cart*Shell functions. I think most CGIs call
at least one of these functions. This commit removes the existing
copy/pasted code from a few CGIs and replaces it with one call.
Adding this to the cart-setup means that (like before), UDC is
setup even for small JSON calls and a process is spawned to watch
the CGI and kill it ("Apoptosis"). Any comments on whether this should
be implemented differently are appreciated. I have not added bottleneck
to this function right now as apparently we're calling bottleneck only
from some of our CGIs.
diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index 7fece59..dcb3f0d 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -1516,37 +1516,41 @@
char *hgsid = getSessionId();
struct cart *cart = cartNew(hguid, hgsid, exclude, oldVars);
cartExclude(cart, sessionVar);
if (sameOk(cfgOption("signalsHandler"), "on")) /* most cgis call this routine */
initSigHandlers(hDumpStackEnabled());
char *httpProxy = cfgOption("httpProxy"); /* most cgis call this routine */
if (httpProxy)
setenv("http_proxy", httpProxy, TRUE); /* net.c cannot see the cart, pass the value through env var */
return cart;
}
struct cart *cartAndCookieWithHtml(char *cookieName, char **exclude,
struct hash *oldVars, boolean doContentType)
/* Load cart from cookie and session cgi variable. Write cookie
* and optionally content-type part HTTP preamble to web page. Don't
- * write any HTML though. */
+ * write any HTML though.
+ * Also does common cgi setup, like UDC config and cgi apoptosis */
{
if (doContentType)
htmlPushEarlyHandlers();
else
pushWarnHandler(cartEarlyWarningHandler);
struct cart *cart = cartForSession(cookieName, exclude, oldVars);
+
+hCgiStartSetup(cart);
+
popWarnHandler();
cartWriteCookie(cart, cookieName);
if (doContentType)
{
puts("Content-Type:text/html");
puts("\n");
}
return cart;
}
struct cart *cartAndCookie(char *cookieName, char **exclude,
struct hash *oldVars)
/* Load cart from cookie and session cgi variable. Write cookie and
* content-type part HTTP preamble to web page. Don't write any HTML though. */
{
@@ -1707,38 +1711,43 @@
char * link = webTimeStampedLinkToResourceOnFirstCall(styleFile, TRUE); // resource file link wrapped in html
if (link != NULL)
{
htmlSetStyleTheme(link); // for htmshell.c, used by hgTracks
webSetStyle(link); // for web.c, used by hgc
}
}
}
void cartHtmlShellWithHead(char *head, 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 including head and title, 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. */
+ * invocations of the cgi-script.
+ * Also does common cgi setup, like UDC config and cgi apoptosis
+ * */
{
struct cart *cart;
char *db, *org, *pos, *clade=NULL;
char titlePlus[128];
char extra[128];
pushWarnHandler(cartEarlyWarningHandler);
cart = cartAndCookie(cookieName, exclude, oldVars);
+
+hCgiStartSetup(cart);
+
getDbAndGenome(cart, &db, &org, oldVars);
clade = hClade(org);
pos = cartOptionalString(cart, positionCgiName);
pos = addCommasToPos(db, stripCommas(pos));
if(pos != NULL && oldVars != NULL)
{
struct hashEl *oldpos = hashLookup(oldVars, positionCgiName);
if(oldpos != NULL && differentString(pos,oldpos->val))
cartSetString(cart,"lastPosition",oldpos->val);
}
*extra = 0;
if (pos == NULL && org != NULL)
safef(titlePlus,sizeof(titlePlus), "%s%s - %s",trackHubSkipHubName(org), extra, title );
else if (pos != NULL && org == NULL)
safef(titlePlus,sizeof(titlePlus), "%s - %s",pos, title );