From 6bb41cb5f886b03c8b79af72d1fea807b7aac3c8 Mon Sep 17 00:00:00 2001 From: Sebastian Theophil Date: Thu, 19 Mar 2015 14:44:52 +0100 Subject: [PATCH 1/3] Use Mac Sandbox compatible temp folder --- .../interprocess/detail/shared_dir_helpers.hpp | 18 +++++++++++++----- lib/boost/interprocess/TempFile.mm | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) mode change 100644 => 100755 include/boost/interprocess/detail/shared_dir_helpers.hpp create mode 100644 lib/boost/interprocess/TempFile.mm diff --git a/include/boost/interprocess/detail/shared_dir_helpers.hpp b/include/boost/interprocess/detail/shared_dir_helpers.hpp old mode 100644 new mode 100755 index a0ac766f..f2229cd2 --- a/include/boost/interprocess/detail/shared_dir_helpers.hpp +++ b/include/boost/interprocess/detail/shared_dir_helpers.hpp @@ -102,13 +102,21 @@ namespace ipcdetail { #endif #endif //#if defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME) +#if defined(BOOST_INTERPROCESS_TEMP_DIR_FUNC) + void get_temp_dir(std::string& dir_path); +#else + inline void get_temp_dir(std::string& dir_path) { + #if defined (BOOST_INTERPROCESS_WINDOWS) + winapi::get_shared_documents_folder(dir_path); + #else + dir_path = "/tmp"; + #endif + } +#endif + inline void get_shared_dir_root(std::string &dir_path) { - #if defined (BOOST_INTERPROCESS_WINDOWS) - winapi::get_shared_documents_folder(dir_path); - #else - dir_path = "/tmp"; - #endif + get_temp_dir(dir_path); //We always need this path, so throw on error if(dir_path.empty()){ error_info err = system_error_code(); diff --git a/lib/boost/interprocess/TempFile.mm b/lib/boost/interprocess/TempFile.mm new file mode 100644 index 00000000..ae566767 --- /dev/null +++ b/lib/boost/interprocess/TempFile.mm @@ -0,0 +1,22 @@ +#import +#include + +namespace boost { + namespace interprocess { + namespace ipcdetail { + void get_temp_dir(std::string& strPath) { + @autoreleasepool { + // Files in NSTemporaryDirectory are automatically deleted after an unspecified time (apparently 3 days) + // This is ok if a process still holds a file handle to that file. The file system blocks are not + // freed until the handle is freed. + // But no other process can access this file via the file name. + // http://www.cocoawithlove.com/2009/07/temporary-files-and-folders-in-cocoa.html + NSArray *astrPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + if(0<[astrPaths count]) { + strPath.assign([[astrPaths objectAtIndex:0] UTF8String]); + } + } + } + } + } +} \ No newline at end of file From 5ab7370b53400c2b38b2dac8df5d932dbfd0e126 Mon Sep 17 00:00:00 2001 From: Sebastian Theophil Date: Mon, 19 Sep 2016 16:51:49 +0200 Subject: [PATCH 2/3] Remove TempFile.mm --- lib/boost/interprocess/TempFile.mm | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 lib/boost/interprocess/TempFile.mm diff --git a/lib/boost/interprocess/TempFile.mm b/lib/boost/interprocess/TempFile.mm deleted file mode 100644 index ae566767..00000000 --- a/lib/boost/interprocess/TempFile.mm +++ /dev/null @@ -1,22 +0,0 @@ -#import -#include - -namespace boost { - namespace interprocess { - namespace ipcdetail { - void get_temp_dir(std::string& strPath) { - @autoreleasepool { - // Files in NSTemporaryDirectory are automatically deleted after an unspecified time (apparently 3 days) - // This is ok if a process still holds a file handle to that file. The file system blocks are not - // freed until the handle is freed. - // But no other process can access this file via the file name. - // http://www.cocoawithlove.com/2009/07/temporary-files-and-folders-in-cocoa.html - NSArray *astrPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); - if(0<[astrPaths count]) { - strPath.assign([[astrPaths objectAtIndex:0] UTF8String]); - } - } - } - } - } -} \ No newline at end of file From 6956f113925ff817d8db4f11447d6f298898d9a5 Mon Sep 17 00:00:00 2001 From: Sebastian Theophil Date: Thu, 22 Sep 2016 11:59:29 +0200 Subject: [PATCH 3/3] Replaced BOOST_INTERPROCESS_TEMP_DIR_FUNC with BOOST_INTERPROCESS_SHARED_DIR_FUNC - BOOST_INTERPROCESS_SHARED_DIR_FUNC has the same semantics as BOOST_INTERPROCESS_SHARED_DIR_PATH and can be used as the more flexible alternative - Added documentation --- doc/interprocess.qbk | 38 +++++++++++++++++----- .../interprocess/detail/shared_dir_helpers.hpp | 37 ++++++++++++--------- 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/doc/interprocess.qbk b/doc/interprocess.qbk index 8362132d..d4072d3b 100644 --- a/doc/interprocess.qbk +++ b/doc/interprocess.qbk @@ -6626,7 +6626,7 @@ want [*Boost.Interprocess] to initialize the COM library with another model, def [section:notes_windows_shm_folder Shared memory emulation folder] -Shared memory (`shared_memory_object`) is implemented in windows using memory mapped files, placed in a +Shared memory (`shared_memory_object`) is implemented in Windows using memory mapped files, placed in a shared directory in the shared documents folder (`SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Common AppData`). This directory name is the last bootup time obtained via COM calls (if `BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTUPTIME`) defined or searching the system log for a startup event (the default implementation), so that each bootup shared memory is created in a new @@ -6643,8 +6643,19 @@ If using the default implementation, (`BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTU found, this might be due to some buggy software that floods or erases the event log. In any error case (shared documents folder is not defined or bootup time could not be obtained, the library throws an error. You still -can use [*Boost.Interprocess] definining your own directory as the shared directory. Just define `BOOST_INTERPROCESS_SHARED_DIR_PATH` -when using the library and that path will be used to place shared memory files. +can use [*Boost.Interprocess] definining your own directory as the shared directory. When your shared directory is a compile-time constant, +define `BOOST_INTERPROCESS_SHARED_DIR_PATH` when using the library and that path will be used to place shared memory files. When you have +to determine the shared directory at runtime, define `BOOST_INTERPROCESS_SHARED_DIR_FUNC` and implement the function + +[c++] + + namespace boost { + namespace interprocess { + namespace ipcdetail { + void get_shared_dir(std::string &shared_dir); + } + } + } [endsect] @@ -6662,11 +6673,22 @@ those heavy headers. [section:notes_linux_shm_folder Shared memory emulation folder] -On systems without POSIX shared memory support shared memory objects are implemented as memory mapped files, using a directory -placed in "/tmp" that can include (if `BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME` is defined) the last bootup time (if the Os supports it). -As in Windows, in any error case obtaining this directory the library throws an error . You still can use -[*Boost.Interprocess] definining your own directory as the shared directory. Just define `BOOST_INTERPROCESS_SHARED_DIR_PATH` -when using the library and that path will be used to place shared memory files. +On systems without POSIX shared memory support, shared memory objects are implemented as memory mapped files, using a directory +placed in "/tmp" that can include (if `BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME` is defined) the last bootup time (if the OS supports it). +As in Windows, in any error case obtaining this directory the library throws an error . When your shared directory is a compile-time constant, +define `BOOST_INTERPROCESS_SHARED_DIR_PATH` when using the library and that path will be used to place shared memory files. When you have +to determine the shared directory at runtime, define `BOOST_INTERPROCESS_SHARED_DIR_FUNC` and implement the function + +[c++] + + namespace boost { + namespace interprocess { + namespace ipcdetail { + void get_shared_dir(std::string &shared_dir); + } + } + } + [endsect] diff --git a/include/boost/interprocess/detail/shared_dir_helpers.hpp b/include/boost/interprocess/detail/shared_dir_helpers.hpp index f2229cd2..bfce9fe0 100755 --- a/include/boost/interprocess/detail/shared_dir_helpers.hpp +++ b/include/boost/interprocess/detail/shared_dir_helpers.hpp @@ -102,21 +102,14 @@ namespace ipcdetail { #endif #endif //#if defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME) -#if defined(BOOST_INTERPROCESS_TEMP_DIR_FUNC) - void get_temp_dir(std::string& dir_path); -#else - inline void get_temp_dir(std::string& dir_path) { - #if defined (BOOST_INTERPROCESS_WINDOWS) - winapi::get_shared_documents_folder(dir_path); - #else - dir_path = "/tmp"; - #endif - } -#endif - inline void get_shared_dir_root(std::string &dir_path) { - get_temp_dir(dir_path); + #if defined (BOOST_INTERPROCESS_WINDOWS) + winapi::get_shared_documents_folder(dir_path); + #else + dir_path = "/tmp"; + #endif + //We always need this path, so throw on error if(dir_path.empty()){ error_info err = system_error_code(); @@ -126,11 +119,22 @@ inline void get_shared_dir_root(std::string &dir_path) dir_path += "/boost_interprocess"; } +#ifdef BOOST_INTERPROCESS_SHARED_DIR_FUNC +namespace boost { + namespace interprocess { + namespace ipcdetail { + // When BOOST_INTERPROCESS_SHARED_DIR_FUNC is defined, users have to implement + // get_shared_dir + void get_shared_dir(std::string &shared_dir); + } + } +} +#else inline void get_shared_dir(std::string &shared_dir) { #if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) shared_dir = BOOST_INTERPROCESS_SHARED_DIR_PATH; - #else + #else get_shared_dir_root(shared_dir); #if defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME) shared_dir += "/"; @@ -138,6 +142,7 @@ inline void get_shared_dir(std::string &shared_dir) #endif #endif } +#endif inline void shared_filepath(const char *filename, std::string &filepath) { @@ -148,8 +153,8 @@ inline void shared_filepath(const char *filename, std::string &filepath) inline void create_shared_dir_and_clean_old(std::string &shared_dir) { - #if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) - shared_dir = BOOST_INTERPROCESS_SHARED_DIR_PATH; + #if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) || defined(BOOST_INTERPROCESS_SHARED_DIR_FUNC) + get_shared_dir(shared_dir); #else //First get the temp directory std::string root_shared_dir;