| 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 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 // Create the socket file somewhere in /tmp which is usually mounted as a | 962 // Create the socket file somewhere in /tmp which is usually mounted as a |
| 963 // normal filesystem. Some network filesystems (notably AFS) are screwy and | 963 // normal filesystem. Some network filesystems (notably AFS) are screwy and |
| 964 // do not support Unix domain sockets. | 964 // do not support Unix domain sockets. |
| 965 if (!socket_dir_.CreateUniqueTempDir()) { | 965 if (!socket_dir_.CreateUniqueTempDir()) { |
| 966 LOG(ERROR) << "Failed to create socket directory."; | 966 LOG(ERROR) << "Failed to create socket directory."; |
| 967 return false; | 967 return false; |
| 968 } | 968 } |
| 969 | 969 |
| 970 // Check that the directory was created with the correct permissions. | 970 // Check that the directory was created with the correct permissions. |
| 971 int dir_mode = 0; | 971 int dir_mode = 0; |
| 972 CHECK(base::GetPosixFilePermissions(socket_dir_.path(), &dir_mode) && | 972 CHECK(base::GetPosixFilePermissions(socket_dir_.GetPath(), &dir_mode) && |
| 973 dir_mode == base::FILE_PERMISSION_USER_MASK) | 973 dir_mode == base::FILE_PERMISSION_USER_MASK) |
| 974 << "Temp directory mode is not 700: " << std::oct << dir_mode; | 974 << "Temp directory mode is not 700: " << std::oct << dir_mode; |
| 975 | 975 |
| 976 // Setup the socket symlink and the two cookies. | 976 // Setup the socket symlink and the two cookies. |
| 977 base::FilePath socket_target_path = | 977 base::FilePath socket_target_path = |
| 978 socket_dir_.path().Append(chrome::kSingletonSocketFilename); | 978 socket_dir_.GetPath().Append(chrome::kSingletonSocketFilename); |
| 979 base::FilePath cookie(GenerateCookie()); | 979 base::FilePath cookie(GenerateCookie()); |
| 980 base::FilePath remote_cookie_path = | 980 base::FilePath remote_cookie_path = |
| 981 socket_dir_.path().Append(chrome::kSingletonCookieFilename); | 981 socket_dir_.GetPath().Append(chrome::kSingletonCookieFilename); |
| 982 UnlinkPath(socket_path_); | 982 UnlinkPath(socket_path_); |
| 983 UnlinkPath(cookie_path_); | 983 UnlinkPath(cookie_path_); |
| 984 if (!SymlinkPath(socket_target_path, socket_path_) || | 984 if (!SymlinkPath(socket_target_path, socket_path_) || |
| 985 !SymlinkPath(cookie, cookie_path_) || | 985 !SymlinkPath(cookie, cookie_path_) || |
| 986 !SymlinkPath(cookie, remote_cookie_path)) { | 986 !SymlinkPath(cookie, remote_cookie_path)) { |
| 987 // We've already locked things, so we can't have lost the startup race, | 987 // We've already locked things, so we can't have lost the startup race, |
| 988 // but something doesn't like us. | 988 // but something doesn't like us. |
| 989 LOG(ERROR) << "Failed to create symlinks."; | 989 LOG(ERROR) << "Failed to create symlinks."; |
| 990 if (!socket_dir_.Delete()) | 990 if (!socket_dir_.Delete()) |
| 991 LOG(ERROR) << "Encountered a problem when deleting socket directory."; | 991 LOG(ERROR) << "Encountered a problem when deleting socket directory."; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 void ProcessSingleton::KillProcess(int pid) { | 1057 void ProcessSingleton::KillProcess(int pid) { |
| 1058 // TODO(james.su@gmail.com): Is SIGKILL ok? | 1058 // TODO(james.su@gmail.com): Is SIGKILL ok? |
| 1059 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); | 1059 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); |
| 1060 // ESRCH = No Such Process (can happen if the other process is already in | 1060 // ESRCH = No Such Process (can happen if the other process is already in |
| 1061 // progress of shutting down and finishes before we try to kill it). | 1061 // progress of shutting down and finishes before we try to kill it). |
| 1062 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " | 1062 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " |
| 1063 << base::safe_strerror(errno); | 1063 << base::safe_strerror(errno); |
| 1064 } | 1064 } |
| OLD | NEW |