MCPcopy Create free account
hub / github.com/COVESA/vsomeip / remove_lockfile

Method remove_lockfile

implementation/utility/src/utility.cpp:209–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207}
208
209void utility::remove_lockfile(const std::string& _network) {
210 std::scoped_lock its_lock(get_utility_mutex());
211 auto& data = get_utility_data();
212
213 auto r = data.find(_network);
214 if (r == data.end()) // No need to do anything as automatic
215 return;
216
217#ifdef _WIN32
218 if (r->second.lock_handle_ != INVALID_HANDLE_VALUE) {
219 if (CloseHandle(r->second.lock_handle_) == 0) {
220 VSOMEIP_ERROR_P << "CloseHandle failed." << std::hex << GetLastError();
221 }
222 wchar_t its_tmp_folder[MAX_PATH];
223 if (GetTempPathW(MAX_PATH, its_tmp_folder)) {
224 std::wstring its_lockfile(its_tmp_folder);
225 std::string its_network(_network + ".lck");
226 its_lockfile.append(its_network.begin(), its_network.end());
227 if (DeleteFileW(its_lockfile.c_str()) == 0) {
228 VSOMEIP_ERROR_P << "DeleteFileW failed: " << std::hex << GetLastError();
229 }
230 } else {
231 VSOMEIP_ERROR_P << "Could not get temp folder." << std::hex << GetLastError();
232 }
233 }
234#else
235 std::string its_base_path(base_path() + _network);
236 std::string its_lockfile(its_base_path + ".lck");
237
238 if (r->second.lock_fd_ != -1) {
239 if (close(r->second.lock_fd_) == -1) {
240 VSOMEIP_ERROR_P << "Could not close lock_fd_: errno " << errno;
241 }
242 }
243 if (remove(its_lockfile.c_str()) == -1) {
244 VSOMEIP_ERROR_P << "Could not remove " << its_lockfile << ": errno " << errno;
245 }
246#endif
247 data.erase(_network);
248}
249
250bool utility::exists(const std::string& _path) {
251 struct stat its_stat;

Callers 1

TESTFunction · 0.80

Calls 3

base_pathFunction · 0.85
endMethod · 0.80
beginMethod · 0.80

Tested by

no test coverage detected