Commit 96836fc5 authored by Ramon Nou's avatar Ramon Nou
Browse files

fcntl setfl attempt on libc

parent 35b198ec
Loading
Loading
Loading
Loading
+36 −3
Original line number Diff line number Diff line
@@ -341,7 +341,27 @@ DLSYM_WRAPPER(int, chmod, (char* path, mode_t mode), (path, mode), "chmod")
DLSYM_WRAPPER(int, fchmod, (int fd, mode_t mode), (fd, mode), "fchmod")
DLSYM_WRAPPER(int, chown, (char* path, uid_t owner, gid_t group),
              (path, owner, group), "chown")
DLSYM_WRAPPER(int, fcntl, (int fd, int cmd, long arg), (fd, cmd, arg), "fcntl")
// DLSYM_WRAPPER(int, fcntl, (int fd, int cmd, ...), (fd, cmd, ...), "fcntl")
static int (*real_fcntl)(int fd, int cmd, ...) = nullptr;
int
dlsym_fcntl(int fd, int cmd, ...) {
    if(!real_fcntl) {
        real_fcntl = reinterpret_cast<int (*)(int fd, int cmd, ...)>(
                dlsym(((void*) -1l), "fcntl"));
        if(!real_fcntl) {
            fprintf(stderr, "dlsym failed for %s: %s\n", "fcntl", dlerror());
            (*__errno_location()) = 38;
            return (int) -1;
        }
    }
    log_arguments("fcntl", fd, cmd);
    va_list myargs;
    va_start(myargs, cmd);
    auto res = real_fcntl(fd, cmd, myargs);
    va_end(myargs);
    return res;
}

DLSYM_WRAPPER(int, access, (const char* path, int mode), (path, mode), "access")
DLSYM_WRAPPER(int, faccessat, (int dfd, const char* path, int mode, int flags),
              (dfd, path, mode, flags), "faccessat")
@@ -1268,7 +1288,7 @@ chdir(const char* path) {


int
fcntl(int fd, int cmd, long arg) // TODO
fcntl(int fd, int cmd, ...) // TODO
{
    initializeGekko();

@@ -1316,6 +1336,12 @@ fcntl(int fd, int cmd, long arg) // TODO
                    ret |= O_RDWR;
                }
                return ret;
            case F_SETFL:
                DEBUG_INFO("[GKFS] F_SETFL {}", fd);
                ret = 0;
                CTX->file_map()->get(fd)->set_flag(
                        gkfs::filemap::OpenFile_flags::rdwr, true);
                return ret;

            case F_SETFD:
                DEBUG_INFO("[GKFS] F_SETFD {}", fd);
@@ -1337,8 +1363,15 @@ fcntl(int fd, int cmd, long arg) // TODO
                return -ENOTSUP;
        }
    }
    va_list myargs;
    va_start(myargs, cmd);

    auto res = dlsym_fcntl(fd, cmd, myargs);
    va_end(myargs);
    return res;


    GKFS_FALLBACK(fcntl, fd, cmd, arg);
    // GKFS_FALLBACK(fcntl, fd, cmd, arg);
}

int