From e6fc1b91a7e083c98564dec00bfe217265486073 Mon Sep 17 00:00:00 2001 From: Yannick Martin Date: Tue, 3 Jun 2025 16:33:12 +0200 Subject: [PATCH] AddComment: return Comment::Ptr instead of String containing the name Mimic 88e5744d54f79ab6a84260bd4a8d2cc0ffd43465 and address nullptr on concurrent add-comment / remove-comment actions. --- lib/icinga/apiactions.cpp | 4 ++-- lib/icinga/comment.cpp | 4 ++-- lib/icinga/comment.hpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 885834edc..781705b64 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -316,11 +316,11 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object, return ApiActions::CreateResult(503, "Icinga is reloading."); } - String commentName = Comment::AddComment(checkable, CommentUser, + Comment::Ptr comment = Comment::AddComment(checkable, CommentUser, HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"), false, timestamp); - Comment::Ptr comment = Comment::GetByName(commentName); + String commentName = comment->GetName(); Dictionary::Ptr additional = new Dictionary({ { "name", commentName }, diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 9c0b92359..0d1967440 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -130,7 +130,7 @@ int Comment::GetNextCommentID() return l_NextCommentID; } -String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryType, const String& author, +Comment::Ptr Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryType, const String& author, const String& text, bool persistent, double expireTime, bool sticky, const String& id, const MessageOrigin::Ptr& origin) { String fullName; @@ -184,7 +184,7 @@ String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryTyp Log(LogNotice, "Comment") << "Added comment '" << comment->GetName() << "'."; - return fullName; + return comment; } void Comment::RemoveComment(const String& id, bool removedManually, const String& removedBy, diff --git a/lib/icinga/comment.hpp b/lib/icinga/comment.hpp index 653208478..a230040f8 100644 --- a/lib/icinga/comment.hpp +++ b/lib/icinga/comment.hpp @@ -34,7 +34,7 @@ public: static int GetNextCommentID(); - static String AddComment(const intrusive_ptr& checkable, CommentType entryType, + static Ptr AddComment(const intrusive_ptr& checkable, CommentType entryType, const String& author, const String& text, bool persistent, double expireTime, bool sticky = false, const String& id = String(), const MessageOrigin::Ptr& origin = nullptr);