Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 1 | /* Copyright 2016 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 | |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 6 | #include <errno.h> |
| 7 | #include <signal.h> |
| 8 | #include <sys/mount.h> |
| 9 | #include <sys/stat.h> |
| 10 | #include <sys/types.h> |
| 11 | #include <unistd.h> |
| 12 | |
Luis Hector Chavez | 5381d00 | 2017-09-16 12:54:24 -0700 | [diff] [blame] | 13 | #include <base/files/file_path.h> |
| 14 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 15 | #include "libcontainer/test_harness.h" |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 16 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 17 | #include "libcontainer/container_cgroup.h" |
| 18 | #include "libcontainer/libcontainer.h" |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 19 | |
| 20 | static const pid_t INIT_TEST_PID = 5555; |
Chinyue Chen | 4f3fd68 | 2016-07-01 14:11:42 +0800 | [diff] [blame] | 21 | static const int TEST_CPU_SHARES = 200; |
| 22 | static const int TEST_CPU_QUOTA = 20000; |
| 23 | static const int TEST_CPU_PERIOD = 50000; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 24 | |
| 25 | struct mount_args { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 26 | char* source; |
| 27 | char* target; |
| 28 | char* filesystemtype; |
| 29 | unsigned long mountflags; |
| 30 | const void* data; |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 31 | bool outside_mount; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 32 | }; |
| 33 | static struct mount_args mount_call_args[5]; |
| 34 | static int mount_called; |
| 35 | |
| 36 | struct mknod_args { |
Luis Hector Chavez | 5381d00 | 2017-09-16 12:54:24 -0700 | [diff] [blame] | 37 | base::FilePath pathname; |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 38 | mode_t mode; |
| 39 | dev_t dev; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 40 | }; |
| 41 | static struct mknod_args mknod_call_args; |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 42 | static bool mknod_called; |
Chinyue Chen | 03c54ae | 2016-06-29 12:29:10 +0800 | [diff] [blame] | 43 | static dev_t stat_rdev_ret; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 44 | |
| 45 | static int kill_called; |
| 46 | static int kill_sig; |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 47 | static const char* minijail_alt_syscall_table; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 48 | static int minijail_ipc_called; |
| 49 | static int minijail_vfs_called; |
| 50 | static int minijail_net_called; |
| 51 | static int minijail_pids_called; |
| 52 | static int minijail_run_as_init_called; |
| 53 | static int minijail_user_called; |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 54 | static int minijail_cgroups_called; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 55 | static int minijail_wait_called; |
| 56 | static int minijail_reset_signal_mask_called; |
| 57 | static int mount_ret; |
Luis Hector Chavez | 5381d00 | 2017-09-16 12:54:24 -0700 | [diff] [blame] | 58 | static base::FilePath mkdtemp_root; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 59 | |
| 60 | /* global mock cgroup. */ |
Dylan Reid | 355d5e4 | 2016-04-29 16:53:31 -0700 | [diff] [blame] | 61 | #define MAX_ADD_DEVICE_CALLS 2 |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 62 | struct mock_cgroup { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 63 | struct container_cgroup cg; |
| 64 | int freeze_ret; |
| 65 | int thaw_ret; |
| 66 | int deny_all_devs_ret; |
| 67 | int add_device_ret; |
| 68 | int set_cpu_ret; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 69 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 70 | int init_called_count; |
| 71 | int deny_all_devs_called_count; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 72 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 73 | int add_dev_allow[MAX_ADD_DEVICE_CALLS]; |
| 74 | int add_dev_major[MAX_ADD_DEVICE_CALLS]; |
| 75 | int add_dev_minor[MAX_ADD_DEVICE_CALLS]; |
| 76 | int add_dev_read[MAX_ADD_DEVICE_CALLS]; |
| 77 | int add_dev_write[MAX_ADD_DEVICE_CALLS]; |
| 78 | int add_dev_modify[MAX_ADD_DEVICE_CALLS]; |
| 79 | char add_dev_type[MAX_ADD_DEVICE_CALLS]; |
| 80 | int add_dev_called_count; |
Chinyue Chen | fac909e | 2016-06-24 14:17:42 +0800 | [diff] [blame] | 81 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 82 | int set_cpu_shares_count; |
| 83 | int set_cpu_quota_count; |
| 84 | int set_cpu_period_count; |
| 85 | int set_cpu_rt_runtime_count; |
| 86 | int set_cpu_rt_period_count; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static struct mock_cgroup gmcg; |
| 90 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 91 | static int mock_freeze(const struct container_cgroup* cg) { |
| 92 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
| 93 | return mcg->freeze_ret; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 96 | static int mock_thaw(const struct container_cgroup* cg) { |
| 97 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
| 98 | return mcg->thaw_ret; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 101 | static int mock_deny_all_devices(const struct container_cgroup* cg) { |
| 102 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
| 103 | ++mcg->deny_all_devs_called_count; |
| 104 | return mcg->deny_all_devs_ret; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 107 | static int mock_add_device(const struct container_cgroup* cg, |
| 108 | int allow, |
| 109 | int major, |
| 110 | int minor, |
| 111 | int read, |
| 112 | int write, |
| 113 | int modify, |
| 114 | char type) { |
| 115 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
Dylan Reid | 355d5e4 | 2016-04-29 16:53:31 -0700 | [diff] [blame] | 116 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 117 | if (mcg->add_dev_called_count >= MAX_ADD_DEVICE_CALLS) |
| 118 | return mcg->add_device_ret; |
| 119 | mcg->add_dev_allow[mcg->add_dev_called_count] = allow; |
| 120 | mcg->add_dev_major[mcg->add_dev_called_count] = major; |
| 121 | mcg->add_dev_minor[mcg->add_dev_called_count] = minor; |
| 122 | mcg->add_dev_read[mcg->add_dev_called_count] = read; |
| 123 | mcg->add_dev_write[mcg->add_dev_called_count] = write; |
| 124 | mcg->add_dev_modify[mcg->add_dev_called_count] = modify; |
| 125 | mcg->add_dev_type[mcg->add_dev_called_count] = type; |
| 126 | mcg->add_dev_called_count++; |
| 127 | return mcg->add_device_ret; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 130 | static int mock_set_cpu_shares(const struct container_cgroup* cg, int shares) { |
| 131 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
| 132 | mcg->set_cpu_shares_count++; |
| 133 | return mcg->set_cpu_ret; |
Chinyue Chen | fac909e | 2016-06-24 14:17:42 +0800 | [diff] [blame] | 134 | } |
| 135 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 136 | static int mock_set_cpu_quota(const struct container_cgroup* cg, int quota) { |
| 137 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
| 138 | mcg->set_cpu_quota_count++; |
| 139 | return mcg->set_cpu_ret; |
Chinyue Chen | fac909e | 2016-06-24 14:17:42 +0800 | [diff] [blame] | 140 | } |
| 141 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 142 | static int mock_set_cpu_period(const struct container_cgroup* cg, int period) { |
| 143 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
| 144 | mcg->set_cpu_period_count++; |
| 145 | return mcg->set_cpu_ret; |
Chinyue Chen | fac909e | 2016-06-24 14:17:42 +0800 | [diff] [blame] | 146 | } |
| 147 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 148 | static int mock_set_cpu_rt_runtime(const struct container_cgroup* cg, |
| 149 | int rt_runtime) { |
| 150 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
| 151 | mcg->set_cpu_rt_runtime_count++; |
| 152 | return mcg->set_cpu_ret; |
Chinyue Chen | fac909e | 2016-06-24 14:17:42 +0800 | [diff] [blame] | 153 | } |
| 154 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 155 | static int mock_set_cpu_rt_period(const struct container_cgroup* cg, |
| 156 | int rt_period) { |
| 157 | struct mock_cgroup* mcg = (struct mock_cgroup*)cg; |
| 158 | mcg->set_cpu_rt_period_count++; |
| 159 | return mcg->set_cpu_ret; |
Chinyue Chen | fac909e | 2016-06-24 14:17:42 +0800 | [diff] [blame] | 160 | } |
| 161 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 162 | struct container_cgroup* container_cgroup_new(const char* name, |
| 163 | const char* cgroup_root, |
| 164 | const char* cgroup_parent, |
| 165 | uid_t uid, |
| 166 | gid_t gid) { |
| 167 | gmcg.cg.name = strdup(name); |
| 168 | return &gmcg.cg; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 171 | void container_cgroup_destroy(struct container_cgroup* c) { |
| 172 | free(c->name); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 175 | TEST(premounted_runfs) { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 176 | char premounted_runfs[] = "/tmp/cgtest_run/root"; |
| 177 | struct container_config* config = container_config_create(); |
| 178 | ASSERT_NE(nullptr, config); |
Keshav Santhanam | 0e4c328 | 2016-07-14 10:25:16 -0700 | [diff] [blame] | 179 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 180 | container_config_premounted_runfs(config, premounted_runfs); |
| 181 | const char* result = container_config_get_premounted_runfs(config); |
| 182 | ASSERT_EQ(0, strcmp(result, premounted_runfs)); |
Keshav Santhanam | 0e4c328 | 2016-07-14 10:25:16 -0700 | [diff] [blame] | 183 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 184 | container_config_destroy(config); |
Keshav Santhanam | 0e4c328 | 2016-07-14 10:25:16 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 187 | TEST(pid_file_path) { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 188 | char pid_file_path[] = "/tmp/cgtest_run/root/container.pid"; |
| 189 | struct container_config* config = container_config_create(); |
| 190 | ASSERT_NE(nullptr, config); |
Keshav Santhanam | 0e4c328 | 2016-07-14 10:25:16 -0700 | [diff] [blame] | 191 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 192 | container_config_pid_file(config, pid_file_path); |
| 193 | const char* result = container_config_get_pid_file(config); |
| 194 | ASSERT_EQ(0, strcmp(result, pid_file_path)); |
Keshav Santhanam | 0e4c328 | 2016-07-14 10:25:16 -0700 | [diff] [blame] | 195 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 196 | container_config_destroy(config); |
Keshav Santhanam | 0e4c328 | 2016-07-14 10:25:16 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 199 | /* Start of tests. */ |
| 200 | FIXTURE(container_test) { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 201 | struct container_config* config; |
| 202 | struct container* container; |
| 203 | int mount_flags; |
| 204 | char* rootfs; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 205 | }; |
| 206 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 207 | FIXTURE_SETUP(container_test) { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 208 | char temp_template[] = "/tmp/cgtestXXXXXX"; |
| 209 | char rundir_template[] = "/tmp/cgtest_runXXXXXX"; |
| 210 | char* rundir; |
| 211 | char path[256]; |
| 212 | const char* pargs[] = { |
| 213 | "/sbin/init", |
| 214 | }; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 215 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 216 | memset(&mount_call_args, 0, sizeof(mount_call_args)); |
| 217 | mount_called = 0; |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 218 | mknod_called = false; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 219 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 220 | memset(&gmcg, 0, sizeof(gmcg)); |
| 221 | static const struct cgroup_ops cgops = { |
| 222 | .freeze = mock_freeze, |
| 223 | .thaw = mock_thaw, |
| 224 | .deny_all_devices = mock_deny_all_devices, |
| 225 | .add_device = mock_add_device, |
| 226 | .set_cpu_shares = mock_set_cpu_shares, |
| 227 | .set_cpu_quota = mock_set_cpu_quota, |
| 228 | .set_cpu_period = mock_set_cpu_period, |
| 229 | .set_cpu_rt_runtime = mock_set_cpu_rt_runtime, |
| 230 | .set_cpu_rt_period = mock_set_cpu_rt_period, |
| 231 | }; |
| 232 | gmcg.cg.ops = &cgops; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 233 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 234 | self->rootfs = strdup(mkdtemp(temp_template)); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 235 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 236 | kill_called = 0; |
| 237 | minijail_alt_syscall_table = nullptr; |
| 238 | minijail_ipc_called = 0; |
| 239 | minijail_vfs_called = 0; |
| 240 | minijail_net_called = 0; |
| 241 | minijail_pids_called = 0; |
| 242 | minijail_run_as_init_called = 0; |
| 243 | minijail_user_called = 0; |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 244 | minijail_cgroups_called = 0; |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 245 | minijail_wait_called = 0; |
| 246 | minijail_reset_signal_mask_called = 0; |
| 247 | mount_ret = 0; |
| 248 | stat_rdev_ret = makedev(2, 3); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 249 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 250 | snprintf(path, sizeof(path), "%s/dev", self->rootfs); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 251 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 252 | self->mount_flags = MS_NOSUID | MS_NODEV | MS_NOEXEC; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 253 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 254 | self->config = container_config_create(); |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 255 | container_config_uid_map(self->config, "0 0 4294967295"); |
| 256 | container_config_gid_map(self->config, "0 0 4294967295"); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 257 | container_config_rootfs(self->config, self->rootfs); |
| 258 | container_config_program_argv(self->config, pargs, 1); |
| 259 | container_config_alt_syscall_table(self->config, "testsyscalltable"); |
| 260 | container_config_add_mount(self->config, |
| 261 | "testtmpfs", |
| 262 | "tmpfs", |
| 263 | "/tmp", |
| 264 | "tmpfs", |
| 265 | nullptr, |
| 266 | nullptr, |
| 267 | self->mount_flags, |
| 268 | 0, |
| 269 | 1000, |
| 270 | 1000, |
| 271 | 0x666, |
| 272 | 0, |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 273 | 0); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 274 | container_config_add_device(self->config, |
| 275 | 'c', |
| 276 | "/dev/foo", |
| 277 | S_IRWXU | S_IRWXG, |
| 278 | 245, |
| 279 | 2, |
| 280 | 0, |
| 281 | 1000, |
| 282 | 1001, |
| 283 | 1, |
| 284 | 1, |
| 285 | 0); |
| 286 | /* test dynamic minor on /dev/null */ |
| 287 | container_config_add_device(self->config, |
| 288 | 'c', |
| 289 | "/dev/null", |
| 290 | S_IRWXU | S_IRWXG, |
| 291 | 1, |
| 292 | -1, |
| 293 | 1, |
| 294 | 1000, |
| 295 | 1001, |
| 296 | 1, |
| 297 | 1, |
| 298 | 0); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 299 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 300 | container_config_set_cpu_shares(self->config, TEST_CPU_SHARES); |
| 301 | container_config_set_cpu_cfs_params( |
| 302 | self->config, TEST_CPU_QUOTA, TEST_CPU_PERIOD); |
| 303 | /* Invalid params, so this won't be applied. */ |
| 304 | container_config_set_cpu_rt_params(self->config, 20000, 20000); |
Chinyue Chen | fac909e | 2016-06-24 14:17:42 +0800 | [diff] [blame] | 305 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 306 | rundir = mkdtemp(rundir_template); |
| 307 | self->container = container_new("containerUT", rundir); |
| 308 | ASSERT_NE(nullptr, self->container); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 311 | FIXTURE_TEARDOWN(container_test) { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 312 | char path[256]; |
| 313 | int i; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 314 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 315 | container_destroy(self->container); |
| 316 | snprintf(path, sizeof(path), "rm -rf %s", self->rootfs); |
| 317 | EXPECT_EQ(0, system(path)); |
| 318 | free(self->rootfs); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 319 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 320 | for (i = 0; i < mount_called; i++) { |
| 321 | free(mount_call_args[i].source); |
| 322 | free(mount_call_args[i].target); |
| 323 | free(mount_call_args[i].filesystemtype); |
| 324 | } |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 327 | TEST_F(container_test, test_mount_tmp_start) { |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 328 | ASSERT_EQ(0, container_start(self->container, self->config)); |
| 329 | ASSERT_EQ(2, mount_called); |
| 330 | EXPECT_EQ(false, mount_call_args[1].outside_mount); |
| 331 | EXPECT_STREQ("tmpfs", mount_call_args[1].source); |
| 332 | EXPECT_STREQ("/tmp", mount_call_args[1].target); |
| 333 | EXPECT_STREQ("tmpfs", mount_call_args[1].filesystemtype); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 334 | EXPECT_EQ(mount_call_args[1].mountflags, |
| 335 | static_cast<unsigned long>(self->mount_flags)); |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 336 | EXPECT_EQ(nullptr, mount_call_args[1].data); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 337 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 338 | EXPECT_EQ(1, minijail_ipc_called); |
| 339 | EXPECT_EQ(1, minijail_vfs_called); |
| 340 | EXPECT_EQ(1, minijail_net_called); |
| 341 | EXPECT_EQ(1, minijail_pids_called); |
| 342 | EXPECT_EQ(1, minijail_user_called); |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 343 | EXPECT_EQ(1, minijail_cgroups_called); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 344 | EXPECT_EQ(1, minijail_run_as_init_called); |
| 345 | EXPECT_EQ(1, gmcg.deny_all_devs_called_count); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 346 | |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 347 | ASSERT_EQ(2, gmcg.add_dev_called_count); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 348 | EXPECT_EQ(1, gmcg.add_dev_allow[0]); |
| 349 | EXPECT_EQ(245, gmcg.add_dev_major[0]); |
| 350 | EXPECT_EQ(2, gmcg.add_dev_minor[0]); |
| 351 | EXPECT_EQ(1, gmcg.add_dev_read[0]); |
| 352 | EXPECT_EQ(1, gmcg.add_dev_write[0]); |
| 353 | EXPECT_EQ(0, gmcg.add_dev_modify[0]); |
| 354 | EXPECT_EQ('c', gmcg.add_dev_type[0]); |
Dylan Reid | 355d5e4 | 2016-04-29 16:53:31 -0700 | [diff] [blame] | 355 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 356 | EXPECT_EQ(1, gmcg.add_dev_allow[1]); |
| 357 | EXPECT_EQ(1, gmcg.add_dev_major[1]); |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 358 | EXPECT_EQ(-1, gmcg.add_dev_minor[1]); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 359 | EXPECT_EQ(1, gmcg.add_dev_read[1]); |
| 360 | EXPECT_EQ(1, gmcg.add_dev_write[1]); |
| 361 | EXPECT_EQ(0, gmcg.add_dev_modify[1]); |
| 362 | EXPECT_EQ('c', gmcg.add_dev_type[1]); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 363 | |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 364 | ASSERT_EQ(true, mknod_called); |
Manoj Gupta | ea9a50b | 2017-09-20 21:06:43 -0700 | [diff] [blame] | 365 | EXPECT_STREQ(mkdtemp_root.Append("root/dev/null").value().c_str(), |
| 366 | mknod_call_args.pathname.value().c_str()); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 367 | EXPECT_EQ(mknod_call_args.mode, |
| 368 | static_cast<mode_t>(S_IRWXU | S_IRWXG | S_IFCHR)); |
| 369 | EXPECT_EQ(mknod_call_args.dev, makedev(1, 3)); |
Chinyue Chen | 03c54ae | 2016-06-29 12:29:10 +0800 | [diff] [blame] | 370 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 371 | EXPECT_EQ(1, gmcg.set_cpu_shares_count); |
| 372 | EXPECT_EQ(TEST_CPU_SHARES, container_config_get_cpu_shares(self->config)); |
| 373 | EXPECT_EQ(1, gmcg.set_cpu_quota_count); |
| 374 | EXPECT_EQ(TEST_CPU_QUOTA, container_config_get_cpu_quota(self->config)); |
| 375 | EXPECT_EQ(1, gmcg.set_cpu_period_count); |
| 376 | EXPECT_EQ(TEST_CPU_PERIOD, container_config_get_cpu_period(self->config)); |
| 377 | EXPECT_EQ(0, gmcg.set_cpu_rt_runtime_count); |
| 378 | EXPECT_EQ(0, container_config_get_cpu_rt_runtime(self->config)); |
| 379 | EXPECT_EQ(0, gmcg.set_cpu_rt_period_count); |
| 380 | EXPECT_EQ(0, container_config_get_cpu_rt_period(self->config)); |
Chinyue Chen | fac909e | 2016-06-24 14:17:42 +0800 | [diff] [blame] | 381 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 382 | ASSERT_NE(nullptr, minijail_alt_syscall_table); |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 383 | EXPECT_STREQ("testsyscalltable", minijail_alt_syscall_table); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 384 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 385 | EXPECT_EQ(0, container_wait(self->container)); |
| 386 | EXPECT_EQ(1, minijail_wait_called); |
| 387 | EXPECT_EQ(1, minijail_reset_signal_mask_called); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 390 | TEST_F(container_test, test_kill_container) { |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 391 | ASSERT_EQ(0, container_start(self->container, self->config)); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 392 | EXPECT_EQ(0, container_kill(self->container)); |
| 393 | EXPECT_EQ(1, kill_called); |
| 394 | EXPECT_EQ(SIGKILL, kill_sig); |
| 395 | EXPECT_EQ(1, minijail_wait_called); |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* libc stubs so the UT doesn't need root to call mount, etc. */ |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 399 | extern "C" { |
| 400 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 401 | int mount(const char* source, |
| 402 | const char* target, |
| 403 | const char* filesystemtype, |
| 404 | unsigned long mountflags, |
| 405 | const void* data) { |
| 406 | if (mount_called >= 5) |
| 407 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 408 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 409 | mount_call_args[mount_called].source = strdup(source); |
| 410 | mount_call_args[mount_called].target = strdup(target); |
| 411 | mount_call_args[mount_called].filesystemtype = strdup(filesystemtype); |
| 412 | mount_call_args[mount_called].mountflags = mountflags; |
| 413 | mount_call_args[mount_called].data = data; |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 414 | mount_call_args[mount_called].outside_mount = true; |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 415 | ++mount_called; |
| 416 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 417 | } |
| 418 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 419 | int umount(const char* target) { |
| 420 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 423 | int umount2(const char* target, int flags) { |
| 424 | return 0; |
| 425 | } |
| 426 | |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 427 | #ifdef __USE_EXTERN_INLINES |
| 428 | /* Some environments use an inline version of mknod. */ |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 429 | int __xmknod(int ver, const char* pathname, __mode_t mode, __dev_t* dev) |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 430 | #else |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 431 | int mknod(const char* pathname, mode_t mode, dev_t dev) |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 432 | #endif |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 433 | { |
Luis Hector Chavez | 5381d00 | 2017-09-16 12:54:24 -0700 | [diff] [blame] | 434 | mknod_call_args.pathname = base::FilePath(pathname); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 435 | mknod_call_args.mode = mode; |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 436 | #ifdef __USE_EXTERN_INLINES |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 437 | mknod_call_args.dev = *dev; |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 438 | #else |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 439 | mknod_call_args.dev = dev; |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 440 | #endif |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 441 | mknod_called = true; |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 442 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 443 | } |
| 444 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 445 | int chown(const char* path, uid_t owner, gid_t group) { |
| 446 | return 0; |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 447 | } |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 448 | |
Luis Hector Chavez | 836d7b2 | 2017-09-14 15:11:15 -0700 | [diff] [blame] | 449 | int kill(pid_t pid, int sig) { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 450 | ++kill_called; |
| 451 | kill_sig = sig; |
| 452 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 455 | #ifdef __USE_EXTERN_INLINES |
| 456 | /* Some environments use an inline version of stat. */ |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 457 | int __xstat(int ver, const char* path, struct stat* buf) |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 458 | #else |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 459 | int stat(const char* path, struct stat* buf) |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 460 | #endif |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 461 | { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 462 | buf->st_rdev = stat_rdev_ret; |
| 463 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 466 | int chmod(const char* path, mode_t mode) { |
| 467 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 470 | char* mkdtemp(char* template_string) { |
Luis Hector Chavez | 5381d00 | 2017-09-16 12:54:24 -0700 | [diff] [blame] | 471 | mkdtemp_root = base::FilePath(template_string); |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 472 | return template_string; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 475 | int mkdir(const char* pathname, mode_t mode) { |
| 476 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 479 | int rmdir(const char* pathname) { |
| 480 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 483 | int unlink(const char* pathname) { |
| 484 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 487 | uid_t getuid(void) { |
| 488 | return 0; |
| 489 | } |
| 490 | |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 491 | /* Minijail stubs */ |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 492 | struct minijail* minijail_new(void) { |
| 493 | return (struct minijail*)0x55; |
Chinyue Chen | 03c54ae | 2016-06-29 12:29:10 +0800 | [diff] [blame] | 494 | } |
| 495 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 496 | void minijail_destroy(struct minijail* j) {} |
| 497 | |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 498 | int minijail_mount_with_data(struct minijail* j, |
| 499 | const char* source, |
| 500 | const char* target, |
| 501 | const char* filesystemtype, |
| 502 | unsigned long mountflags, |
| 503 | const char* data) { |
| 504 | if (mount_called >= 5) |
| 505 | return 0; |
| 506 | |
| 507 | mount_call_args[mount_called].source = strdup(source); |
| 508 | mount_call_args[mount_called].target = strdup(target); |
| 509 | mount_call_args[mount_called].filesystemtype = strdup(filesystemtype); |
| 510 | mount_call_args[mount_called].mountflags = mountflags; |
| 511 | mount_call_args[mount_called].data = data; |
| 512 | mount_call_args[mount_called].outside_mount = false; |
| 513 | ++mount_called; |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | int minijail_namespace_user_disable_setgroups(struct minijail* j) { |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 518 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 521 | void minijail_namespace_vfs(struct minijail* j) { |
| 522 | ++minijail_vfs_called; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 525 | void minijail_namespace_ipc(struct minijail* j) { |
| 526 | ++minijail_ipc_called; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 527 | } |
| 528 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 529 | void minijail_namespace_net(struct minijail* j) { |
| 530 | ++minijail_net_called; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 533 | void minijail_namespace_pids(struct minijail* j) { |
| 534 | ++minijail_pids_called; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 535 | } |
| 536 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 537 | void minijail_namespace_user(struct minijail* j) { |
| 538 | ++minijail_user_called; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 541 | void minijail_namespace_cgroups(struct minijail* j) { |
| 542 | ++minijail_cgroups_called; |
| 543 | } |
| 544 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 545 | int minijail_uidmap(struct minijail* j, const char* uidmap) { |
| 546 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 549 | int minijail_gidmap(struct minijail* j, const char* gidmap) { |
| 550 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 551 | } |
| 552 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 553 | int minijail_enter_pivot_root(struct minijail* j, const char* dir) { |
| 554 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 557 | void minijail_run_as_init(struct minijail* j) { |
| 558 | ++minijail_run_as_init_called; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 561 | int minijail_run_pid_pipes_no_preload(struct minijail* j, |
| 562 | const char* filename, |
| 563 | char* const argv[], |
| 564 | pid_t* pchild_pid, |
| 565 | int* pstdin_fd, |
| 566 | int* pstdout_fd, |
| 567 | int* pstderr_fd) { |
| 568 | *pchild_pid = INIT_TEST_PID; |
| 569 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 570 | } |
| 571 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 572 | int minijail_write_pid_file(struct minijail* j, const char* path) { |
| 573 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 576 | int minijail_wait(struct minijail* j) { |
| 577 | ++minijail_wait_called; |
| 578 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 579 | } |
| 580 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 581 | int minijail_use_alt_syscall(struct minijail* j, const char* table) { |
| 582 | minijail_alt_syscall_table = table; |
| 583 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 584 | } |
| 585 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 586 | int minijail_add_to_cgroup(struct minijail* j, const char* cg_path) { |
| 587 | return 0; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 590 | void minijail_reset_signal_mask(struct minijail* j) { |
| 591 | ++minijail_reset_signal_mask_called; |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 594 | void minijail_skip_remount_private(struct minijail* j) {} |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 595 | |
Luis Hector Chavez | 9e03e17 | 2017-09-15 11:29:54 -0700 | [diff] [blame] | 596 | void minijail_close_open_fds(struct minijail* j) {} |
| 597 | |
Luis Hector Chavez | 31735bc | 2017-09-15 08:17:10 -0700 | [diff] [blame] | 598 | } // extern "C" |
Luis Hector Chavez | f9b1687 | 2017-09-14 14:22:15 -0700 | [diff] [blame] | 599 | |
Dylan Reid | 837c74a | 2016-01-22 17:25:21 -0800 | [diff] [blame] | 600 | TEST_HARNESS_MAIN |