diff options
author | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 17:14:36 +0000 |
---|---|---|
committer | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 17:14:36 +0000 |
commit | 56f0f264ff866052ebcb24e75147cb600e6547a1 (patch) | |
tree | 8b16bded93f914cacbf3cb130fae3539ad4bb268 /chrome/common/service_process_util_linux.cc | |
parent | 04a8454da64b62bfad5091efd5cf1143443283f0 (diff) | |
download | chromium_src-56f0f264ff866052ebcb24e75147cb600e6547a1.zip chromium_src-56f0f264ff866052ebcb24e75147cb600e6547a1.tar.gz chromium_src-56f0f264ff866052ebcb24e75147cb600e6547a1.tar.bz2 |
Get service process running standalone on the mac by hooking it into launchd.
BUG=NONE
TEST=BUILD
Review URL: http://codereview.chromium.org/6482016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/service_process_util_linux.cc')
-rw-r--r-- | chrome/common/service_process_util_linux.cc | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/chrome/common/service_process_util_linux.cc b/chrome/common/service_process_util_linux.cc new file mode 100644 index 0000000..1a53889 --- /dev/null +++ b/chrome/common/service_process_util_linux.cc @@ -0,0 +1,79 @@ +// 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. + +#include "chrome/common/service_process_util_posix.h" + +#include <signal.h> +#include <unistd.h> + +#include "base/file_util.h" +#include "base/logging.h" +#include "base/threading/platform_thread.h" +#include "chrome/common/multi_process_lock.h" + +namespace { + +// Attempts to take a lock named |name|. If |waiting| is true then this will +// make multiple attempts to acquire the lock. +// Caller is responsible for ownership of the MultiProcessLock. +MultiProcessLock* TakeNamedLock(const std::string& name, bool waiting) { + scoped_ptr<MultiProcessLock> lock(MultiProcessLock::Create(name)); + if (lock == NULL) return NULL; + bool got_lock = false; + for (int i = 0; i < 10; ++i) { + if (lock->TryLock()) { + got_lock = true; + break; + } + if (!waiting) break; + base::PlatformThread::Sleep(100 * i); + } + if (!got_lock) { + lock.reset(); + } + return lock.release(); +} + +MultiProcessLock* TakeServiceInitializingLock(bool waiting) { + std::string lock_name = + GetServiceProcessScopedName("_service_initializing"); + return TakeNamedLock(lock_name, waiting); +} + +} // namespace + +MultiProcessLock* TakeServiceRunningLock(bool waiting) { + std::string lock_name = + GetServiceProcessScopedName("_service_running"); + return TakeNamedLock(lock_name, waiting); +} + +bool ForceServiceProcessShutdown(const std::string& version, + base::ProcessId process_id) { + if (kill(process_id, SIGTERM) < 0) { + PLOG(ERROR) << "kill"; + return false; + } + return true; +} + +bool CheckServiceProcessReady() { + scoped_ptr<MultiProcessLock> running_lock(TakeServiceRunningLock(false)); + return running_lock.get() == NULL; +} + +bool ServiceProcessState::TakeSingletonLock() { + state_->initializing_lock_.reset(TakeServiceInitializingLock(true)); + return state_->initializing_lock_.get(); +} + +bool ServiceProcessState::AddToAutoRun(CommandLine* cmd_line) { + NOTIMPLEMENTED(); + return false; +} + +bool ServiceProcessState::RemoveFromAutoRun() { + NOTIMPLEMENTED(); + return false; +} |