summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2015-04-26 00:59:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-04-26 00:59:01 +0000
commitccac2be8a6269469087a7978e1a6db62ef4618c6 (patch)
tree6d0f776cc2ad0012cd72bb3da57fb48c69322b7d
parent178299fd459b7622e9e3de05a48d6ba050f92bec (diff)
parente34577ce1bd4a8de53ff3d9178b4f78c86086dc8 (diff)
downloadsystem_core-ccac2be8a6269469087a7978e1a6db62ef4618c6.zip
system_core-ccac2be8a6269469087a7978e1a6db62ef4618c6.tar.gz
system_core-ccac2be8a6269469087a7978e1a6db62ef4618c6.tar.bz2
Merge "init: use SELinux /dev/null if available"
-rw-r--r--init/util.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/init/util.cpp b/init/util.cpp
index 332aa2a..b7fb867 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -379,23 +379,28 @@ int wait_for_file(const char *filename, int timeout)
void open_devnull_stdio(void)
{
- int fd;
- static const char *name = "/dev/__null__";
- if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) {
- fd = open(name, O_RDWR);
- unlink(name);
- if (fd >= 0) {
- dup2(fd, 0);
- dup2(fd, 1);
- dup2(fd, 2);
- if (fd > 2) {
- close(fd);
- }
- return;
+ // Try to avoid the mknod() call if we can. Since SELinux makes
+ // a /dev/null replacement available for free, let's use it.
+ int fd = open("/sys/fs/selinux/null", O_RDWR);
+ if (fd == -1) {
+ // OOPS, /sys/fs/selinux/null isn't available, likely because
+ // /sys/fs/selinux isn't mounted. Fall back to mknod.
+ static const char *name = "/dev/__null__";
+ if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) {
+ fd = open(name, O_RDWR);
+ unlink(name);
+ }
+ if (fd == -1) {
+ exit(1);
}
}
- exit(1);
+ dup2(fd, 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+ if (fd > 2) {
+ close(fd);
+ }
}
void import_kernel_cmdline(int in_qemu,