Merge "init: use SELinux /dev/null if available"
This commit is contained in:
commit
ccac2be8a6
1 changed files with 19 additions and 14 deletions
|
|
@ -379,23 +379,28 @@ int wait_for_file(const char *filename, int timeout)
|
||||||
|
|
||||||
void open_devnull_stdio(void)
|
void open_devnull_stdio(void)
|
||||||
{
|
{
|
||||||
int fd;
|
// Try to avoid the mknod() call if we can. Since SELinux makes
|
||||||
static const char *name = "/dev/__null__";
|
// a /dev/null replacement available for free, let's use it.
|
||||||
if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) {
|
int fd = open("/sys/fs/selinux/null", O_RDWR);
|
||||||
fd = open(name, O_RDWR);
|
if (fd == -1) {
|
||||||
unlink(name);
|
// OOPS, /sys/fs/selinux/null isn't available, likely because
|
||||||
if (fd >= 0) {
|
// /sys/fs/selinux isn't mounted. Fall back to mknod.
|
||||||
dup2(fd, 0);
|
static const char *name = "/dev/__null__";
|
||||||
dup2(fd, 1);
|
if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) {
|
||||||
dup2(fd, 2);
|
fd = open(name, O_RDWR);
|
||||||
if (fd > 2) {
|
unlink(name);
|
||||||
close(fd);
|
}
|
||||||
}
|
if (fd == -1) {
|
||||||
return;
|
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,
|
void import_kernel_cmdline(int in_qemu,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue