added mutex
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
This commit is contained in:
1 parent
e74ab7a560
commit
e6ec1527da
8 files changed
+36
-18
No files matched your search
@@ -61,10 +61,13 @@ void add_user(const httplib::Request& request, httplib::Response& response)
|
||||
syslog(LOG_ERR, "access reject in add user request");
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream usersfile(USERS_FILE);
|
||||
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
||||
usersfile.close();
|
||||
nlohmann::json all_users;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(usersfilemutex);
|
||||
std::ifstream usersfile(USERS_FILE);
|
||||
all_users = nlohmann::json::parse(usersfile);
|
||||
usersfile.close();
|
||||
}
|
||||
|
||||
nlohmann::json response_user_data = nullptr;
|
||||
for (nlohmann::json& user : all_users) {
|
||||
@@ -102,6 +105,7 @@ void add_user(const httplib::Request& request, httplib::Response& response)
|
||||
new_user_data += "}";
|
||||
all_users.push_back(nlohmann::json::parse(new_user_data));
|
||||
|
||||
std::lock_guard<std::mutex> lock(usersfilemutex);
|
||||
std::ofstream usersfilew(USERS_FILE);
|
||||
usersfilew << all_users.dump(4);
|
||||
usersfilew.close();
|
||||
|
||||
Reference in new issue
Block a user