Find the answer to your Linux question:
Results 1 to 4 of 4
While intercepting read system call, I'm trying to get find the filename for a given file descriptor and print it. For this, I'm trying to invoke the readlink system call ...
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    4

    Invoking readlink system call from user space

    While intercepting read system call, I'm trying to get find the filename for a given file descriptor and print it. For this, I'm trying to invoke the readlink system call from user space...

    /*global declaration*/
    asmlinkage long (*original_readlink)(const char __user *,char __user *, int bufsiz);

    /*Inside my_sys_read */
    int len=0;
    char readfilepath[100];
    len = original_readlink("/proc/1735/fd/4",readfilepath,99);

    /* In my init()*/
    original_readlink=(void *)syscall_table[__NR_readlink];

    But when I invoke this readlink function, Im getting a return value of -14. It is supposed to return -1 for an error and 0 for a success.. But I get -14. Do any of you have an idea on this? If so please could you help me...

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,977
    What function does original_readlink() point to. It is a pointer to a function, but you don't show what function it has been assigned. FWIW, the readlink() function is a user-space function that does what you want. Read the man page: man 2 readlink
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    4
    Thank you for your response...

    I initially tried using readlink function directly, but it threw up a compile-time error,
    error: implicit declaration of function ‘readlink’

    I included the header <asm/unistd.h>

    My unistd.h has only the macro defined for readlink system call...

    #define __NR_readlink 1035
    __SYSCALL(__NR_readlink, sys_readlink)

    Please let me know how can I invoke readlink in this case...

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,977
    What happens if you only #include <unistd.h>? That should work. If it doesn't, then your compiler installation may be broken...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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