Commit 3f002b02 authored by Ramon Nou's avatar Ramon Nou
Browse files

Added fflush

parent a6836eb6
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -221,7 +221,8 @@ int
dlsym_fsync(int fd);
int
dlsym_flock(int fd, int operation);

int
dlsym_fflush(FILE* stream);
// Manager API

char*
+36 −12
Original line number Diff line number Diff line
@@ -127,6 +127,15 @@ int (*real_feof)(FILE*) = NULL;
// fputs and fgets
int (*real_fputs)(const char*, FILE*) = NULL;
char* (*real_fgets)(char*, int, FILE*) = NULL;
// fflush
int (*real_fflush)(FILE*) = NULL;
int
dlsym_fflush(FILE* stream) {
    if(real_fflush == NULL) {
        real_fflush = (int (*)(FILE*)) dlsym(RTLD_NEXT, "fflush");
    }
    return real_fflush(stream);
}


void
@@ -1275,12 +1284,10 @@ ftruncate(int fd, off_t length) {
            // get path from file_map
            std::string path = CTX->file_map()->get(fd)->path();
            return gkfs::syscall::gkfs_truncate(path, length);

        }
    }



    int ret = dlsym_ftruncate(fd, length);

    debug_info("[BYPASS] << After ftruncate....\n");
@@ -2645,8 +2652,7 @@ fopen(const char* filename, const char* mode) {
            case gkfs::preload::RelativizeStatus::fd_not_a_dir:
                errno = ENOTDIR;
                return NULL;
            case gkfs::preload::RelativizeStatus::internal:
            {
            case gkfs::preload::RelativizeStatus::internal: {
                int fd = 0;
                debug_info("[BYPASS] >> fopen GEKKO.... %s \n", filename);
                // convert mode to open mode
@@ -2825,3 +2831,21 @@ fgets(char* str, int n, FILE* stream) {

    return dlsym_fgets(str, n, stream);
}


// implement fflush and bypass if gekko
int
fflush(FILE* stream) {
    debug_info("[BYPASS] >> fflush.... \n");
    initializeGekko();
    int ret;
    if(CTX->interception_enabled()) {
        if(CTX->file_map()->exist(stream->_fileno)) {
            // flush stream with gkfs_fsync
            return 0;
        }
    }

    ret = dlsym_fflush(stream);
    return ret;
}