Skip to content

Instantly share code, notes, and snippets.

@b1tninja
Created May 7, 2019 04:51
Show Gist options
  • Save b1tninja/330813bcb7474e8b9f40e884b1cc2fdb to your computer and use it in GitHub Desktop.
Save b1tninja/330813bcb7474e8b9f40e884b1cc2fdb to your computer and use it in GitHub Desktop.
nocache.patch
commit 9519ee51ecd775e4beaf7625c79207e78df9e0d7
gpg: Signature made Mon 06 May 2019 09:50:33 PM PDT
gpg: using RSA key F6CC1F4DF325EACBBE2532481F299543498470BA
gpg: issuer "justincapella@gmail.com"
gpg: Good signature from "Justin Capella <justincapella@gmail.com>" [ultimate]
Author: Justin Capella <justincapella@gmail.com>
Date: Mon May 6 21:50:33 2019 -0700
opendir
diff --git a/nocache.c b/nocache.c
index 84fd0e1..78c5049 100644
--- a/nocache.c
+++ b/nocache.c
@@ -26,6 +26,7 @@ static void handle_stdout(void);
static void store_pageinfo(int fd);
static void free_unclaimed_pages(int fd);
+int opendir(const char *dirname);
int open(const char *pathname, int flags, mode_t mode);
int open64(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, int flags, mode_t mode);
@@ -41,6 +42,7 @@ FILE *fopen(const char *path, const char *mode);
FILE *fopen64(const char *path, const char *mode);
int fclose(FILE *fp);
+int (*_original_opendir)(const char *dirname);
int (*_original_open)(const char *pathname, int flags, mode_t mode);
int (*_original_open64)(const char *pathname, int flags, mode_t mode);
int (*_original_creat)(const char *pathname, int flags, mode_t mode);
@@ -120,6 +122,7 @@ static void init(void)
fds = malloc(max_fds * sizeof(*fds));
assert(fds != NULL);
+ _original_opendir = (int (*)(const char *,)) dlsym(RTLD_NEXT, "opendir");
_original_open = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "open");
_original_open64 = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "open64");
_original_creat = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "creat");
@@ -214,6 +217,22 @@ static void destroy(void)
pthread_mutex_unlock(&fds_iter_lock);
}
+int opendir(const char *dirname)
+{
+ int fd;
+
+ if(!_original_opendir)
+ _original_opendir = (int (*)(const char *)) dlsym(RTLD_NEXT, "opendir");
+ assert(_original_opendir != NULL);
+
+ if((fd = _original_opendir(dirname)) != NULL) {
+ DEBUG("opendir(dirname=%s) = %d\n",
+ dirname, fd);
+ store_pageinfo(fd);
+ }
+ return fd;
+}
+
int open(const char *pathname, int flags, mode_t mode)
{
int fd;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment