blob: 6bf650e54f2f79ace58466863983843dbdb8f209 [file] [log] [blame]
Elly Jones0c016cc2011-12-19 16:19:22 -05001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "subprocess_tool.h"
6
7#include <dbus-c++/dbus.h>
8#include <signal.h>
9
10#include "process_with_id.h"
11
12namespace debugd {
13
14const char* kErrorNoSuchProcess =
15 "org.chromium.debugd.error.NoSuchProcess";
16
17SubprocessTool::SubprocessTool() { }
18SubprocessTool::~SubprocessTool() { }
19
20ProcessWithId* SubprocessTool::CreateProcess() {
21 ProcessWithId* p = new ProcessWithId();
22 if (!p->Init() || processes_.count(p->id()) == 1)
23 return NULL;
24 processes_[p->id()] = p;
25 return p;
26}
27
28void SubprocessTool::Stop(const std::string& handle, DBus::Error& error) {
29 if (processes_.count(handle) != 1) {
30 error.set(kErrorNoSuchProcess, handle.c_str());
31 return;
32 }
33 ProcessWithId* p = processes_[handle];
34 p->Kill(SIGKILL, 0); // no timeout
35 p->Wait();
36 processes_.erase(handle);
37 delete p;
38}
39
40}; // namespace debugd