Skip to content

Commit ce3275d

Browse files
Disallow stage deletions during reload
Once the new worker process has read the config, it also includes a `include */include.conf` statement within the config packages root directory, and from there on we must not allow to delete any stage directory from the config package. Otherwise, when the worker actually evaluates that include statement, it will fail to find the directory where the include file is located, or the `active.conf` file, which is included from each stage's `include.conf` file, thus causing the worker fail. Co-Authored-By: Johannes Schmidt <[email protected]>
1 parent 1ac4d83 commit ce3275d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/remote/configpackageshandler.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "remote/configpackageshandler.hpp"
44
#include "remote/configpackageutility.hpp"
5+
#include "remote/configobjectslock.hpp"
56
#include "remote/httputility.hpp"
67
#include "remote/filterutility.hpp"
78
#include "base/exception.hpp"
@@ -111,6 +112,12 @@ void ConfigPackagesHandler::HandlePost(
111112
return;
112113
}
113114

115+
ConfigObjectsSharedLock configObjectsSharedLock(std::try_to_lock);
116+
if (!configObjectsSharedLock) {
117+
HttpUtility::SendJsonError(response, params, 503, "Icinga is reloading");
118+
return;
119+
}
120+
114121
try {
115122
std::unique_lock<std::mutex> lock(ConfigPackageUtility::GetStaticPackageMutex());
116123

@@ -157,6 +164,12 @@ void ConfigPackagesHandler::HandleDelete(
157164
return;
158165
}
159166

167+
ConfigObjectsSharedLock lock(std::try_to_lock);
168+
if (!lock) {
169+
HttpUtility::SendJsonError(response, params, 503, "Icinga is reloading");
170+
return;
171+
}
172+
160173
try {
161174
ConfigPackageUtility::DeletePackage(packageName);
162175
} catch (const std::exception& ex) {

lib/remote/configstageshandler.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "remote/configstageshandler.hpp"
44
#include "remote/configpackageutility.hpp"
5+
#include "remote/configobjectslock.hpp"
56
#include "remote/httputility.hpp"
67
#include "remote/filterutility.hpp"
78
#include "base/application.hpp"
@@ -135,6 +136,12 @@ void ConfigStagesHandler::HandlePost(
135136
if (reload && !activate)
136137
BOOST_THROW_EXCEPTION(std::invalid_argument("Parameter 'reload' must be false when 'activate' is false."));
137138

139+
ConfigObjectsSharedLock configObjectsSharedLock(std::try_to_lock);
140+
if (!configObjectsSharedLock) {
141+
HttpUtility::SendJsonError(response, params, 503, "Icinga is reloading");
142+
return;
143+
}
144+
138145
{
139146
std::lock_guard runningPackageUpdatesLock(l_RunningPackageUpdatesMutex);
140147
double currentReloadFailedTime = Application::GetLastReloadFailed();
@@ -228,6 +235,12 @@ void ConfigStagesHandler::HandleDelete(
228235
if (!ConfigPackageUtility::ValidateStageName(stageName))
229236
return HttpUtility::SendJsonError(response, params, 400, "Invalid stage name '" + stageName + "'.");
230237

238+
ConfigObjectsSharedLock lock(std::try_to_lock);
239+
if (!lock) {
240+
HttpUtility::SendJsonError(response, params, 503, "Icinga is reloading");
241+
return;
242+
}
243+
231244
try {
232245
ConfigPackageUtility::DeleteStage(packageName, stageName);
233246
} catch (const std::exception& ex) {

0 commit comments

Comments
 (0)