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

Unified Diff: chrome/common/multi_process_lock_linux.cc

Issue 8341052: share all the needed linux code with OpenBSD in chrome and content (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebased due to LOG macro changes Created 9 years, 1 month 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
Index: chrome/common/multi_process_lock_linux.cc
diff --git a/chrome/common/multi_process_lock_linux.cc b/chrome/common/multi_process_lock_linux.cc
index c5b70a40528e50c987526e7ec73a2e1c4b1f84e7..f610237eea781c2f5c27b081d663ddcc6282fef7 100644
--- a/chrome/common/multi_process_lock_linux.cc
+++ b/chrome/common/multi_process_lock_linux.cc
@@ -24,33 +24,30 @@ class MultiProcessLockLinux : public MultiProcessLock {
}
virtual bool TryLock() {
+ struct sockaddr_un address;
+
+ // +1 for terminator, +1 for 0 in position 0 that makes it an
+ // abstract named socket.
+ const size_t max_len = sizeof(address.sun_path) - 2;
+
if (fd_ != -1) {
DLOG(ERROR) << "MultiProcessLock is already locked - " << name_;
return true;
}
- if (name_.length() > MULTI_PROCESS_LOCK_NAME_MAX_LEN) {
+ if (name_.length() > max_len) {
LOG(ERROR) << "Socket name too long (" << name_.length()
- << " > " << MULTI_PROCESS_LOCK_NAME_MAX_LEN << ") - " << name_;
+ << " > " << max_len << ") - " << name_;
return false;
}
- struct sockaddr_un address;
-
- // +1 for terminator, +1 for 0 in position 0 that makes it an
- // abstract named socket.
- // If this assert fails it is because sockaddr_un.sun_path size has been
- // redefined and MULTI_PROCESS_LOCK_NAME_MAX_LEN can change accordingly.
- COMPILE_ASSERT(sizeof(address.sun_path)
- == MULTI_PROCESS_LOCK_NAME_MAX_LEN + 2, sun_path_size_changed);
-
memset(&address, 0, sizeof(address));
int print_length = snprintf(&address.sun_path[1],
- MULTI_PROCESS_LOCK_NAME_MAX_LEN + 1,
+ max_len + 1,
"%s", name_.c_str());
if (print_length < 0 ||
- print_length > static_cast<int>(MULTI_PROCESS_LOCK_NAME_MAX_LEN)) {
+ print_length > static_cast<int>(max_len)) {
PLOG(ERROR) << "Couldn't create sun_path - " << name_;
return false;
}

Powered by Google App Engine
This is Rietveld 408576698