Skip to content
Draft
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
30 changes: 25 additions & 5 deletions src/client/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ void test_log(const char *name)
int result;
if (!run_tests)
return;
if (client_is_disconnected() && strcmp(getenv("SPINDLE_TEST"), "TEST_RELIABILITY") == 0)
return;
result = open(name, O_RDONLY);
if (result != -1)
close(result);
Expand Down Expand Up @@ -445,6 +447,7 @@ char *client_library_load(const char *name)
{
char *newname;
int errcode, direxists;
int result;
char fixed_name[MAX_PATH_LEN+1];

check_for_fork();
Expand All @@ -469,7 +472,11 @@ char *client_library_load(const char *name)
if (is_in_spindle_cache(name)) {
debug_printf2("Library %s is in spindle cache (%s). Translating request\n", name, location);
memset(fixed_name, 0, MAX_PATH_LEN+1);
send_orig_path_request(ldcsid, orig_file_name, fixed_name);
result = send_orig_path_request(ldcsid, orig_file_name, fixed_name);
if (result == DISCONNECT) {
debug_printf2("Client is in disconnected state. Returning %s for loading\n", name);
return (char *) name;
}
orig_file_name = fixed_name;
debug_printf2("Spindle cache library %s translated to original path %s\n", name, orig_file_name);
}
Expand All @@ -488,8 +495,12 @@ char *client_library_load(const char *name)
return (char *) name;
}

get_relocated_file(ldcsid, orig_file_name, 1, &newname, &errcode, &direxists);

result = get_relocated_file(ldcsid, orig_file_name, 1, &newname, &errcode, &direxists);
if (result == DISCONNECT) {
debug_printf2("Client is in disconnected state. Returning %s for loading\n", name);
return (char *) name;
}

if(!newname) {
newname = concatStrings(NOT_FOUND_PREFIX, orig_file_name);
if (!direxists)
Expand All @@ -508,13 +519,18 @@ static void read_python_prefixes(int fd, char **path)
{
int use_cache = (opts & OPT_SHMCACHE) && (shm_cachesize > 0);
int found_file = 0;
int result;

if (use_cache) {
debug_printf2("Looking up python prefixes in shared cache\n");
found_file = fetch_from_cache("*SPINDLE_PYTHON_PREFIXES", path);
}
if (!found_file) {
get_python_prefix(fd, path);
result = get_python_prefix(fd, path);
if (result == DISCONNECT) {
debug_printf2("Spindle disconnected. Using empty python prefixes\n");
(*path)[0] = '\0';
}
if (use_cache)
shmcache_update("*SPINDLE_PYTHON_PREFIXES", *path);
}
Expand Down Expand Up @@ -600,7 +616,11 @@ static ldso_info_t *load_ldso_metadata()
}

if (!found_file) {
send_ldso_info_request(ldcsid, interp_name, filename);
result = send_ldso_info_request(ldcsid, interp_name, filename);
if (result == DISCONNECT) {
debug_printf2("Client disconnected. No ldso info\n");
return NULL;
}
if (use_cache)
shmcache_update(cachename, filename);
ldso_info_name = filename;
Expand Down
25 changes: 22 additions & 3 deletions src/client/client/exec_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ int exec_pathsearch(int ldcsid, const char *orig_exec, char **reloc_exec, int *e
{
char *saveptr = NULL, *path, *cur;
char newexec[MAX_PATH_LEN+1];
int result;

if (!orig_exec) {
err_printf("Null exec passed to exec_pathsearch\n");
Expand All @@ -228,14 +229,22 @@ int exec_pathsearch(int ldcsid, const char *orig_exec, char **reloc_exec, int *e
}

if (orig_exec[0] == '/' || orig_exec[0] == '.') {
get_relocated_file(ldcsid, (char *) orig_exec, 1, reloc_exec, errcode, NULL);
result = get_relocated_file(ldcsid, (char *) orig_exec, 1, reloc_exec, errcode, NULL);
if (result == DISCONNECT) {
debug_printf3("Disconnected during exec\n");
return DISCONNECT;
}
debug_printf3("exec_pathsearch translated %s to %s\n", orig_exec, *reloc_exec);
return 0;
}

path = getenv("PATH");
if (!path) {
get_relocated_file(ldcsid, (char *) orig_exec, 1, reloc_exec, errcode, NULL);
result = get_relocated_file(ldcsid, (char *) orig_exec, 1, reloc_exec, errcode, NULL);
if (result == DISCONNECT) {
debug_printf3("Disconnected during exec\n");
return DISCONNECT;
}
debug_printf3("No path. exec_pathsearch translated %s to %s\n", orig_exec, *reloc_exec);
return 0;
}
Expand All @@ -256,6 +265,11 @@ int exec_pathsearch(int ldcsid, const char *orig_exec, char **reloc_exec, int *e
result = stat(newexec, &buf);
exists = (result != -1);
}
if (result == DISCONNECT) {
debug_printf3("Disconnected during exec\n");
if (path) spindle_free(path);
return DISCONNECT;
}
if (!exists)
continue;
if (buf.st_mode & S_IFDIR) {
Expand All @@ -269,7 +283,12 @@ int exec_pathsearch(int ldcsid, const char *orig_exec, char **reloc_exec, int *e
continue;
}
debug_printf2("File %s exists and has execute set, requesting full file\n", newexec);
get_relocated_file(ldcsid, newexec, 1, reloc_exec, errcode, NULL);
result = get_relocated_file(ldcsid, newexec, 1, reloc_exec, errcode, NULL);
if (result == DISCONNECT) {
debug_printf3("Disconnected during exec\n");
if (path) spindle_free(path);
return DISCONNECT;
}
debug_printf2("Exec search request returned %s -> %s\n", newexec, *reloc_exec ? *reloc_exec : "NULL");
if (*reloc_exec) {
found = 1;
Expand Down
35 changes: 25 additions & 10 deletions src/client/client/intercept_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,8 @@ static int prep_exec(const char *filepath, char **argv,
{
int result;
char *interp_name;
int i;

debug_printf3("prep_exec for filepath %s to newpath %s\n", filepath, newpath);
if (spindle_debug_prints >= 3) {
debug_printf3("Args for exec are:\n");
for (i = 0; argv[i]; i++) {
debug_printf3("%d. %s\n", i, argv[i]);
}
}


if (errcode == EACCES) {
strncpy(newpath, filepath, newpath_size);
Expand Down Expand Up @@ -327,6 +319,7 @@ static int find_exec(const char *filepath, char **argv, char *newpath, int newpa
int errcode, exists;
struct stat buf;
int reloc_exec;
int result;

*propogate_spindle = shouldPropogateSpindle(envp, filepath);

Expand All @@ -353,11 +346,19 @@ static int find_exec(const char *filepath, char **argv, char *newpath, int newpa
sync_cwd();

debug_printf2("Requesting stat on exec of %s to validate file\n", filepath);
int result = get_stat_result(ldcsid, (char *) filepath, 0, &exists, &buf);
result = get_stat_result(ldcsid, (char *) filepath, 0, &exists, &buf);
if (result == STAT_SELF_OPEN) {
result = stat(filepath, &buf);
exists = (result != -1);
}
else if (result == DISCONNECT) {
debug_printf3("Disconnected. Passing through original file %s\n", filepath);
*propogate_spindle = 0;
strncpy(newpath, filepath, newpath_size);
newpath[newpath_size-1] = '\0';
return 0;
}

if (!exists) {
set_errno(ENOENT);
return -1;
Expand All @@ -370,7 +371,14 @@ static int find_exec(const char *filepath, char **argv, char *newpath, int newpa
return -1;
}
debug_printf2("Exec operation requesting file: %s\n", filepath);
get_relocated_file(ldcsid, (char *) filepath, 1, &newname, &errcode, NULL);
result = get_relocated_file(ldcsid, (char *) filepath, 1, &newname, &errcode, NULL);
if (result == DISCONNECT) {
debug_printf3("Disconnected. Passing through original file %s\n", filepath);
*propogate_spindle = 0;
strncpy(newpath, filepath, newpath_size);
newpath[newpath_size-1] = '\0';
return 0;
}
debug_printf("Exec file request returned %s -> %s with errcode %d\n",
filepath, newname ? newname : "NULL", errcode);

Expand Down Expand Up @@ -415,6 +423,13 @@ static int find_exec_pathsearch(const char *filepath, char **argv, char *newpath
set_errno(errcode);
return -1;
}
if (result == DISCONNECT) {
debug_printf3("Disconnected. Passing through original file %s\n", filepath);
*propogate_spindle = 0;
strncpy(newpath, filepath, newpath_size);
newpath[newpath_size-1] = '\0';
return 0;
}
debug_printf("Exec file request returned %s -> %s with errcode %d\n",
filepath, newname ? newname : "NULL", errcode);

Expand Down
7 changes: 6 additions & 1 deletion src/client/client/intercept_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static int handle_proc_pid_maps_open(const char *path, char **newpath);
static int do_check_file(const char *path, char **newpath) {
char *myname, *newname;
int errcode;
int result;

myname=(char *) path;
debug_printf2("Open operation requesting file: %s\n", path);
Expand All @@ -64,7 +65,11 @@ static int do_check_file(const char *path, char **newpath) {
}
sync_cwd();

get_relocated_file(ldcsid, myname, 0, &newname, &errcode, NULL);
result = get_relocated_file(ldcsid, myname, 0, &newname, &errcode, NULL);
if (result == DISCONNECT) {
debug_printf3("Disconnected. Access original file %s\n", path);
return -1;
}

if (newname != NULL) {
*newpath=newname;
Expand Down
6 changes: 4 additions & 2 deletions src/client/client/intercept_readlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ ssize_t readlink_wrapper(const char *path, char *buf, size_t bufsiz)
else if (intercept_result == REDIRECT) {
debug_printf3("Intercepting readlink(%s)\n", path);
result = get_readlink_result(ldcsid, path, resultpath, &rl_result, &readlink_errcode);
if (result == -1 || result == STAT_SELF_OPEN) {
if (result == -1 || result == STAT_SELF_OPEN || result == DISCONNECT) {
if (result == -1)
err_printf("Spindle readlink returned error. Using orig readlink\n");
else
else if (result == STAT_SELF_OPEN)
debug_printf3("Spindle readlink returned self open. Using orig readlink\n");
else if (result == DISCONNECT)
debug_printf3("Spindle disconnected. Using orig readlink\n");
result = orig_readlink(path, resultpath, sizeof(resultpath));
if (result == -1) {
errno = get_errno();
Expand Down
20 changes: 16 additions & 4 deletions src/client/client/intercept_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ int handle_stat(const char *path, struct stat *buf, int flags)
if (ldcsid < 0 || !use_ldcs || !path || !buf) {
debug_printf3("no ldcs: stat query %s\n", path ? path : "NULL");
if (path)
test_log(path);
test_log(path);
debug_printf3("Returning ORIG_STAT (%d)\n", (int) ORIG_STAT);
return ORIG_STAT;
}
sync_cwd();
Expand All @@ -75,7 +76,11 @@ int handle_stat(const char *path, struct stat *buf, int flags)
debug_printf3("Allowing original stat on %s\n", path);
return ORIG_STAT;
}
if (result == -1) {
else if (result == DISCONNECT) {
debug_printf3("Disconnected. Using riginal stat on %s\n", path);
return ORIG_STAT;
}
else if (result == -1) {
/* Spindle level error */
debug_printf3("Allowing original stat on %s\n", path);
return ORIG_STAT;
Expand Down Expand Up @@ -128,7 +133,7 @@ static int handle_fstat(int fd, struct stat* buf, int flags)
if (get_pathname_from_fd(fd, path, sizeof(path)) < 0)
return -1;

debug_printf3("%s Redirecting fstat(%s) to the spindle\n", __func__, path);
debug_printf3("Redirecting fstat(%d=%s) to spindle\n", fd, path);
return handle_stat(path, buf, flags);
}

Expand Down Expand Up @@ -222,8 +227,10 @@ int rtcache_lxstat64(int vers, const char *path, struct stat *buf)
int rtcache_fstat(int fd, struct stat *buf)
{
int result = handle_fstat(fd, buf, 0);
debug_printf3("handle_fstat returned %d (ORIG_STAT = %d)\n", result, (int) ORIG_STAT);
if (result != ORIG_STAT)
return result;
debug_printf3("Calling orig_fstat on fd %d\n", fd);
result = orig_fstat(fd, buf);
if (result == -1) {
errno = get_errno();
Expand All @@ -235,8 +242,10 @@ int rtcache_fstat(int fd, struct stat *buf)
int rtcache_fxstat(int vers, int fd, struct stat *buf)
{
int result = handle_fstat(fd, buf, IS_XSTAT);
debug_printf3("handle_fstat returned %d (ORIG_STAT = %d)\n", result, (int) ORIG_STAT);
if (result != ORIG_STAT)
return result;
debug_printf3("Calling orig_fxstat on fd %d\n", fd);
result = orig_fxstat(vers, fd, buf);
if (result == -1) {
errno = get_errno();
Expand All @@ -247,9 +256,12 @@ int rtcache_fxstat(int vers, int fd, struct stat *buf)

int rtcache_fxstat64(int vers, int fd, struct stat *buf)
{
int result = handle_fstat(fd, buf, IS_XSTAT | IS_64);
int result;
result = handle_fstat(fd, buf, IS_XSTAT | IS_64);
debug_printf3("handle_fstat returned %d (ORIG_STAT = %d)\n", result, (int) ORIG_STAT);
if (result != ORIG_STAT)
return result;
debug_printf3("Calling orig_fxstat64 on fd %d\n", fd);
result = orig_fxstat64(vers, fd, buf);
if (result == -1) {
errno = get_errno();
Expand Down
10 changes: 8 additions & 2 deletions src/client/client/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,17 @@ static int get_metadata_result(int fd, const char *path, int is_lstat, int *exis
if (!found_file) {
debug_printf2("Sending request for %sstat of %s to server\n", is_lstat ? "l" : "", path);
network_result = send_stat_request(fd, (char *) path, is_lstat, buffer);
debug_printf2("Server returned stat result for %s: %s\n", path, buffer);

if (network_result == -1)
buffer[0] = '\0';
if (network_result == STAT_SELF) {
debug_printf3("Returning STAT_SELF_OPEN from get_metadata for %s\n", path);
return STAT_SELF_OPEN;
}
if (network_result == DISCONNECT) {
debug_printf3("Disconnected. Returning original stat for %s\n", path);
return STAT_SELF_OPEN;
}
debug_printf2("Server returned stat result for %s: %s\n", path, buffer);

if (use_cache)
update_cache(cache_name, dir_name, buffer, &errcode, ENOENT);
Expand Down Expand Up @@ -336,6 +339,9 @@ int get_relocated_file(int fd, const char *name, int dso, char** newname, int *e

debug_printf2("Send file request to server: %s\n", name);
result = send_file_query(fd, (char *) name, dso, newname, errorcode);
if (result == DISCONNECT) {
return DISCONNECT;
}
debug_printf2("Recv file from server: %s\n", *newname ? *newname : "NONE");

if (use_cache) {
Expand Down
Loading
Loading