diff options
author | Nick Kralevich <nnk@google.com> | 2013-03-15 09:45:12 -0700 |
---|---|---|
committer | Nick Kralevich <nnk@google.com> | 2013-03-15 09:48:32 -0700 |
commit | a1703220834ddeffde5d571cd776ca981e8a42f6 (patch) | |
tree | a87f3e5ca1d4f7cc1c3680ef9f1097582b16a0df /liblog/logd_write.c | |
parent | 80dac35023bb7860b7382ca995e19710bd894e7e (diff) | |
download | system_core-a1703220834ddeffde5d571cd776ca981e8a42f6.zip system_core-a1703220834ddeffde5d571cd776ca981e8a42f6.tar.gz system_core-a1703220834ddeffde5d571cd776ca981e8a42f6.tar.bz2 |
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
Diffstat (limited to 'liblog/logd_write.c')
-rw-r--r-- | liblog/logd_write.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/liblog/logd_write.c b/liblog/logd_write.c index d812abc..3613d25 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -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 |