#include <password-exception.h>
#include <fcntl.h>
+#include <string.h>
namespace SecurityServer
{
Throw(PasswordException::FStreamWriteError);
}
file.close();
- int fd = open(path.c_str(), O_WRONLY | O_APPEND); fsync(fd); close(fd);
+
+ int fd;
+ if (0 <= (fd = open(path.c_str(), O_WRONLY | O_APPEND))) {
+ fsync(fd);
+ close(fd);
+ } else {
+ int err = errno;
+ LogError("Failed to fsync on file: " << path << " strerror: " << strerror(err));
+ }
}
void PasswordFileBuffer::Load(const std::string &path)
#include <password-file-buffer.h>
#include <fcntl.h>
+#include <string.h>
const std::string DATA_DIR = "/opt/data/security-server";
const std::string PASSWORD_FILE = "password.pwd";
Throw(PasswordException::FStreamWriteError);
}
attemptFile.close();
- int fd = open((DATA_DIR + "/" + ATTEMPT_FILE).c_str(), O_WRONLY | O_APPEND); fsync(fd); close(fd);
+
+ int fd;
+ if (0 <= (fd = open((DATA_DIR + "/" + ATTEMPT_FILE).c_str(), O_WRONLY | O_APPEND))) {
+ fsync(fd); // force synchronization system buffers with file
+ close(fd);
+ } else {
+ int err = errno;
+ LogError("Failed to sync attempt file: " << DATA_DIR << "/" << ATTEMPT_FILE << "strerror: " << strerror(err));
+ }
}
bool PasswordFile::isPasswordActive() const