summaryrefslogtreecommitdiff
path: root/init/service_utils.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2019-07-08 15:09:36 -0700
committerTom Cherry <tomcherry@google.com>2019-07-09 16:17:36 +0000
commit247ffbf3140a454fb2facf0e66ca1547e0833797 (patch)
tree4ab9a5713994334ae650f64730f939de1950e53b /init/service_utils.cpp
parent0e04ce98ef9ffdba486c33589b6c0f4922c4152c (diff)
Fix a few clang-tidy issues and add NOLINT for others
android-base: * Add NOLINT for expanding namespace std for std::string* ostream overload libdm: * Fix missing parentesis around macro parameters init: * Fix missing CLOEXEC usage and add NOLINT for the intended usages. * Fix missing parentesis around macro parameters * Fix erase() / remove_if() idiom * Correctly specific unsigned char when intended * 'namespace flags' should be signed, since 'flags' it signed for clone() * Add clear to property restore vector<string> to empty after move * Explicit comparison against 0 for strcmp Test: build Change-Id: I8c31dafda2c43ebc5aa50124cbbd6e23ed2c4101
Diffstat (limited to 'init/service_utils.cpp')
-rw-r--r--init/service_utils.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/init/service_utils.cpp b/init/service_utils.cpp
index f88ea9758..34aa8370f 100644
--- a/init/service_utils.cpp
+++ b/init/service_utils.cpp
@@ -120,22 +120,19 @@ Result<void> SetUpPidNamespace(const char* name) {
}
void ZapStdio() {
- int fd;
- fd = open("/dev/null", O_RDWR);
+ auto fd = unique_fd{open("/dev/null", O_RDWR | O_CLOEXEC)};
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
- close(fd);
}
void OpenConsole(const std::string& console) {
- int fd = open(console.c_str(), O_RDWR);
- if (fd == -1) fd = open("/dev/null", O_RDWR);
+ auto fd = unique_fd{open(console.c_str(), O_RDWR | O_CLOEXEC)};
+ if (fd == -1) fd.reset(open("/dev/null", O_RDWR | O_CLOEXEC));
ioctl(fd, TIOCSCTTY, 0);
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
- close(fd);
}
} // namespace