]> granicus.if.org Git - icinga2/commitdiff
Fix crash when deleting config files fails
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 5 Oct 2016 12:17:26 +0000 (14:17 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 5 Oct 2016 12:17:26 +0000 (14:17 +0200)
fixes #12860

lib/remote/configobjectutility.cpp

index f14b6809655d87796eb02c939ad9b50b0b653ddc..f6ae2ccfa3ab41a7cbb4abc2262c326f0090c21a 100644 (file)
@@ -136,7 +136,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
 
                if (!ConfigItem::CommitItems(ascope.GetContext(), upq, newItems) || !ConfigItem::ActivateItems(upq, newItems, true)) {
                        if (errors) {
-                               if (unlink(path.CStr()) < 0) {
+                               if (unlink(path.CStr()) < 0 && errno != ENOENT) {
                                        BOOST_THROW_EXCEPTION(posix_error()
                                            << boost::errinfo_api_function("unlink")
                                            << boost::errinfo_errno(errno)
@@ -155,7 +155,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
        } catch (const std::exception& ex) {
                delete expr;
 
-               if (unlink(path.CStr()) < 0) {
+               if (unlink(path.CStr()) < 0 && errno != ENOENT) {
                        BOOST_THROW_EXCEPTION(posix_error()
                            << boost::errinfo_api_function("unlink")
                            << boost::errinfo_errno(errno)
@@ -217,7 +217,7 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo
        String path = GetObjectConfigPath(object->GetReflectionType(), object->GetName());
 
        if (Utility::PathExists(path)) {
-               if (unlink(path.CStr()) < 0) {
+               if (unlink(path.CStr()) < 0 && errno != ENOENT) {
                        BOOST_THROW_EXCEPTION(posix_error()
                            << boost::errinfo_api_function("unlink")
                            << boost::errinfo_errno(errno)