Verified Commit 71606ea7 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Intercept __open{at,}{64,}_2

`tar` and other gnu coreutils are using __openat{64,}_2 variant.
We need to intercept also that apart of the main `openat` function.

StackOverflow related question [1]

[1]: https://stackoverflow.com/questions/9161116/intercepting-the-openat-system-call-for-gnu-tar
parent 83cc0e40
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -32,6 +32,19 @@ size_t intcp_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
strong_alias(intcp_fwrite, fwrite)
strong_alias(intcp_fwrite, fwrite_unlocked)

int intcp_open(const char* path, int flags, ...);
strong_alias(intcp_open, open)
strong_alias(intcp_open, __open_2)
int intcp_open64(const char* path, int flags, ...);
strong_alias(intcp_open64, open64)
strong_alias(intcp_open64, __open64_2)
int intcp_openat(int dirfd, const char *cpath, int flags, ...);
strong_alias(intcp_openat, openat)
strong_alias(intcp_openat, __openat_2)
int intcp_openat64(int dirfd, const char *path, int flags, ...);
strong_alias(intcp_openat64, openat64)
strong_alias(intcp_openat64, __openat64_2)

#endif // IFS_INTCP_FUNCTIONS_HPP

} // extern C
+6 −6
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ void inline notsup_error_32_bit_func(const char* func = __builtin_FUNCTION()) {
    CTX->log()->error("{}() is NOT SUPPORTED. According to glibc, this function should be called only on 32-bit machine", func);
}

int open(const char* path, int flags, ...) {
int intcp_open(const char* path, int flags, ...) {
    init_passthrough_if_needed();

    mode_t mode = 0;
@@ -45,7 +45,7 @@ int open(const char* path, int flags, ...) {

#undef open64

int open64(const char* path, int flags, ...) {
int intcp_open64(const char* path, int flags, ...) {
    init_passthrough_if_needed();
    mode_t mode = 0;
    if (flags & O_CREAT) {
@@ -54,10 +54,10 @@ int open64(const char* path, int flags, ...) {
        mode = va_arg(ap, mode_t);
        va_end(ap);
    }
    return open(path, flags | O_LARGEFILE, mode);
    return intcp_open(path, flags | O_LARGEFILE, mode);
}

int openat(int dirfd, const char *cpath, int flags, ...) {
int intcp_openat(int dirfd, const char *cpath, int flags, ...) {
    init_passthrough_if_needed();

    mode_t mode = 0;
@@ -112,7 +112,7 @@ int openat(int dirfd, const char *cpath, int flags, ...) {
    return LIBC_FUNC(openat, dirfd, resolved.c_str(), flags, mode);
}

int openat64(int dirfd, const char *path, int flags, ...) {
int intcp_openat64(int dirfd, const char *path, int flags, ...) {
    init_passthrough_if_needed();

    mode_t mode = 0;
@@ -123,7 +123,7 @@ int openat64(int dirfd, const char *path, int flags, ...) {
        va_end(vl);
    }

    return openat(dirfd, path, flags | O_LARGEFILE, mode);
    return intcp_openat(dirfd, path, flags | O_LARGEFILE, mode);
}

/******  FILE OPS  ******/