liblog: fix fd leakage
File descriptors remain open across an exec unless FD_CLOEXEC is
set. Add O_CLOEXEC to the open() call to prevent file descriptor
leakage.
In particular, the following program will eventually run out of
file descriptors:
int main(int argc, char **argv) {
printf("===== entering main =====\n");
ALOGW("entering main");
system("ls -l /proc/self/fd/");
execv(argv[0], argv);
printf("exec failed\n");
return -1;
}
Change-Id: I5be43ab3b9f82a05f242b1f586454c50568af388
This commit is contained in:
parent
80dac35023
commit
a170322083
1 changed files with 3 additions and 1 deletions
|
|
@ -24,6 +24,8 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <cutils/logger.h>
|
||||
#include <cutils/logd.h>
|
||||
|
|
@ -37,7 +39,7 @@
|
|||
#define log_writev(filedes, vector, count) fakeLogWritev(filedes, vector, count)
|
||||
#define log_close(filedes) fakeLogClose(filedes)
|
||||
#else
|
||||
#define log_open(pathname, flags) open(pathname, flags)
|
||||
#define log_open(pathname, flags) open(pathname, (flags) | O_CLOEXEC)
|
||||
#define log_writev(filedes, vector, count) writev(filedes, vector, count)
|
||||
#define log_close(filedes) close(filedes)
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue