@@ -236,10 +236,17 @@ WinService::Startup WinService::getStartup() const
236
236
237
237
void WinService::setFailureActions (FailureActionVector failureActions, const std::string& command, const std::string& rebootMessage)
238
238
{
239
+
240
+ if (failureActions.size () > 3 ) {
241
+ throw InvalidArgumentException{ " Only 0-3 Failure Actions are supported" };
242
+ }
243
+
239
244
open ();
240
- auto actions = new SC_ACTION[3 ];
245
+ auto actions = new SC_ACTION[failureActions. size () ];
241
246
SERVICE_FAILURE_ACTIONSW ac;
242
-
247
+ ac.lpCommand = NULL ;
248
+ ac.lpRebootMsg = NULL ;
249
+
243
250
std::wstring urebootMessage;
244
251
Poco::UnicodeConverter::toUTF16 (rebootMessage, urebootMessage);
245
252
std::vector<wchar_t > rebootMessageVector{ urebootMessage.begin (), urebootMessage.end () };
@@ -250,7 +257,7 @@ void WinService::setFailureActions(FailureActionVector failureActions, const std
250
257
std::vector<wchar_t > commandVector{ uComamnd.begin (), uComamnd.end () };
251
258
commandVector.push_back (' \0 ' );
252
259
253
- for (auto i = 0 ; i < 3 ; i++)
260
+ for (auto i = 0 ; i < failureActions. size () ; i++)
254
261
{
255
262
switch (failureActions[i].type )
256
263
{
@@ -276,7 +283,7 @@ void WinService::setFailureActions(FailureActionVector failureActions, const std
276
283
}
277
284
278
285
ac.dwResetPeriod = 0 ;
279
- ac.cActions = 3 ;
286
+ ac.cActions = failureActions. size () ;
280
287
ac.lpsaActions = actions;
281
288
282
289
if (!ChangeServiceConfig2W (_svcHandle, SERVICE_CONFIG_FAILURE_ACTIONS, &ac))
0 commit comments