From ff954069da2e5bf5f9f5cc73752b71c6b92d6a85 Mon Sep 17 00:00:00 2001 From: Thomas Bonfort Date: Mon, 9 Apr 2012 06:02:09 +0200 Subject: [PATCH] re-enable fastcgi signal handling closes #4093 --- mapgd.c | 9 +++++++-- mapserv.c | 13 ++++++------- mapserver.h | 4 ++-- maputil.c | 4 ++-- shp2img.c | 14 +++++++------- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/mapgd.c b/mapgd.c index ec125f054c..3e5d1da461 100644 --- a/mapgd.c +++ b/mapgd.c @@ -51,9 +51,14 @@ int msGDSetup() { return MS_SUCCESS; } -void msGDCleanup() { +void msGDCleanup(int signal) { #ifdef USE_GD_FT - gdFontCacheShutdown(); + if(!signal) { + /* there's a potential deadlock if we're killed by a signal and the font + cache is already locked. We don't tear down the fontcache in this case + to avoid it (issue 4093)*/ + gdFontCacheShutdown(); + } #endif } diff --git a/mapserv.c b/mapserv.c index 3d9dd6def0..c72e46962d 100644 --- a/mapserv.c +++ b/mapserv.c @@ -44,7 +44,6 @@ MS_CVSID("$Id$") /************************************************************************/ /* FastCGI cleanup functions. */ /************************************************************************/ -static int exitSignal; #ifndef WIN32 void msCleanupOnSignal( int nInData ) { @@ -53,7 +52,8 @@ void msCleanupOnSignal( int nInData ) /* normal stdio functions. */ msIO_installHandlers( NULL, NULL, NULL ); msIO_fprintf( stderr, "In msCleanupOnSignal.\n" ); - exitSignal = 1; + msCleanup(1); + exit(0); } #endif @@ -70,7 +70,7 @@ void msCleanupOnExit( void ) fprintf( fp_out, "In msCleanupOnExit\n" ); fclose( fp_out ); #endif - msCleanup(); + msCleanup(1); } #endif @@ -83,13 +83,12 @@ int main(int argc, char *argv[]) { struct mstimeval execstarttime, execendtime; struct mstimeval requeststarttime, requestendtime; mapservObj* mapserv = NULL; - exitSignal = 0; msSetup(); /* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */ if( msDebugInitFromEnv() != MS_SUCCESS ) { msCGIWriteError(mapserv); - msCleanup(); + msCleanup(0); exit(0); } @@ -162,7 +161,7 @@ int main(int argc, char *argv[]) { /* In FastCGI case we loop accepting multiple requests. In normal CGI */ /* use we only accept and process one request. */ - while( !exitSignal && FCGI_Accept() >= 0 ) { + while( FCGI_Accept() >= 0 ) { #endif /* def USE_FASTCGI */ /* -------------------------------------------------------------------- */ @@ -229,6 +228,6 @@ int main(int argc, char *argv[]) { (execendtime.tv_sec+execendtime.tv_usec/1.0e6)- (execstarttime.tv_sec+execstarttime.tv_usec/1.0e6) ); } - msCleanup(); + msCleanup(0); exit( 0 ); } diff --git a/mapserver.h b/mapserver.h index 8a4eb19e1f..eb4d8dad7c 100644 --- a/mapserver.h +++ b/mapserver.h @@ -1731,7 +1731,7 @@ struct layerVTable { MS_DLL_EXPORT int msSaveImage(mapObj *map, imageObj *img, char *filename); MS_DLL_EXPORT void msFreeImage(imageObj *img); MS_DLL_EXPORT int msSetup(void); -MS_DLL_EXPORT void msCleanup(void); +MS_DLL_EXPORT void msCleanup(int signal); MS_DLL_EXPORT mapObj *msLoadMapFromString(char *buffer, char *new_mappath); /* Function prototypes, not wrapable */ @@ -2265,7 +2265,7 @@ MS_DLL_EXPORT imageObj *msImageCreateIM(int width, int height, outputFormatObj * MS_DLL_EXPORT imageObj *msImageLoadGD( const char *filename ); MS_DLL_EXPORT imageObj *msImageLoadGDCtx( gdIOCtx *ctx, const char *driver ); MS_DLL_EXPORT int msGDSetup(); -MS_DLL_EXPORT void msGDCleanup(); +MS_DLL_EXPORT void msGDCleanup(int signal); #endif MS_DLL_EXPORT void msImageStartLayerIM(mapObj *map, layerObj *layer, imageObj *image); MS_DLL_EXPORT int msSaveImageIM(imageObj* img, char *filename, outputFormatObj *format); diff --git a/maputil.c b/maputil.c index b2b62374dc..73722f927a 100644 --- a/maputil.c +++ b/maputil.c @@ -1881,7 +1881,7 @@ int msSetup() /* This is intended to be a function to cleanup anything that "hangs around" when all maps are destroyed, like Registered GDAL drivers, and so forth. */ -void msCleanup() +void msCleanup(int signal) { msForceTmpFileBase( NULL ); msConnPoolFinalCleanup(); @@ -1911,7 +1911,7 @@ void msCleanup() #endif #ifdef USE_GD - msGDCleanup(); + msGDCleanup(signal); #endif #ifdef USE_GEOS diff --git a/shp2img.c b/shp2img.c index 065e128068..066eccb6b0 100644 --- a/shp2img.c +++ b/shp2img.c @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) if ( msDebugInitFromEnv() != MS_SUCCESS ) { msWriteError(stderr); - msCleanup(); + msCleanup(0); exit(1); } @@ -129,7 +129,7 @@ int main(int argc, char *argv[]) map = msLoadMap(argv[i+1], NULL); if(!map) { msWriteError(stderr); - msCleanup(); + msCleanup(0); exit(1); } msApplyDefaultSubstitutions(map); @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) if(!map) { fprintf(stderr, "Mapfile (-m) option not specified.\n"); - msCleanup(); + msCleanup(0); exit(1); } @@ -243,7 +243,7 @@ int main(int argc, char *argv[]) if( argc <= i+4 ) { fprintf( stderr, "Argument -e needs 4 space separated numbers as argument.\n" ); - msCleanup(); + msCleanup(0); exit(1); } map->extent.minx = atof(argv[i+1]); @@ -271,7 +271,7 @@ int main(int argc, char *argv[]) } if (layer_found==0) { fprintf(stderr, "Layer (-l) \"%s\" not found\n", layers[j]); - msCleanup(); + msCleanup(0); exit(1); } } @@ -303,7 +303,7 @@ int main(int argc, char *argv[]) msWriteError(stderr); msFreeMap(map); - msCleanup(); + msCleanup(0); exit(1); } @@ -321,7 +321,7 @@ int main(int argc, char *argv[]) (requeststarttime.tv_sec+requeststarttime.tv_usec/1.0e6) ); } - msCleanup(); + msCleanup(0); } /* for(draws=0; draws