blob: 9a668c07fc5037fde10d8c91ab2f7c070ab9cd36 [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
mukesh agrawalf407d592013-07-31 11:37:57 -070024 // This is a singleton -- use Minijail::GetInstance()->Foo().
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -070025 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
Jorge Lucangeli Obesccd5c852012-12-19 18:08:40 -080040 // minijail_run_pid and waitpid
41 virtual bool RunSync(struct minijail *jail, std::vector<char *> args,
42 int *status);
43
Jorge Lucangeli Obes8c1706f2012-08-30 15:30:48 -070044 // minijail_run_pid_pipe
45 virtual bool RunPipe(struct minijail *jail, std::vector<char *> args,
46 pid_t *pid, int *stdin);
47
Christopher Wiley8fa357c2013-02-21 11:35:58 -080048 // minijail_run_pid_pipes
49 virtual bool RunPipes(struct minijail *jail, std::vector<char *> args,
50 pid_t *pid, int *stdin, int *stdout, int *stderr);
51
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -070052 // Run() and Destroy()
53 virtual bool RunAndDestroy(struct minijail *jail,
54 std::vector<char *> args,
55 pid_t *pid);
56
Jorge Lucangeli Obesccd5c852012-12-19 18:08:40 -080057 // RunSync() and Destroy()
58 virtual bool RunSyncAndDestroy(struct minijail *jail,
59 std::vector<char *> args,
60 int *status);
61
Jorge Lucangeli Obes8c1706f2012-08-30 15:30:48 -070062 // RunPipe() and Destroy()
63 virtual bool RunPipeAndDestroy(struct minijail *jail,
64 std::vector<char *> args,
65 pid_t *pid, int *stdin);
66
Christopher Wiley8fa357c2013-02-21 11:35:58 -080067 // RunPipes() and Destroy()
68 virtual bool RunPipesAndDestroy(struct minijail *jail,
69 std::vector<char *> args,
70 pid_t *pid, int *stdin,
71 int *stdout, int *stderr);
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -070072 protected:
73 Minijail();
74
75 private:
76 friend struct base::DefaultLazyInstanceTraits<Minijail>;
77
78 DISALLOW_COPY_AND_ASSIGN(Minijail);
79};
80
81} // namespace shill
82
83#endif // SHILL_MINIJAIL_H_