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

This commit is contained in:
wt committed 2025-04-18 15:47:36 +07:00
1 parent e74ab7a560
commit e6ec1527da
8 files changed
+36 -18

No files matched your search

+8 -5
View File
@@ -46,11 +46,13 @@ void change_user(const httplib::Request& request, httplib::Response& response)
syslog(LOG_ERR, "access reject in change 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();
}
std::string changeusruserid = userid;
if (json_body["userid"] != nullptr) {
changeusruserid = json_body["userid"];
@@ -103,6 +105,7 @@ void change_user(const httplib::Request& request, httplib::Response& response)
syslog(LOG_ERR, "can't find this user in change user request");
return;
}
std::lock_guard<std::mutex> lock(usersfilemutex);
std::ofstream usersfilew(USERS_FILE);
usersfilew << all_users.dump(4);
usersfilew.close();