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

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

Issue 218883008: Use process_singleton_linux on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CreateUniqueTempDir is fine. DCHECK socket path length. Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "base/sequenced_task_runner_helpers.h" 67 #include "base/sequenced_task_runner_helpers.h"
68 #include "base/stl_util.h" 68 #include "base/stl_util.h"
69 #include "base/strings/string_number_conversions.h" 69 #include "base/strings/string_number_conversions.h"
70 #include "base/strings/string_split.h" 70 #include "base/strings/string_split.h"
71 #include "base/strings/stringprintf.h" 71 #include "base/strings/stringprintf.h"
72 #include "base/strings/sys_string_conversions.h" 72 #include "base/strings/sys_string_conversions.h"
73 #include "base/strings/utf_string_conversions.h" 73 #include "base/strings/utf_string_conversions.h"
74 #include "base/threading/platform_thread.h" 74 #include "base/threading/platform_thread.h"
75 #include "base/time/time.h" 75 #include "base/time/time.h"
76 #include "base/timer/timer.h" 76 #include "base/timer/timer.h"
77 #include "chrome/browser/ui/process_singleton_dialog_linux.h"
78 #include "chrome/common/chrome_constants.h" 77 #include "chrome/common/chrome_constants.h"
79 #include "content/public/browser/browser_thread.h" 78 #include "content/public/browser/browser_thread.h"
80 #include "grit/chromium_strings.h" 79 #include "grit/chromium_strings.h"
81 #include "grit/generated_resources.h" 80 #include "grit/generated_resources.h"
82 #include "net/base/net_util.h" 81 #include "net/base/net_util.h"
83 #include "ui/base/l10n/l10n_util.h" 82 #include "ui/base/l10n/l10n_util.h"
84 83
84 #if defined(OS_LINUX)
85 #include "chrome/browser/ui/process_singleton_dialog_linux.h"
86 #endif
87
85 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS) 88 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS)
86 #include "ui/views/linux_ui/linux_ui.h" 89 #include "ui/views/linux_ui/linux_ui.h"
87 #endif 90 #endif
88 91
89 using content::BrowserThread; 92 using content::BrowserThread;
90 93
91 const int ProcessSingleton::kTimeoutInSeconds; 94 const int ProcessSingleton::kTimeoutInSeconds;
92 95
93 namespace { 96 namespace {
94 97
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 *pid = -1; 294 *pid = -1;
292 295
293 return true; 296 return true;
294 } 297 }
295 298
296 // Returns true if the user opted to unlock the profile. 299 // Returns true if the user opted to unlock the profile.
297 bool DisplayProfileInUseError(const base::FilePath& lock_path, 300 bool DisplayProfileInUseError(const base::FilePath& lock_path,
298 const std::string& hostname, 301 const std::string& hostname,
299 int pid) { 302 int pid) {
300 base::string16 error = l10n_util::GetStringFUTF16( 303 base::string16 error = l10n_util::GetStringFUTF16(
301 IDS_PROFILE_IN_USE_LINUX, 304 IDS_PROFILE_IN_USE_POSIX,
302 base::IntToString16(pid), 305 base::IntToString16(pid),
303 base::ASCIIToUTF16(hostname)); 306 base::ASCIIToUTF16(hostname));
307 LOG(ERROR) << base::SysWideToNativeMB(base::UTF16ToWide(error)).c_str();
308 if (!g_disable_prompt) {
309 #if defined(OS_LINUX)
304 base::string16 relaunch_button_text = l10n_util::GetStringUTF16( 310 base::string16 relaunch_button_text = l10n_util::GetStringUTF16(
305 IDS_PROFILE_IN_USE_LINUX_RELAUNCH); 311 IDS_PROFILE_IN_USE_LINUX_RELAUNCH);
306 LOG(ERROR) << base::SysWideToNativeMB(base::UTF16ToWide(error)).c_str(); 312 return ShowProcessSingletonDialog(error, relaunch_button_text);
Scott Hess - ex-Googler 2014/04/18 20:51:33 Indentation is wrong in here. I think having the
jackhou1 2014/04/24 02:34:54 Done.
307 if (!g_disable_prompt) 313 #endif
308 return ShowProcessSingletonDialog(error, relaunch_button_text); 314 #if defined(OS_MACOSX)
Scott Hess - ex-Googler 2014/04/18 20:51:33 I think #elif defined(OS_MACOSX) would make sense,
jackhou1 2014/04/24 02:34:54 Done.
315 // On Mac, always usurp the lock.
316 return true;
317 #endif
318 }
tapted 2014/04/17 08:36:14 should this closing paren be before the #if?
jackhou1 2014/04/24 02:34:54 It matches with the "if (!g_disable_prompt) {", bu
309 return false; 319 return false;
310 } 320 }
311 321
312 bool IsChromeProcess(pid_t pid) { 322 bool IsChromeProcess(pid_t pid) {
313 base::FilePath other_chrome_path(base::GetProcessExecutablePath(pid)); 323 base::FilePath other_chrome_path(base::GetProcessExecutablePath(pid));
314 return (!other_chrome_path.empty() && 324 return (!other_chrome_path.empty() &&
315 other_chrome_path.BaseName() == 325 other_chrome_path.BaseName() ==
316 base::FilePath(chrome::kBrowserProcessExecutableName)); 326 base::FilePath(chrome::kBrowserProcessExecutableName));
317 } 327 }
318 328
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 return false; 898 return false;
889 } 899 }
890 900
891 // Create the socket file somewhere in /tmp which is usually mounted as a 901 // Create the socket file somewhere in /tmp which is usually mounted as a
892 // normal filesystem. Some network filesystems (notably AFS) are screwy and 902 // normal filesystem. Some network filesystems (notably AFS) are screwy and
893 // do not support Unix domain sockets. 903 // do not support Unix domain sockets.
894 if (!socket_dir_.CreateUniqueTempDir()) { 904 if (!socket_dir_.CreateUniqueTempDir()) {
895 LOG(ERROR) << "Failed to create socket directory."; 905 LOG(ERROR) << "Failed to create socket directory.";
896 return false; 906 return false;
897 } 907 }
908
909 // Check that the directory was created with the correct permissions.
910 int dir_mode = 0;
911 if (!base::GetPosixFilePermissions(socket_dir_.path(), &dir_mode) ||
912 dir_mode != base::FILE_PERMISSION_USER_MASK) {
mattm 2014/04/17 21:44:55 Should log an error here?
Scott Hess - ex-Googler 2014/04/18 20:51:33 As long as it doesn't cruft up buildbot or other l
jackhou1 2014/04/24 02:34:54 We don't want to create a socket in an unsafe dire
913 NOTREACHED();
914 return false;
915 }
916
898 // Setup the socket symlink and the two cookies. 917 // Setup the socket symlink and the two cookies.
899 base::FilePath socket_target_path = 918 base::FilePath socket_target_path =
900 socket_dir_.path().Append(chrome::kSingletonSocketFilename); 919 socket_dir_.path().Append(chrome::kSingletonSocketFilename);
920 // Check that socket_target_path is short enough for a Unix domain socket.
921 DCHECK_GT(104u, socket_target_path.value().length());
tapted 2014/04/17 08:36:14 This might only make sense on Mac, where the strin
mattm 2014/04/17 21:44:55 SetupSocket already has a CHECK() of the path leng
Scott Hess - ex-Googler 2014/04/18 20:51:33 I would think that would be why you'd want the che
jackhou1 2014/04/24 02:34:54 You're right, the check in SetupSocketAddr does th
922
901 base::FilePath cookie(GenerateCookie()); 923 base::FilePath cookie(GenerateCookie());
902 base::FilePath remote_cookie_path = 924 base::FilePath remote_cookie_path =
903 socket_dir_.path().Append(chrome::kSingletonCookieFilename); 925 socket_dir_.path().Append(chrome::kSingletonCookieFilename);
904 UnlinkPath(socket_path_); 926 UnlinkPath(socket_path_);
905 UnlinkPath(cookie_path_); 927 UnlinkPath(cookie_path_);
906 if (!SymlinkPath(socket_target_path, socket_path_) || 928 if (!SymlinkPath(socket_target_path, socket_path_) ||
907 !SymlinkPath(cookie, cookie_path_) || 929 !SymlinkPath(cookie, cookie_path_) ||
908 !SymlinkPath(cookie, remote_cookie_path)) { 930 !SymlinkPath(cookie, remote_cookie_path)) {
909 // We've already locked things, so we can't have lost the startup race, 931 // We've already locked things, so we can't have lost the startup race,
910 // but something doesn't like us. 932 // but something doesn't like us.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 } 999 }
978 1000
979 void ProcessSingleton::KillProcess(int pid) { 1001 void ProcessSingleton::KillProcess(int pid) {
980 // TODO(james.su@gmail.com): Is SIGKILL ok? 1002 // TODO(james.su@gmail.com): Is SIGKILL ok?
981 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); 1003 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL);
982 // ESRCH = No Such Process (can happen if the other process is already in 1004 // ESRCH = No Such Process (can happen if the other process is already in
983 // progress of shutting down and finishes before we try to kill it). 1005 // progress of shutting down and finishes before we try to kill it).
984 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " 1006 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: "
985 << safe_strerror(errno); 1007 << safe_strerror(errno);
986 } 1008 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698