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