Commit e6df5f64 authored by Aleksandr's avatar Aleksandr Committed by Julius Plenz

work around libselinux.so issue

This issue came up in the real world because apparently libselinux.so.1 does an fopen in a constructor function. Big Thanks to Mike Shal (http://sourceware.org/ml/libc-help/2009-06/msg00000.html ) [Made some cosmetic changes -JP] Fixes: GitHub issues #1 and #2 Signed-off-by: 's avatarJulius Plenz <julius@plenz.com>
parent 5de2538b
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
#include <errno.h>
#include "fcntl_helpers.h" #include "fcntl_helpers.h"
...@@ -185,17 +186,32 @@ int close(int fd) ...@@ -185,17 +186,32 @@ int close(int fd)
FILE *fopen(const char *path, const char *mode) FILE *fopen(const char *path, const char *mode)
{ {
int fd; int fd;
FILE *fp; FILE *fp = NULL;
if((fp = _original_fopen(path, mode)) != NULL)
if((fd = fileno(fp)) != -1) if(!_original_fopen)
store_pageinfo(fd); _original_fopen = (FILE *(*)(const char *, const char *)) dlsym(RTLD_NEXT, "fopen");
if(_original_fopen) {
if((fp = _original_fopen(path, mode)) != NULL)
if((fd = fileno(fp)) != -1)
store_pageinfo(fd);
}
return fp; return fp;
} }
int fclose(FILE *fp) int fclose(FILE *fp)
{ {
free_unclaimed_pages(fileno(fp)); if(!_original_fclose)
return _original_fclose(fp); _original_fclose = (int (*)(FILE *)) dlsym(RTLD_NEXT, "fclose");
if(_original_fclose) {
free_unclaimed_pages(fileno(fp));
return _original_fclose(fp);
}
errno = EFAULT;
return EOF;
} }
static void store_pageinfo(int fd) static void store_pageinfo(int fd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment