blob: 42f45806a55725eb4d345c23a755c6705b2ed30d [file] [log] [blame]
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -07001// Copyright (c) 2012 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#ifndef SHILL_MINIJAIL_H_
6#define SHILL_MINIJAIL_H_
7
8#include <vector>
9
10extern "C" {
11#include <linux/capability.h>
12}
13
14#include <base/lazy_instance.h>
15#include <chromeos/libminijail.h>
16
17namespace shill {
18
19// A Minijail abstraction allowing Minijail mocking in tests.
20class Minijail {
21 public:
22 virtual ~Minijail();
23
24 // This is a singleton -- use Minijail::GetInstance()->Foo()
25 static Minijail *GetInstance();
26
27 // minijail_new
28 virtual struct minijail *New();
29 // minijail_destroy
30 virtual void Destroy(struct minijail *jail);
31
32 // minijail_change_user/minijail_change_group
33 virtual bool DropRoot(struct minijail *jail, const char *user);
34 // minijail_use_caps
35 virtual void UseCapabilities(struct minijail *jail, uint64_t capmask);
36
37 // minijail_run_pid
38 virtual bool Run(struct minijail *jail, std::vector<char *> args, pid_t *pid);
39
40 // Run() and Destroy()
41 virtual bool RunAndDestroy(struct minijail *jail,
42 std::vector<char *> args,
43 pid_t *pid);
44
45 protected:
46 Minijail();
47
48 private:
49 friend struct base::DefaultLazyInstanceTraits<Minijail>;
50
51 DISALLOW_COPY_AND_ASSIGN(Minijail);
52};
53
54} // namespace shill
55
56#endif // SHILL_MINIJAIL_H_