configmgr/source/components.cxx | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-)
New commits: commit 8cdf186fac523959d011d76dc0ae8083cc266614 Author: Stephan Bergmann <[email protected]> AuthorDate: Wed Jul 24 14:04:07 2024 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Wed Jul 24 22:15:30 2024 +0200 Remove bExitWasCalled-handling from confgimgr::Components dtor That code had been added with 9fa4eff9be5e440099517a522a83e20debaf2955 "profilesafe: Enhancements to BackupFileHelper", but it looks dubious: For one, I cannot find proof for the claim that MSVC would run destructors of static objects upon _exit. Building a simple C++ test program > #include <iostream> > #include <stdlib.h> > struct S { ~S() { std::cerr << "hello "; } }; > S s; > void f() { _exit(1); } > int main() { f(); } with contemporary MSVC 17.10 and executing it shows no "hello" stderr output (see <https://gcc.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:13,endLineNumber:5,positionColumn:13,positionLineNumber:5,selectionStartColumn:13,selectionStartLineNumber:5,startColumn:13,startLineNumber:5),source:'%23include+%3Ciostream%3E%0A%23include+%3Cstdlib.h%3E%0Astruct+S+%7B+~S()+%7B+std::cerr+%3C%3C+%22hello%5Cn%22%3B+%7D+%7D%3B%0AS+s%3B%0Avoid+f()+%7B+_exit(1)%3B+%7D%0Aint+main()+%7B+f()%3B+%7D%0A'),l:'5',n:'1',o:'C%2B%2B+source+%231',t:'0')),k:32.19670284753087,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:vcpp_v19_40_VS17_10_x64,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'0',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStart Column:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x64+msvc+v19.40+VS17.10+(Editor+%231)',t:'0'),(h:output,i:(compilerName:'x86-64+clang+18.1.0',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x64+msvc+v19.40+VS17.10+(Compiler+%231)',t:'0')),k:67.80329715246913,l:'4',m:100.00000000000001,n:'0',o:'',s:1,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4>). If there indeed were issues with MSVC and non-standard _exit, a solution might be to use standard _Exit instead (in FatalError in desktop/source/app/app.cxx). And for another, when bExitWasCalled was true in configmgr::Components::~Components, it would still have called writeThread_->join() (i.e., it would potentially still have called writeModFile from within configmgr::Components::WriteThread::execute()), but (a) only after waiting out its full > delay_.wait(std::chrono::seconds(1)); (because it missed to call configmgr::Components::WriteThread::flush, which calls delay_.set()), and (b) potentially running into a deadlock because it called writeThread_->join() with *lock_ locked, which configmgr::Components::WriteThread::execute wants to lock too. (I came across this because it got into my way when trying to adapt the lifecycle of configmgr::Components::WriteThread to the needs of the Emscripten build.) Change-Id: Icb4ebf00d1d316b80c29f7bd91b86614ef4ac430 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170940 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index 8afaaff3bae8..d2b709e9c337 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -51,7 +51,6 @@ #include <sal/types.h> #include <salhelper/thread.hxx> #include <comphelper/diagnose_ex.hxx> -#include <comphelper/backupfilehelper.hxx> #include <o3tl/string_view.hxx> #include "additions.hxx" @@ -607,34 +606,7 @@ Components::Components( Components::~Components() { - // get flag if _exit was already called which is a sign to not secure user config. - // this is used for win only currently where calling _exit() unfortunately still - // calls destructors (what is not wanted). May be needed for other systems, too - // (unknown yet) but can do no harm - const bool bExitWasCalled(comphelper::BackupFileHelper::getExitWasCalled()); - -#ifndef _WIN32 - // we can add a SAL_WARN here for other systems where the destructor gets called after - // an _exit() call. Still safe - the getExitWasCalled() is used, but a hint that _exit - // behaves different on a system - SAL_WARN_IF(bExitWasCalled, "configmgr", "Components::~Components() called after _exit() call"); -#endif - - if (bExitWasCalled) - { - // do not write, re-join threads - osl::MutexGuard g(*lock_); - - if (writeThread_.is()) - { - writeThread_->join(); - } - } - else - { - // write changes - flushModifications(); - } + flushModifications(); for (auto const& rootElem : roots_) {
