Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google, Inc |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "libprocessgroup" |
| 19 | |
| 20 | #include <assert.h> |
| 21 | #include <dirent.h> |
Elliott Hughes | 0badbd6 | 2014-12-29 12:24:25 -0800 | [diff] [blame] | 22 | #include <errno.h> |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 23 | #include <fcntl.h> |
Chih-Hung Hsieh | fcc8115 | 2014-11-20 17:05:15 -0800 | [diff] [blame] | 24 | #include <inttypes.h> |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 25 | #include <mutex> |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 26 | #include <stdbool.h> |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <sys/types.h> |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 32 | #include <memory> |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 33 | |
| 34 | #include <log/log.h> |
| 35 | #include <private/android_filesystem_config.h> |
| 36 | |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 37 | #include <utils/SystemClock.h> |
| 38 | |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 39 | #include <processgroup/processgroup.h> |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 40 | |
Martijn Coenen | 5bb91ab | 2016-03-18 15:28:31 +0100 | [diff] [blame] | 41 | // Uncomment line below use memory cgroups for keeping track of (forked) PIDs |
| 42 | // #define USE_MEMCG 1 |
| 43 | |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 44 | #define MEM_CGROUP_PATH "/dev/memcg/apps" |
Martijn Coenen | 623b56a | 2016-02-08 11:42:25 +0100 | [diff] [blame] | 45 | #define MEM_CGROUP_TASKS "/dev/memcg/apps/tasks" |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 46 | #define ACCT_CGROUP_PATH "/acct" |
| 47 | |
| 48 | #define PROCESSGROUP_UID_PREFIX "uid_" |
| 49 | #define PROCESSGROUP_PID_PREFIX "pid_" |
| 50 | #define PROCESSGROUP_CGROUP_PROCS_FILE "/cgroup.procs" |
| 51 | #define PROCESSGROUP_MAX_UID_LEN 11 |
| 52 | #define PROCESSGROUP_MAX_PID_LEN 11 |
| 53 | #define PROCESSGROUP_MAX_PATH_LEN \ |
| 54 | ((sizeof(MEM_CGROUP_PATH) > sizeof(ACCT_CGROUP_PATH) ? \ |
| 55 | sizeof(MEM_CGROUP_PATH) : sizeof(ACCT_CGROUP_PATH)) + \ |
| 56 | sizeof(PROCESSGROUP_UID_PREFIX) + 1 + \ |
| 57 | PROCESSGROUP_MAX_UID_LEN + \ |
| 58 | sizeof(PROCESSGROUP_PID_PREFIX) + 1 + \ |
| 59 | PROCESSGROUP_MAX_PID_LEN + \ |
| 60 | sizeof(PROCESSGROUP_CGROUP_PROCS_FILE) + \ |
| 61 | 1) |
| 62 | |
| 63 | std::once_flag init_path_flag; |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 64 | |
| 65 | struct ctx { |
| 66 | bool initialized; |
| 67 | int fd; |
| 68 | char buf[128]; |
| 69 | char *buf_ptr; |
| 70 | size_t buf_len; |
| 71 | }; |
| 72 | |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 73 | static const char* getCgroupRootPath() { |
Martijn Coenen | 5bb91ab | 2016-03-18 15:28:31 +0100 | [diff] [blame] | 74 | #ifdef USE_MEMCG |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 75 | static const char* cgroup_root_path = NULL; |
| 76 | std::call_once(init_path_flag, [&]() { |
Martijn Coenen | 623b56a | 2016-02-08 11:42:25 +0100 | [diff] [blame] | 77 | // Check if mem cgroup is mounted, only then check for write-access to avoid |
| 78 | // SELinux denials |
| 79 | cgroup_root_path = access(MEM_CGROUP_TASKS, F_OK) || access(MEM_CGROUP_PATH, W_OK) ? |
| 80 | ACCT_CGROUP_PATH : MEM_CGROUP_PATH; |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 81 | }); |
| 82 | return cgroup_root_path; |
Martijn Coenen | 5bb91ab | 2016-03-18 15:28:31 +0100 | [diff] [blame] | 83 | #else |
| 84 | return ACCT_CGROUP_PATH; |
| 85 | #endif |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 88 | static int convertUidToPath(char *path, size_t size, uid_t uid) |
| 89 | { |
| 90 | return snprintf(path, size, "%s/%s%d", |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 91 | getCgroupRootPath(), |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 92 | PROCESSGROUP_UID_PREFIX, |
| 93 | uid); |
| 94 | } |
| 95 | |
| 96 | static int convertUidPidToPath(char *path, size_t size, uid_t uid, int pid) |
| 97 | { |
| 98 | return snprintf(path, size, "%s/%s%d/%s%d", |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 99 | getCgroupRootPath(), |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 100 | PROCESSGROUP_UID_PREFIX, |
| 101 | uid, |
| 102 | PROCESSGROUP_PID_PREFIX, |
| 103 | pid); |
| 104 | } |
| 105 | |
| 106 | static int initCtx(uid_t uid, int pid, struct ctx *ctx) |
| 107 | { |
| 108 | int ret; |
| 109 | char path[PROCESSGROUP_MAX_PATH_LEN] = {0}; |
| 110 | convertUidPidToPath(path, sizeof(path), uid, pid); |
| 111 | strlcat(path, PROCESSGROUP_CGROUP_PROCS_FILE, sizeof(path)); |
| 112 | |
| 113 | int fd = open(path, O_RDONLY); |
| 114 | if (fd < 0) { |
| 115 | ret = -errno; |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 116 | SLOGW("failed to open %s: %s", path, strerror(errno)); |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 117 | return ret; |
| 118 | } |
| 119 | |
| 120 | ctx->fd = fd; |
| 121 | ctx->buf_ptr = ctx->buf; |
| 122 | ctx->buf_len = 0; |
| 123 | ctx->initialized = true; |
| 124 | |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 125 | SLOGV("Initialized context for %s", path); |
| 126 | |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static int refillBuffer(struct ctx *ctx) |
| 131 | { |
| 132 | memmove(ctx->buf, ctx->buf_ptr, ctx->buf_len); |
| 133 | ctx->buf_ptr = ctx->buf; |
| 134 | |
| 135 | ssize_t ret = read(ctx->fd, ctx->buf_ptr + ctx->buf_len, |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 136 | sizeof(ctx->buf) - ctx->buf_len - 1); |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 137 | if (ret < 0) { |
| 138 | return -errno; |
| 139 | } else if (ret == 0) { |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | ctx->buf_len += ret; |
Dianne Hackborn | 67f46cb | 2014-10-15 11:36:28 -0700 | [diff] [blame] | 144 | ctx->buf[ctx->buf_len] = 0; |
Chih-Hung Hsieh | fcc8115 | 2014-11-20 17:05:15 -0800 | [diff] [blame] | 145 | SLOGV("Read %zd to buffer: %s", ret, ctx->buf); |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 146 | |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 147 | assert(ctx->buf_len <= sizeof(ctx->buf)); |
| 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
| 152 | static pid_t getOneAppProcess(uid_t uid, int appProcessPid, struct ctx *ctx) |
| 153 | { |
| 154 | if (!ctx->initialized) { |
| 155 | int ret = initCtx(uid, appProcessPid, ctx); |
| 156 | if (ret < 0) { |
| 157 | return ret; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | char *eptr; |
| 162 | while ((eptr = (char *)memchr(ctx->buf_ptr, '\n', ctx->buf_len)) == NULL) { |
| 163 | int ret = refillBuffer(ctx); |
| 164 | if (ret == 0) { |
| 165 | return -ERANGE; |
| 166 | } |
| 167 | if (ret < 0) { |
| 168 | return ret; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | *eptr = '\0'; |
| 173 | char *pid_eptr = NULL; |
| 174 | errno = 0; |
| 175 | long pid = strtol(ctx->buf_ptr, &pid_eptr, 10); |
| 176 | if (errno != 0) { |
| 177 | return -errno; |
| 178 | } |
| 179 | if (pid_eptr != eptr) { |
| 180 | return -EINVAL; |
| 181 | } |
| 182 | |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 183 | ctx->buf_len -= (eptr - ctx->buf_ptr) + 1; |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 184 | ctx->buf_ptr = eptr + 1; |
| 185 | |
| 186 | return (pid_t)pid; |
| 187 | } |
| 188 | |
| 189 | static int removeProcessGroup(uid_t uid, int pid) |
| 190 | { |
| 191 | int ret; |
| 192 | char path[PROCESSGROUP_MAX_PATH_LEN] = {0}; |
| 193 | |
| 194 | convertUidPidToPath(path, sizeof(path), uid, pid); |
| 195 | ret = rmdir(path); |
| 196 | |
| 197 | convertUidToPath(path, sizeof(path), uid); |
| 198 | rmdir(path); |
| 199 | |
| 200 | return ret; |
| 201 | } |
| 202 | |
| 203 | static void removeUidProcessGroups(const char *uid_path) |
| 204 | { |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 205 | std::unique_ptr<DIR, decltype(&closedir)> uid(opendir(uid_path), closedir); |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 206 | if (uid != NULL) { |
| 207 | struct dirent cur; |
| 208 | struct dirent *dir; |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 209 | while ((readdir_r(uid.get(), &cur, &dir) == 0) && dir) { |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 210 | char path[PROCESSGROUP_MAX_PATH_LEN]; |
| 211 | |
| 212 | if (dir->d_type != DT_DIR) { |
| 213 | continue; |
| 214 | } |
| 215 | |
| 216 | if (strncmp(dir->d_name, PROCESSGROUP_PID_PREFIX, strlen(PROCESSGROUP_PID_PREFIX))) { |
| 217 | continue; |
| 218 | } |
| 219 | |
| 220 | snprintf(path, sizeof(path), "%s/%s", uid_path, dir->d_name); |
| 221 | SLOGV("removing %s\n", path); |
| 222 | rmdir(path); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | void removeAllProcessGroups() |
| 228 | { |
| 229 | SLOGV("removeAllProcessGroups()"); |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 230 | const char *cgroup_root_path = getCgroupRootPath(); |
James Hawkins | 22b6f7a | 2016-02-19 11:10:30 -0800 | [diff] [blame] | 231 | std::unique_ptr<DIR, decltype(&closedir)> root(opendir(cgroup_root_path), closedir); |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 232 | if (root == NULL) { |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 233 | SLOGE("failed to open %s: %s", cgroup_root_path, strerror(errno)); |
Colin Cross | c15dd04 | 2014-08-20 14:11:13 -0700 | [diff] [blame] | 234 | } else { |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 235 | struct dirent cur; |
| 236 | struct dirent *dir; |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 237 | while ((readdir_r(root.get(), &cur, &dir) == 0) && dir) { |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 238 | char path[PROCESSGROUP_MAX_PATH_LEN]; |
| 239 | |
| 240 | if (dir->d_type != DT_DIR) { |
| 241 | continue; |
| 242 | } |
| 243 | if (strncmp(dir->d_name, PROCESSGROUP_UID_PREFIX, strlen(PROCESSGROUP_UID_PREFIX))) { |
| 244 | continue; |
| 245 | } |
| 246 | |
Martijn Coenen | b82bab6 | 2016-01-20 16:39:16 -0800 | [diff] [blame] | 247 | snprintf(path, sizeof(path), "%s/%s", cgroup_root_path, dir->d_name); |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 248 | removeUidProcessGroups(path); |
| 249 | SLOGV("removing %s\n", path); |
| 250 | rmdir(path); |
| 251 | } |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
| 255 | static int killProcessGroupOnce(uid_t uid, int initialPid, int signal) |
| 256 | { |
| 257 | int processes = 0; |
| 258 | struct ctx ctx; |
| 259 | pid_t pid; |
| 260 | |
| 261 | ctx.initialized = false; |
| 262 | |
| 263 | while ((pid = getOneAppProcess(uid, initialPid, &ctx)) >= 0) { |
| 264 | processes++; |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 265 | if (pid == 0) { |
| 266 | // Should never happen... but if it does, trying to kill this |
| 267 | // will boomerang right back and kill us! Let's not let that happen. |
| 268 | SLOGW("Yikes, we've been told to kill pid 0! How about we don't do that."); |
| 269 | continue; |
| 270 | } |
| 271 | if (pid != initialPid) { |
| 272 | // We want to be noisy about killing processes so we can understand |
| 273 | // what is going on in the log; however, don't be noisy about the base |
| 274 | // process, since that it something we always kill, and we have already |
| 275 | // logged elsewhere about killing it. |
| 276 | SLOGI("Killing pid %d in uid %d as part of process group %d", pid, uid, initialPid); |
| 277 | } |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 278 | int ret = kill(pid, signal); |
| 279 | if (ret == -1) { |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 280 | SLOGW("failed to kill pid %d: %s", pid, strerror(errno)); |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | if (ctx.initialized) { |
| 285 | close(ctx.fd); |
| 286 | } |
| 287 | |
| 288 | return processes; |
| 289 | } |
| 290 | |
| 291 | int killProcessGroup(uid_t uid, int initialPid, int signal) |
| 292 | { |
| 293 | int processes; |
Yusuke Sato | d503930 | 2015-06-16 13:51:14 -0700 | [diff] [blame] | 294 | const int sleep_us = 5 * 1000; // 5ms |
Chih-Hung Hsieh | fcc8115 | 2014-11-20 17:05:15 -0800 | [diff] [blame] | 295 | int64_t startTime = android::uptimeMillis(); |
Yusuke Sato | d503930 | 2015-06-16 13:51:14 -0700 | [diff] [blame] | 296 | int retry = 40; |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 297 | |
| 298 | while ((processes = killProcessGroupOnce(uid, initialPid, signal)) > 0) { |
| 299 | SLOGV("killed %d processes for processgroup %d\n", processes, initialPid); |
Yusuke Sato | d503930 | 2015-06-16 13:51:14 -0700 | [diff] [blame] | 300 | if (retry > 0) { |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 301 | usleep(sleep_us); |
Yusuke Sato | d503930 | 2015-06-16 13:51:14 -0700 | [diff] [blame] | 302 | --retry; |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 303 | } else { |
| 304 | SLOGE("failed to kill %d processes for processgroup %d\n", |
| 305 | processes, initialPid); |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
Chih-Hung Hsieh | fcc8115 | 2014-11-20 17:05:15 -0800 | [diff] [blame] | 310 | SLOGV("Killed process group uid %d pid %d in %" PRId64 "ms, %d procs remain", uid, initialPid, |
Dianne Hackborn | 2c5e7e1 | 2014-10-13 17:45:22 -0700 | [diff] [blame] | 311 | android::uptimeMillis()-startTime, processes); |
| 312 | |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 313 | if (processes == 0) { |
| 314 | return removeProcessGroup(uid, initialPid); |
| 315 | } else { |
| 316 | return -1; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | static int mkdirAndChown(const char *path, mode_t mode, uid_t uid, gid_t gid) |
| 321 | { |
| 322 | int ret; |
| 323 | |
Bernhard Rosenkränzer | 758aeb7 | 2014-11-17 20:46:00 +0100 | [diff] [blame] | 324 | ret = mkdir(path, mode); |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 325 | if (ret < 0 && errno != EEXIST) { |
| 326 | return -errno; |
| 327 | } |
| 328 | |
Bernhard Rosenkränzer | 758aeb7 | 2014-11-17 20:46:00 +0100 | [diff] [blame] | 329 | ret = chown(path, uid, gid); |
Colin Cross | cf8d1c2 | 2014-06-03 13:24:21 -0700 | [diff] [blame] | 330 | if (ret < 0) { |
| 331 | ret = -errno; |
| 332 | rmdir(path); |
| 333 | return ret; |
| 334 | } |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | int createProcessGroup(uid_t uid, int initialPid) |
| 340 | { |
| 341 | char path[PROCESSGROUP_MAX_PATH_LEN] = {0}; |
| 342 | int ret; |
| 343 | |
| 344 | convertUidToPath(path, sizeof(path), uid); |
| 345 | |
| 346 | ret = mkdirAndChown(path, 0750, AID_SYSTEM, AID_SYSTEM); |
| 347 | if (ret < 0) { |
| 348 | SLOGE("failed to make and chown %s: %s", path, strerror(-ret)); |
| 349 | return ret; |
| 350 | } |
| 351 | |
| 352 | convertUidPidToPath(path, sizeof(path), uid, initialPid); |
| 353 | |
| 354 | ret = mkdirAndChown(path, 0750, AID_SYSTEM, AID_SYSTEM); |
| 355 | if (ret < 0) { |
| 356 | SLOGE("failed to make and chown %s: %s", path, strerror(-ret)); |
| 357 | return ret; |
| 358 | } |
| 359 | |
| 360 | strlcat(path, PROCESSGROUP_CGROUP_PROCS_FILE, sizeof(path)); |
| 361 | |
| 362 | int fd = open(path, O_WRONLY); |
| 363 | if (fd < 0) { |
| 364 | ret = -errno; |
| 365 | SLOGE("failed to open %s: %s", path, strerror(errno)); |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | char pid[PROCESSGROUP_MAX_PID_LEN + 1] = {0}; |
| 370 | int len = snprintf(pid, sizeof(pid), "%d", initialPid); |
| 371 | |
| 372 | ret = write(fd, pid, len); |
| 373 | if (ret < 0) { |
| 374 | ret = -errno; |
| 375 | SLOGE("failed to write '%s' to %s: %s", pid, path, strerror(errno)); |
| 376 | } else { |
| 377 | ret = 0; |
| 378 | } |
| 379 | |
| 380 | close(fd); |
| 381 | return ret; |
| 382 | } |
| 383 | |