From ae57f3cd467a742755baab7ea4f46463d16f8674 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 12 Jan 2018 19:52:31 +0000 Subject: [PATCH] Added ability to toggle on/off use of C system() function call, using OSG_SYSTEM_SUPPORTED Cmake option --- CMakeLists.txt | 1 + include/osg/os_utils | 18 +++++++++++++++++- src/osg/Config.in | 1 + src/osgPlugins/lua/lua-5.2.3/src/loslib.c | 6 ++++++ src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp | 5 +++-- src/osgPlugins/tgz/ReaderWriterTGZ.cpp | 5 +++-- src/osgPresentation/KeyEventHandler.cpp | 3 ++- src/osgPresentation/PickEventHandler.cpp | 3 ++- src/osgPresentation/SlideEventHandler.cpp | 5 +++-- src/osgPresentation/SlideShowConstructor.cpp | 3 ++- 10 files changed, 40 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 285725729..0cde1104e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -480,6 +480,7 @@ OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr< OPTION(OSG_USE_REF_PTR_SAFE_DEREFERENCE "Set to ON to throw an exception whenever ref_ptr<> is dereferenced or called. " OFF) OPTION(OSG_ENVVAR_SUPPORTED "Set to ON to build OpenSceneGraph with the OSG_ENVVAR_SUPPOERTED #define enabled to enable use of getenv() related functions." ON) +OPTION(OSG_SYSTEM_SUPPORTED "Set to ON to build OpenSceneGraph with the OSG_SYSTEM_SUPPOERTED #define enabled to enable use of system() related functions." ON) diff --git a/include/osg/os_utils b/include/osg/os_utils index 95ad47c3e..2caf78a9f 100644 --- a/include/osg/os_utils +++ b/include/osg/os_utils @@ -16,13 +16,29 @@ #include -#ifdef OSG_ENVVAR_SUPPORTED +#if defined(OSG_SYSTEM_SUPPORTED) || defined(OSG_ENVVAR_SUPPORTED) #include +#endif + +#ifdef OSG_ENVVAR_SUPPORTED #include #endif namespace osg { +#ifdef OSG_SYSTEM_SUPPORTED +inline int system(const char* command) +{ + return ::system(command); +} +#else +inline int system(const char* command) +{ + OSG_WARN<<"system("< /* ** list of valid conversion specifiers for the 'strftime' function @@ -78,6 +79,8 @@ static int os_execute (lua_State *L) { + +#if defined(OSG_SYSTEM_SUPPORTED) const char *cmd = luaL_optstring(L, 1, NULL); int stat = system(cmd); if (cmd != NULL) @@ -86,6 +89,9 @@ static int os_execute (lua_State *L) { lua_pushboolean(L, stat); /* true if there is a shell */ return 1; } +#else + return 0; +#endif } diff --git a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp index 372d3e61b..788875a22 100644 --- a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp +++ b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -77,7 +78,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter mkdir( dirname, 0700 ); #endif - if ( system( command ) ) { + if (osg::system( command ) ) { return ReadResult::FILE_NOT_HANDLED; } @@ -107,7 +108,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter sprintf( command, "rm -rf %s", dirname ); #endif - if ( system( command ) ) { + if (osg::system( command ) ) { return ReadResult::FILE_NOT_HANDLED; } diff --git a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp index 1b98333fe..d9345bd19 100644 --- a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp +++ b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -94,7 +95,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter OSG_NOTICE<<"Running command '"<getNumChildren() == 0 ) diff --git a/src/osgPresentation/KeyEventHandler.cpp b/src/osgPresentation/KeyEventHandler.cpp index f08fdc003..1b7e7dc6d 100644 --- a/src/osgPresentation/KeyEventHandler.cpp +++ b/src/osgPresentation/KeyEventHandler.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -119,7 +120,7 @@ void KeyEventHandler::doOperation() bool commandRunsInBackground = (_command.find("&")!=std::string::npos); - int result = system(_command.c_str()); + int result = osg::system(_command.c_str()); OSG_INFO<<"system("<<_command<<") result "< #include #include +#include #include @@ -230,7 +231,7 @@ void PickEventHandler::doOperation() bool commandRunsInBackground = (_command.find("&")!=std::string::npos); - int result = system(_command.c_str()); + int result = osg::system(_command.c_str()); OSG_INFO<<"system("<<_command<<") result "< #include #include +#include #include #include @@ -420,7 +421,7 @@ struct LayerAttributesOperator : public ObjectOperator OSG_NOTICE<<"Run "<c_str()<tick(); - int result = system(itr->c_str()); + int result = osg::system(itr->c_str()); OSG_INFO<<"system("<<*itr<<") result "< #include #include +#include #include #include @@ -1749,7 +1750,7 @@ void SlideShowConstructor::addGraph(const std::string& contents, const PositionD std::stringstream command; command<<"dot -Tsvg "< previousOptions = _options;