init: Open /etc/motd with O_CLOEXEC to avoid leaking this file to children
This commit is contained in:
parent
c312d81de4
commit
77d331b258
@ -1,4 +1,5 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <luna.h>
|
#include <luna.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -6,10 +7,16 @@
|
|||||||
|
|
||||||
void show_motd()
|
void show_motd()
|
||||||
{
|
{
|
||||||
FILE* fp = fopen("/etc/motd", "r");
|
int fd = open("/etc/motd", O_RDONLY | O_CLOEXEC);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
if (errno != ENOENT) { perror("open"); }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FILE* fp = fdopen(fd, "r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
if (errno != ENOENT) { perror("fopen"); }
|
perror("fopen");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user