log: Open log file CLOEXEC so child processes don't get the fd
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com> Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
This commit is contained in:
committed by
Bryce Harrington
parent
4a8a3a1c71
commit
6bc33d63cf
@@ -36,8 +36,8 @@
|
|||||||
|
|
||||||
#include "os-compatibility.h"
|
#include "os-compatibility.h"
|
||||||
|
|
||||||
static int
|
int
|
||||||
set_cloexec_or_close(int fd)
|
os_fd_set_cloexec(int fd)
|
||||||
{
|
{
|
||||||
long flags;
|
long flags;
|
||||||
|
|
||||||
@@ -46,16 +46,22 @@ set_cloexec_or_close(int fd)
|
|||||||
|
|
||||||
flags = fcntl(fd, F_GETFD);
|
flags = fcntl(fd, F_GETFD);
|
||||||
if (flags == -1)
|
if (flags == -1)
|
||||||
goto err;
|
return -1;
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
|
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
|
||||||
goto err;
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
set_cloexec_or_close(int fd)
|
||||||
|
{
|
||||||
|
if (os_fd_set_cloexec(fd) != 0) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
err:
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ backtrace(void **buffer, int size)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int
|
||||||
|
os_fd_set_cloexec(int fd);
|
||||||
|
|
||||||
int
|
int
|
||||||
os_socketpair_cloexec(int domain, int type, int protocol, int *sv);
|
os_socketpair_cloexec(int domain, int type, int protocol, int *sv);
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#include "compositor.h"
|
#include "compositor.h"
|
||||||
|
|
||||||
|
#include "os-compatibility.h"
|
||||||
|
|
||||||
static FILE *weston_logfile = NULL;
|
static FILE *weston_logfile = NULL;
|
||||||
|
|
||||||
static int cached_tm_mday = -1;
|
static int cached_tm_mday = -1;
|
||||||
@@ -77,8 +79,11 @@ weston_log_file_open(const char *filename)
|
|||||||
{
|
{
|
||||||
wl_log_set_handler_server(custom_handler);
|
wl_log_set_handler_server(custom_handler);
|
||||||
|
|
||||||
if (filename != NULL)
|
if (filename != NULL) {
|
||||||
weston_logfile = fopen(filename, "a");
|
weston_logfile = fopen(filename, "a");
|
||||||
|
if (weston_logfile)
|
||||||
|
os_fd_set_cloexec(fileno(weston_logfile));
|
||||||
|
}
|
||||||
|
|
||||||
if (weston_logfile == NULL)
|
if (weston_logfile == NULL)
|
||||||
weston_logfile = stderr;
|
weston_logfile = stderr;
|
||||||
|
|||||||
Reference in New Issue
Block a user