From 3d174b45a2d9809edb674971c3b620ded2d28d50 Mon Sep 17 00:00:00 2001 From: Thomas Bonfort Date: Fri, 31 Jan 2014 12:29:45 +0100 Subject: [PATCH] Switch off ogr-output streaming mode for non default io contexts (#4858) --- mapio.c | 17 +++++++++++++++++ mapio.h | 1 + mapogroutput.c | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/mapio.c b/mapio.c index 08612139a0..6373eff577 100644 --- a/mapio.c +++ b/mapio.c @@ -145,6 +145,23 @@ static msIOContextGroup *msIO_GetContextGroup() return group; } +/* returns MS_TRUE if the msIO standard output hasn't been redirected */ +int msIO_isStdContext() { + msIOContextGroup *group = io_context_list; + int nThreadId = msGetThreadId(); + if(!group || group->thread_id != nThreadId) { + group = msIO_GetContextGroup(); + if(!group) { + return MS_FALSE; /* probably a bug */ + } + } + if(group->stderr_context.cbData == (void*)stderr && + group->stdin_context.cbData == (void*)stdin && + group->stdout_context.cbData == (void*)stdout) + return MS_TRUE; + return MS_FALSE; +} + /************************************************************************/ /* msIO_getHandler() */ /************************************************************************/ diff --git a/mapio.h b/mapio.h index b5faef2a44..b6fe1376ee 100644 --- a/mapio.h +++ b/mapio.h @@ -108,6 +108,7 @@ extern "C" { void MS_DLL_EXPORT msIO_Cleanup(void); char MS_DLL_EXPORT *msIO_stripStdoutBufferContentType(void); void MS_DLL_EXPORT msIO_stripStdoutBufferContentHeaders(void); + int MS_DLL_EXPORT msIO_isStdContext(void); /* this is just for setting normal stdout's to binary mode on windows */ diff --git a/mapogroutput.c b/mapogroutput.c index a0949d9d4b..2e161942cb 100644 --- a/mapogroutput.c +++ b/mapogroutput.c @@ -536,6 +536,12 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders ) /* Determine the output datasource name to use. */ /* ==================================================================== */ storage = msGetOutputFormatOption( format, "STORAGE", "filesystem" ); + if( EQUAL(storage,"stream") && !msIO_isStdContext() ) { + /* bug #4858, streaming output won't work if standard output has been + * redirected, we switch to memory output in this case + */ + storage = "memory"; + } /* -------------------------------------------------------------------- */ /* Where are we putting stuff? */