Find the answer to your Linux question:
Results 1 to 2 of 2
Hi all. I'm trying to override PWRITE64 syscall (and maybe others) when using oracle database. I created a shared library and it runs my code, but when I call the ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    4

    oracle: error overriding PWRITE64 with LD_PRELOAD

    Hi all.
    I'm trying to override PWRITE64 syscall (and maybe others) when using oracle database.
    I created a shared library and it runs my code, but when I call the original pwrite, it errors out.
    I guess there's something wrong in my code, but I'm new at c languaje, can someone tell me what am I doing wrong? This is the code;

    #define _GNU_SOURCE
    #include <stdio.h>
    #include <dlfcn.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>


    ssize_t pwrite64(int fd, const void *buf, size_t count, off_t offset) {
    ssize_t (*real_open)(int fd, const void *buf, size_t count, off_t offset);
    static int filedesc;
    ssize_t retorno;

    filedesc=open("/home/oracle/prman/traza_pwrite64",O_RDWR);
    pwrite(filedesc, "first trace \n", 19,0);
    close(filedesc);

    if (!real_open) {
    real_open = dlsym(RTLD_NEXT, "pwrite64");
    }

    filedesc=open("/home/oracle/prman/traza_pwrite64",O_RDWR);
    pwrite(filedesc, "scnd trace \n", 19,0);
    close(filedesc);

    retorno=real_open(fd, buf, count, offset);

    filedesc=open("/home/oracle/prman/traza_pwrite64",O_RDWR);
    pwrite(filedesc, "third trace \n", 19,0);
    close(filedesc);

    return retorno;
    }

    When Oracle uses pwrite64 it errors, and third trace is never written into the trace file, can somebody help me?

  2. #2
    Just Joined!
    Join Date
    Dec 2009
    Posts
    4
    Hi all. Thanks for your time.
    I think the only problem was that I had to initialize real_open pointer to NULL before point it to the original PWRITE64 function:

    real_open=NULL;

    this seems to make it work

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...