This commit is contained in:
Marius Niculescu 2024-06-06 16:08:24 -07:00 коммит произвёл GitHub
Родитель 91d344272e
Коммит eb4078a755
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 43 добавлений и 10 удалений

Просмотреть файл

@ -65,6 +65,7 @@ bool EnableAndStartDaemon(const char* daemonName, void* log)
const char* startTemplate = "systemctl start %s";
char enableCommand[MAX_DAEMON_COMMAND_LENGTH] = {0};
char startCommand[MAX_DAEMON_COMMAND_LENGTH] = {0};
int commandResult = 0;
bool status = true;
if (false == IsDaemonActive(daemonName, log))
@ -74,8 +75,27 @@ bool EnableAndStartDaemon(const char* daemonName, void* log)
OsConfigLogInfo(log, "Starting service '%s'", daemonName);
status = ((0 == ExecuteCommand(NULL, enableCommand, false, false, 0, 0, NULL, NULL, log)) &&
(0 == ExecuteCommand(NULL, startCommand, false, false, 0, 0, NULL, NULL, log)));
if (0 == (commandResult == ExecuteCommand(NULL, enableCommand, false, false, 0, 0, NULL, NULL, log)))
{
if (0 == (commandResult == ExecuteCommand(NULL, startCommand, false, false, 0, 0, NULL, NULL, log)))
{
status = true;
}
else
{
OsConfigLogError(log, "Cannot start service '%s' (%d)", daemonName, commandResult);
status = false;
}
}
else
{
OsConfigLogError(log, "Failed to enable service '%s' (%d)", daemonName, commandResult);
status = false;
}
}
else
{
OsConfigLogInfo(log, "Service '%s' is already running", daemonName);
}
return status;
@ -87,18 +107,27 @@ void StopAndDisableDaemon(const char* daemonName, void* log)
const char* disableTemplate = "sudo systemctl disable %s";
char stopCommand[MAX_DAEMON_COMMAND_LENGTH] = {0};
char disableCommand[MAX_DAEMON_COMMAND_LENGTH] = {0};
int commandResult = 0;
snprintf(stopCommand, sizeof(stopCommand), stopTemplate, daemonName);
snprintf(disableCommand, sizeof(disableCommand), disableTemplate, daemonName);
ExecuteCommand(NULL, stopCommand, false, false, 0, 0, NULL, NULL, log);
ExecuteCommand(NULL, disableCommand, false, false, 0, 0, NULL, NULL, log);
if (0 != (commandResult = ExecuteCommand(NULL, stopCommand, false, false, 0, 0, NULL, NULL, log)))
{
OsConfigLogError(log, "Failed to stop service '%s' (%d)", daemonName, commandResult);
}
if (0 != (commandResult = ExecuteCommand(NULL, disableCommand, false, false, 0, 0, NULL, NULL, log)))
{
OsConfigLogError(log, "Failed to disable service '%s' (%d)", daemonName, commandResult);
}
}
bool RestartDaemon(const char* daemonName, void* log)
{
const char* restartTemplate = "systemctl restart %s";
char restartCommand[MAX_DAEMON_COMMAND_LENGTH] = {0};
int commandResult = 0;
bool status = true;
if (true == IsDaemonActive(daemonName, log))
@ -107,7 +136,11 @@ bool RestartDaemon(const char* daemonName, void* log)
OsConfigLogInfo(log, "Restarting service '%s'", daemonName);
status = (0 == ExecuteCommand(NULL, restartCommand, false, false, 0, 0, NULL, NULL, log));
if (0 != (commandResult = ExecuteCommand(NULL, restartCommand, false, false, 0, 0, NULL, NULL, log)))
{
OsConfigLogError(log, "Failed to restart service '%s' (%d)", daemonName, commandResult);
status = false;
}
}
return status;

Просмотреть файл

@ -73,7 +73,7 @@ int SetEnsurePasswordReuseIsLimited(int remember, void* log)
}
}
if (_status && (0 == status))
if ((0 == _status) || (_status && (0 == status)))
{
status = _status;
}
@ -639,11 +639,11 @@ int SetPasswordCreationRequirements(int retry, int minlen, int minclass, int dcr
OsConfigLogError(log, "SetPasswordCreationRequirements: out of memory when allocating new line for '%s'", g_etcSecurityPwQualityConf);
}
}
}
if (_status && (0 == status))
{
status = _status;
}
if ((0 == _status) || (_status && (0 == status)))
{
status = _status;
}
return status;