Skip to content

Commit 69b29c4

Browse files
authored
Merge pull request #23 from OmSaran/fixexit
Fix bug where exit code is hardcoded to 0
2 parents 0e12340 + 6b8ffba commit 69b29c4

File tree

2 files changed

+69
-44
lines changed

2 files changed

+69
-44
lines changed

splitfs/fileops_hub.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,20 @@ struct Fileops_p* _hub_find_fileop(const char* name)
622622
RETT_OPEN _hub_OPEN(INTF_OPEN)
623623
{
624624
CHECK_RESOLVE_FILEOPS(_hub_);
625+
int access_result;
626+
627+
access_result = access(path, F_OK);
628+
/**
629+
* We need to check if 'path' is a valid pointer, but not crash it
630+
* (segfault) if it's invalid.
631+
*
632+
* Since it is not possible to validate a pointer in the user-space,
633+
* we are making an access system call which validates
634+
* the pointer.
635+
*/
636+
if(access_result == -1 && errno == EFAULT) {
637+
return -1;
638+
}
625639
DEBUG_FILE("CALL: _hub_OPEN for (%s)\n", path);
626640
struct Fileops_p* op_to_use = NULL;
627641
int result;
@@ -662,7 +676,7 @@ RETT_OPEN _hub_OPEN(INTF_OPEN)
662676
}
663677
*/
664678

665-
if(access(path, F_OK))
679+
if(access_result)
666680
{
667681
if(FLAGS_INCLUDE(oflag, O_CREAT)) {
668682
DEBUG("File does not exist and is set to be created. Using managed fileops (%s)\n",

splitfs/fileops_nvp.c

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,6 @@ void nvp_cleanup(void)
978978

979979
DEBUG_FILE("%s: CLEANUP FINISHED\n", __func__);
980980
MSG("%s: Done Cleaning up\n", __func__);
981-
exit(0);
982981
}
983982

984983
void nvp_exit_handler(void)
@@ -6056,13 +6055,15 @@ RETT_UNLINK _nvp_UNLINK(INTF_UNLINK)
60566055
result = _nvp_fileops->UNLINK(CALL_UNLINK);
60576056

60586057
#if !POSIX_ENABLED
6059-
START_TIMING(op_log_entry_t, op_log_entry_time);
6060-
persist_op_entry(LOG_FILE_UNLINK,
6061-
path,
6062-
NULL,
6063-
0,
6064-
0);
6065-
END_TIMING(op_log_entry_t, op_log_entry_time);
6058+
if(result == 0) {
6059+
START_TIMING(op_log_entry_t, op_log_entry_time);
6060+
persist_op_entry(LOG_FILE_UNLINK,
6061+
path,
6062+
NULL,
6063+
0,
6064+
0);
6065+
END_TIMING(op_log_entry_t, op_log_entry_time);
6066+
}
60666067
#endif
60676068

60686069
END_TIMING(unlink_t, unlink_time);
@@ -6163,13 +6164,15 @@ RETT_MKDIR _nvp_MKDIR(INTF_MKDIR)
61636164
#endif
61646165

61656166
#if !POSIX_ENABLED
6166-
START_TIMING(op_log_entry_t, op_log_entry_time);
6167-
persist_op_entry(LOG_DIR_CREATE,
6168-
path,
6169-
NULL,
6170-
mode,
6171-
0);
6172-
END_TIMING(op_log_entry_t, op_log_entry_time);
6167+
if(result == 0) {
6168+
START_TIMING(op_log_entry_t, op_log_entry_time);
6169+
persist_op_entry(LOG_DIR_CREATE,
6170+
path,
6171+
NULL,
6172+
mode,
6173+
0);
6174+
END_TIMING(op_log_entry_t, op_log_entry_time);
6175+
}
61736176
#endif
61746177
return result;
61756178
}
@@ -6186,13 +6189,15 @@ RETT_RENAME _nvp_RENAME(INTF_RENAME)
61866189
#endif
61876190

61886191
#if !POSIX_ENABLED
6189-
START_TIMING(op_log_entry_t, op_log_entry_time);
6190-
persist_op_entry(LOG_RENAME,
6191-
old,
6192-
new,
6193-
0,
6194-
0);
6195-
END_TIMING(op_log_entry_t, op_log_entry_time);
6192+
if(result == 0) {
6193+
START_TIMING(op_log_entry_t, op_log_entry_time);
6194+
persist_op_entry(LOG_RENAME,
6195+
old,
6196+
new,
6197+
0,
6198+
0);
6199+
END_TIMING(op_log_entry_t, op_log_entry_time);
6200+
}
61966201
#endif
61976202
return result;
61986203
}
@@ -6209,13 +6214,15 @@ RETT_LINK _nvp_LINK(INTF_LINK)
62096214
#endif
62106215

62116216
#if !POSIX_ENABLED
6212-
START_TIMING(op_log_entry_t, op_log_entry_time);
6213-
persist_op_entry(LOG_LINK,
6214-
path1,
6215-
path2,
6216-
0,
6217-
0);
6218-
END_TIMING(op_log_entry_t, op_log_entry_time);
6217+
if(result == 0) {
6218+
START_TIMING(op_log_entry_t, op_log_entry_time);
6219+
persist_op_entry(LOG_LINK,
6220+
path1,
6221+
path2,
6222+
0,
6223+
0);
6224+
END_TIMING(op_log_entry_t, op_log_entry_time);
6225+
}
62196226
#endif
62206227
return result;
62216228
}
@@ -6232,13 +6239,15 @@ RETT_SYMLINK _nvp_SYMLINK(INTF_SYMLINK)
62326239
#endif
62336240

62346241
#if !POSIX_ENABLED
6235-
START_TIMING(op_log_entry_t, op_log_entry_time);
6236-
persist_op_entry(LOG_SYMLINK,
6237-
path1,
6238-
path2,
6239-
0,
6240-
0);
6241-
END_TIMING(op_log_entry_t, op_log_entry_time);
6242+
if(result == 0) {
6243+
START_TIMING(op_log_entry_t, op_log_entry_time);
6244+
persist_op_entry(LOG_SYMLINK,
6245+
path1,
6246+
path2,
6247+
0,
6248+
0);
6249+
END_TIMING(op_log_entry_t, op_log_entry_time);
6250+
}
62426251
#endif
62436252
return result;
62446253
}
@@ -6255,13 +6264,15 @@ RETT_RMDIR _nvp_RMDIR(INTF_RMDIR)
62556264
#endif
62566265

62576266
#if !POSIX_ENABLED
6258-
START_TIMING(op_log_entry_t, op_log_entry_time);
6259-
persist_op_entry(LOG_DIR_DELETE,
6260-
path,
6261-
NULL,
6262-
0,
6263-
0);
6264-
END_TIMING(op_log_entry_t, op_log_entry_time);
6267+
if(result == 0) {
6268+
START_TIMING(op_log_entry_t, op_log_entry_time);
6269+
persist_op_entry(LOG_DIR_DELETE,
6270+
path,
6271+
NULL,
6272+
0,
6273+
0);
6274+
END_TIMING(op_log_entry_t, op_log_entry_time);
6275+
}
62656276
#endif
62666277
return result;
62676278
}

0 commit comments

Comments
 (0)