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

Side by Side Diff: chrome/browser/process_singleton_posix.cc

Issue 2561963002: base: Remove the string logging from CHECK(). (Closed)
Patch Set: checkstring: rebase Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // On Linux, when the user tries to launch a second copy of chrome, we check 5 // On Linux, when the user tries to launch a second copy of chrome, we check
6 // for a socket in the user's profile directory. If the socket file is open we 6 // for a socket in the user's profile directory. If the socket file is open we
7 // send a message to the first chrome browser process with the current 7 // send a message to the first chrome browser process with the current
8 // directory and second process command line flags. The second process then 8 // directory and second process command line flags. The second process then
9 // exits. 9 // exits.
10 // 10 //
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 bytes_read += rv; 213 bytes_read += rv;
214 } 214 }
215 } while (bytes_read < bufsize); 215 } while (bytes_read < bufsize);
216 216
217 return bytes_read; 217 return bytes_read;
218 } 218 }
219 219
220 // Set up a sockaddr appropriate for messaging. 220 // Set up a sockaddr appropriate for messaging.
221 void SetupSockAddr(const std::string& path, struct sockaddr_un* addr) { 221 void SetupSockAddr(const std::string& path, struct sockaddr_un* addr) {
222 addr->sun_family = AF_UNIX; 222 addr->sun_family = AF_UNIX;
223 CHECK(path.length() < arraysize(addr->sun_path)) 223 // Socket path too long.
224 << "Socket path too long: " << path; 224 CHECK(path.length() < arraysize(addr->sun_path));
225 base::strlcpy(addr->sun_path, path.c_str(), arraysize(addr->sun_path)); 225 base::strlcpy(addr->sun_path, path.c_str(), arraysize(addr->sun_path));
226 } 226 }
227 227
228 // Set up a socket appropriate for messaging. 228 // Set up a socket appropriate for messaging.
229 int SetupSocketOnly() { 229 int SetupSocketOnly() {
230 int sock = socket(PF_UNIX, SOCK_STREAM, 0); 230 int sock = socket(PF_UNIX, SOCK_STREAM, 0);
231 PCHECK(sock >= 0) << "socket() failed"; 231 // socket() failed
232 CHECK(sock >= 0);
232 233
233 DCHECK(base::SetNonBlocking(sock)) << "Failed to make non-blocking socket."; 234 DCHECK(base::SetNonBlocking(sock)) << "Failed to make non-blocking socket.";
234 int rv = SetCloseOnExec(sock); 235 int rv = SetCloseOnExec(sock);
235 DCHECK_EQ(0, rv) << "Failed to set CLOEXEC on socket."; 236 DCHECK_EQ(0, rv) << "Failed to set CLOEXEC on socket.";
236 237
237 return sock; 238 return sock;
238 } 239 }
239 240
240 // Set up a socket and sockaddr appropriate for messaging. 241 // Set up a socket and sockaddr appropriate for messaging.
241 void SetupSocket(const std::string& path, int* sock, struct sockaddr_un* addr) { 242 void SetupSocket(const std::string& path, int* sock, struct sockaddr_un* addr) {
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 } 970 }
970 971
971 // Create the socket file somewhere in /tmp which is usually mounted as a 972 // Create the socket file somewhere in /tmp which is usually mounted as a
972 // normal filesystem. Some network filesystems (notably AFS) are screwy and 973 // normal filesystem. Some network filesystems (notably AFS) are screwy and
973 // do not support Unix domain sockets. 974 // do not support Unix domain sockets.
974 if (!socket_dir_.CreateUniqueTempDir()) { 975 if (!socket_dir_.CreateUniqueTempDir()) {
975 LOG(ERROR) << "Failed to create socket directory."; 976 LOG(ERROR) << "Failed to create socket directory.";
976 return false; 977 return false;
977 } 978 }
978 979
979 // Check that the directory was created with the correct permissions. 980 // Check that the directory was created with the correct permissions (0700).
980 int dir_mode = 0; 981 int dir_mode = 0;
981 CHECK(base::GetPosixFilePermissions(socket_dir_.GetPath(), &dir_mode) && 982 CHECK(base::GetPosixFilePermissions(socket_dir_.GetPath(), &dir_mode) &&
982 dir_mode == base::FILE_PERMISSION_USER_MASK) 983 dir_mode == base::FILE_PERMISSION_USER_MASK);
983 << "Temp directory mode is not 700: " << std::oct << dir_mode;
984 984
985 // Setup the socket symlink and the two cookies. 985 // Setup the socket symlink and the two cookies.
986 base::FilePath socket_target_path = 986 base::FilePath socket_target_path =
987 socket_dir_.GetPath().Append(chrome::kSingletonSocketFilename); 987 socket_dir_.GetPath().Append(chrome::kSingletonSocketFilename);
988 base::FilePath cookie(GenerateCookie()); 988 base::FilePath cookie(GenerateCookie());
989 base::FilePath remote_cookie_path = 989 base::FilePath remote_cookie_path =
990 socket_dir_.GetPath().Append(chrome::kSingletonCookieFilename); 990 socket_dir_.GetPath().Append(chrome::kSingletonCookieFilename);
991 UnlinkPath(socket_path_); 991 UnlinkPath(socket_path_);
992 UnlinkPath(cookie_path_); 992 UnlinkPath(cookie_path_);
993 if (!SymlinkPath(socket_target_path, socket_path_) || 993 if (!SymlinkPath(socket_target_path, socket_path_) ||
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 } 1064 }
1065 1065
1066 void ProcessSingleton::KillProcess(int pid) { 1066 void ProcessSingleton::KillProcess(int pid) {
1067 // TODO(james.su@gmail.com): Is SIGKILL ok? 1067 // TODO(james.su@gmail.com): Is SIGKILL ok?
1068 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); 1068 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL);
1069 // ESRCH = No Such Process (can happen if the other process is already in 1069 // ESRCH = No Such Process (can happen if the other process is already in
1070 // progress of shutting down and finishes before we try to kill it). 1070 // progress of shutting down and finishes before we try to kill it).
1071 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " 1071 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: "
1072 << base::safe_strerror(errno); 1072 << base::safe_strerror(errno);
1073 } 1073 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698