Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 | 712 |
| 713 /////////////////////////////////////////////////////////////////////////////// | 713 /////////////////////////////////////////////////////////////////////////////// |
| 714 // ProcessSingleton | 714 // ProcessSingleton |
| 715 // | 715 // |
| 716 ProcessSingleton::ProcessSingleton( | 716 ProcessSingleton::ProcessSingleton( |
| 717 const base::FilePath& user_data_dir, | 717 const base::FilePath& user_data_dir, |
| 718 const NotificationCallback& notification_callback) | 718 const NotificationCallback& notification_callback) |
| 719 : notification_callback_(notification_callback), | 719 : notification_callback_(notification_callback), |
| 720 current_pid_(base::GetCurrentProcId()), | 720 current_pid_(base::GetCurrentProcId()), |
| 721 watcher_(new LinuxWatcher(this)) { | 721 watcher_(new LinuxWatcher(this)) { |
| 722 socket_path_ = user_data_dir.Append(chrome::kSingletonSocketFilename); | 722 socket_path_ = user_data_dir.Append(chrome::kSingletonSocketFilename); |
|
Nico
2017/03/17 19:31:49
Why does this one keep using the old path? Why not
mattm
2017/03/17 22:20:18
(I did mention in the CL description, let me know
| |
| 723 lock_path_ = user_data_dir.Append(chrome::kSingletonLockFilename); | 723 lock_path_ = user_data_dir.Append(chrome::kSingletonLockFilename); |
| 724 cookie_path_ = user_data_dir.Append(chrome::kSingletonCookieFilename); | 724 cookie_path_ = user_data_dir.Append(chrome::kSingletonCookieFilename); |
| 725 | 725 |
| 726 kill_callback_ = base::Bind(&ProcessSingleton::KillProcess, | 726 kill_callback_ = base::Bind(&ProcessSingleton::KillProcess, |
| 727 base::Unretained(this)); | 727 base::Unretained(this)); |
| 728 } | 728 } |
| 729 | 729 |
| 730 ProcessSingleton::~ProcessSingleton() { | 730 ProcessSingleton::~ProcessSingleton() { |
| 731 } | 731 } |
| 732 | 732 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 } | 977 } |
| 978 | 978 |
| 979 // Check that the directory was created with the correct permissions. | 979 // Check that the directory was created with the correct permissions. |
| 980 int dir_mode = 0; | 980 int dir_mode = 0; |
| 981 CHECK(base::GetPosixFilePermissions(socket_dir_.GetPath(), &dir_mode) && | 981 CHECK(base::GetPosixFilePermissions(socket_dir_.GetPath(), &dir_mode) && |
| 982 dir_mode == base::FILE_PERMISSION_USER_MASK) | 982 dir_mode == base::FILE_PERMISSION_USER_MASK) |
| 983 << "Temp directory mode is not 700: " << std::oct << dir_mode; | 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::kSingletonSocketRealFilename); |
| 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_) || |
| 994 !SymlinkPath(cookie, cookie_path_) || | 994 !SymlinkPath(cookie, cookie_path_) || |
| 995 !SymlinkPath(cookie, remote_cookie_path)) { | 995 !SymlinkPath(cookie, remote_cookie_path)) { |
| 996 // We've already locked things, so we can't have lost the startup race, | 996 // We've already locked things, so we can't have lost the startup race, |
| 997 // but something doesn't like us. | 997 // but something doesn't like us. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } |
| OLD | NEW |