Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude local path prefixes from being cached #34

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/client/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "client_api.h"
#include "spindle_launch.h"
#include "shmcache.h"
#include "should_intercept.h"

errno_location_t app_errno_location;

Expand Down Expand Up @@ -375,7 +376,13 @@ char *client_library_load(const char *name)
test_log(name);
return (char *) name;
}


/* Do not relocate if the file is to be excluded (e.g., on the local file system) */
if( is_excluded_path(name) ) {
test_log(name);
return (char *) name;
}

sync_cwd();

get_relocated_file(ldcsid, name, &newname, &errcode);
Expand Down
60 changes: 60 additions & 0 deletions src/client/client/should_intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>

#include "spindle_launch.h"
#include "client.h"
Expand All @@ -28,6 +29,49 @@

extern int relocate_spindleapi();

int is_excluded_path(const char *pathname) {
static int is_enabled = -1;
static const char *exclude_prefixes[] = {
"/bin",
"/dev",
"/etc",
"/lib",
"/opt",
"/proc",
"/sbin",
"/sys",
"/tmp",
"/usr",
"/var",
NULL
};
int i;

if( is_enabled < 0 ) {
const char *envar = getenv("SPINDLE_DISABLE_EXCLUDE");
is_enabled = 1; // Default
if( NULL != envar && '1' == envar[0] ) {
is_enabled = 0;
}
}

if( 0 == is_enabled ) {
return 0;
}

if( NULL == pathname ) {
return 0;
}

for(i = 0; NULL != exclude_prefixes[i]; ++i ) {
if( 0 == strncmp(pathname, exclude_prefixes[i], strlen(exclude_prefixes[i])) ) {
return 1;
}
}

return 0;
}

static int is_python_path(const char *pathname)
{
unsigned int i;
Expand Down Expand Up @@ -93,6 +137,10 @@ int open_filter(const char *fname, int flags)
{
char *last_slash, *last_dot;

if( is_excluded_path(fname) ) {
return ORIG_CALL;
}

if (relocate_spindleapi()) {
if (open_for_excl(flags))
return EXCL_OPEN;
Expand Down Expand Up @@ -130,6 +178,10 @@ int fopen_filter(const char *fname, const char *flags)
{
char *last_slash, *last_dot;

if( is_excluded_path(fname) ) {
return ORIG_CALL;
}

if (relocate_spindleapi()) {
if (open_for_excl(flags))
return EXCL_OPEN;
Expand Down Expand Up @@ -161,6 +213,10 @@ int fopen_filter(const char *fname, const char *flags)

int exec_filter(const char *fname)
{
if( is_excluded_path(fname) ) {
return ORIG_CALL;
}

if (relocate_spindleapi())
return REDIRECT;

Expand All @@ -174,6 +230,10 @@ int stat_filter(const char *fname)
{
char *last_dot, *last_slash;

if( is_excluded_path(fname) ) {
return ORIG_CALL;
}

if (relocate_spindleapi())
return REDIRECT;

Expand Down
1 change: 1 addition & 0 deletions src/client/client/should_intercept.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ int fopen_filter(const char *fname, const char *flags);
int exec_filter(const char *fname);
int stat_filter(const char *fname);
int fd_filter(int fd);
int is_excluded_path(const char *pathname);

#endif