summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2015-04-26 01:39:13 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-26 01:39:13 +0000
commitec9bd166cc406d8079b7d33d04b3e04708183d96 (patch)
tree8fef007285bd0349f0fbeed8d2de3cff4f553112 /init
parent1c2457ffdaf833b06a2619d967fe9def7139180f (diff)
parent45a49d0eb7e2e9fc3d2c48884c84f6a6c7397720 (diff)
downloadsystem_core-ec9bd166cc406d8079b7d33d04b3e04708183d96.zip
system_core-ec9bd166cc406d8079b7d33d04b3e04708183d96.tar.gz
system_core-ec9bd166cc406d8079b7d33d04b3e04708183d96.tar.bz2
am 45a49d0e: am ccac2be8: Merge "init: use SELinux /dev/null if available"
* commit '45a49d0eb7e2e9fc3d2c48884c84f6a6c7397720': init: use SELinux /dev/null if available
Diffstat (limited to 'init')
-rw-r--r--init/util.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/init/util.cpp b/init/util.cpp
index 7d53f5a..8511f92 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,