]> granicus.if.org Git - icinga2/commitdiff
Improve error handling for unlinking files
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 9 Nov 2015 12:35:51 +0000 (13:35 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 9 Nov 2015 12:35:51 +0000 (13:35 +0100)
refs #10578

lib/remote/configobjectutility.cpp

index 91b525aa6b5a26308c1a5c708bf7bc0de38a2c0c..91de62c5f4d0fd446d5f54f18fe3c8be65db7113 100644 (file)
@@ -113,7 +113,12 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
 
                if (!ConfigItem::CommitItems(upq) || !ConfigItem::ActivateItems(upq, false, true)) {
                        if (errors) {
-                               unlink(path.CStr());
+                               if (unlink(path.CStr()) < 0) {
+                                       BOOST_THROW_EXCEPTION(posix_error()
+                                           << boost::errinfo_api_function("unlink")
+                                           << boost::errinfo_errno(errno)
+                                           << boost::errinfo_file_name(path));
+                               }
 
                                BOOST_FOREACH(const boost::exception_ptr& ex, upq.GetExceptions()) {
                                        errors->Add(DiagnosticInformation(ex));
@@ -125,7 +130,12 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
        } catch (const std::exception& ex) {
                delete expr;
 
-               unlink(path.CStr());
+               if (unlink(path.CStr()) < 0) {
+                       BOOST_THROW_EXCEPTION(posix_error()
+                           << boost::errinfo_api_function("unlink")
+                           << boost::errinfo_errno(errno)
+                           << boost::errinfo_file_name(path));
+               }
 
                if (errors)
                        errors->Add(DiagnosticInformation(ex));