Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Unified Diff: metrics_library.cc

Issue 6576048: libmetrics -- release the shared file lock when closing, handle EINTR. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/metrics.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: metrics_library.cc
diff --git a/metrics_library.cc b/metrics_library.cc
index f2046a35e50fb170140085507d1204f56d4fe783..3bc800716df9903034363cf678861de5d3bac8dd 100644
--- a/metrics_library.cc
+++ b/metrics_library.cc
@@ -12,6 +12,8 @@
#include <cstdio>
#include <cstring>
+#include <base/eintr_wrapper.h>
+
#define READ_WRITE_ALL_FILE_FLAGS \
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
@@ -130,9 +132,9 @@ bool MetricsLibrary::SendMessageToChrome(int32_t length, const char* message) {
if (!AreMetricsEnabled())
return true;
- int chrome_fd = open(uma_events_file_,
- O_WRONLY | O_APPEND | O_CREAT,
- READ_WRITE_ALL_FILE_FLAGS);
+ int chrome_fd = HANDLE_EINTR(open(uma_events_file_,
+ O_WRONLY | O_APPEND | O_CREAT,
+ READ_WRITE_ALL_FILE_FLAGS));
// If we failed to open it, return.
if (chrome_fd < 0) {
PrintError("open", uma_events_file_, errno);
@@ -146,24 +148,20 @@ bool MetricsLibrary::SendMessageToChrome(int32_t length, const char* message) {
// Grab an exclusive lock to protect Chrome from truncating
// underneath us. Keep the file locked as briefly as possible.
- if (flock(chrome_fd, LOCK_EX) < 0) {
+ if (HANDLE_EINTR(flock(chrome_fd, LOCK_EX)) < 0) {
PrintError("flock", uma_events_file_, errno);
- close(chrome_fd);
+ HANDLE_EINTR(close(chrome_fd));
return false;
}
bool success = true;
- if (write(chrome_fd, message, length) != length) {
+ if (HANDLE_EINTR(write(chrome_fd, message, length)) != length) {
PrintError("write", uma_events_file_, errno);
success = false;
}
- // Release the file lock and close file.
- if (flock(chrome_fd, LOCK_UN) < 0) {
- PrintError("unlock", uma_events_file_, errno);
- success = false;
- }
- close(chrome_fd);
+ // Close the file and release the lock.
+ HANDLE_EINTR(close(chrome_fd));
return success;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698