diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 23:05:19 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 23:05:19 +0000 |
commit | a70d9cf0db8414b4495de849004157cb32658975 (patch) | |
tree | 15ccdc30c586dd05dd8f836c73f7f8744811926c /chrome/browser/process_singleton_linux_uitest.cc | |
parent | 180242c1754b60dd66697f46d7766a5bb49ba322 (diff) | |
download | chromium_src-a70d9cf0db8414b4495de849004157cb32658975.zip chromium_src-a70d9cf0db8414b4495de849004157cb32658975.tar.gz chromium_src-a70d9cf0db8414b4495de849004157cb32658975.tar.bz2 |
ProcessSingletonLinux: check if lock pid is part of the current Chrome instance.
If it is, it must be an orphaned lock file that just happens to have an unfortunate pid, since we haven't tried to create a lockfile ourselves yet.
Also, don't allow kill with pid 0, which would be another way to theoretically kill ourselves.
BUG=42568,43594
TEST=ui_tests, manual testing
Review URL: http://codereview.chromium.org/1981009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46977 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton_linux_uitest.cc')
-rw-r--r-- | chrome/browser/process_singleton_linux_uitest.cc | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/chrome/browser/process_singleton_linux_uitest.cc b/chrome/browser/process_singleton_linux_uitest.cc index d0ba750..b0258e7 100644 --- a/chrome/browser/process_singleton_linux_uitest.cc +++ b/chrome/browser/process_singleton_linux_uitest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -23,6 +23,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/test/chrome_process_util.h" #include "chrome/test/ui/ui_test.h" +#include "net/base/net_util.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -122,6 +123,44 @@ TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessFailure) { EXPECT_FALSE(CrashAwareSleep(sleep_timeout_ms())); } +// Test that we don't kill ourselves by accident if a lockfile with the same pid +// happens to exist. +// TODO(mattm): This doesn't really need to be a uitest. (We don't use the +// uitest created browser process, but we do use some uitest provided stuff like +// the user_data_dir and the NotifyOtherProcess function in this file, which +// would have to be duplicated or shared if this test was moved into a +// unittest.) +TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) { + FilePath lock_path = user_data_dir().Append(chrome::kSingletonLockFilename); + EXPECT_EQ(0, unlink(lock_path.value().c_str())); + std::string symlink_content = StringPrintf( + "%s%c%u", + net::GetHostName().c_str(), + '-', + base::GetCurrentProcId()); + EXPECT_EQ(0, symlink(symlink_content.c_str(), lock_path.value().c_str())); + + base::ProcessId pid = browser_process_id(); + + ASSERT_GE(pid, 1); + + // Block the browser process, so that ProcessSingleton::NotifyOtherProcess() + // will want to kill something. + kill(pid, SIGSTOP); + + // Wait to make sure the browser process is actually stopped. + // It's necessary when running with valgrind. + HANDLE_EINTR(waitpid(pid, 0, WUNTRACED)); + + std::string url("about:blank"); + EXPECT_EQ(ProcessSingleton::PROCESS_NONE, + NotifyOtherProcess(url, action_timeout_ms())); + // If we've gotten to this point without killing ourself, the test succeeded. + + // Unblock the browser process so the test actually finishes. + kill(pid, SIGCONT); +} + // Test that we can still notify a process on the same host even after the // hostname changed. TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessHostChanged) { |