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

fcntl loop

parent 96836fc5
Loading
Loading
Loading
Loading
+14 −22
Original line number Diff line number Diff line
@@ -343,24 +343,6 @@ DLSYM_WRAPPER(int, chown, (char* path, uid_t owner, gid_t group),
              (path, owner, group), "chown")
// 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),
@@ -715,10 +697,10 @@ get_open_fds() {

    dlsym_closedir(dir);

    fds.erase(std::remove_if(fds.begin(), fds.end(),
   /* fds.erase(std::remove_if(fds.begin(), fds.end(),
                             [](int fd) { return fcntl(fd, F_GETFD) < 0; }),
              fds.end());

*/
    return fds;
}

@@ -1363,10 +1345,20 @@ fcntl(int fd, int cmd, ...) // TODO
                return -ENOTSUP;
        }
    }

   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 = dlsym_fcntl(fd, cmd, myargs);
    auto res = real_fcntl(fd, cmd, myargs);
    va_end(myargs);
    return res;