Question

Does there is usual utility which makes a substitution on some calls like execve and open? Like LD_PRELOAD for calls.

Example:

  • we have prog_A which uses prog_B.
  • some days ago prog_B was updated and now prog_A failed!(
  • usual solution is the next:

    $: mv /usr/bin/prog_b /usr/bin/prog_B.new
    $: ln -s /usr/bin/prog_b.old /usr/bin/prog_b
    $: ./prog_a                                       # now run 
    

    but sometimes it's uncomfortably and dirty solution. In some stories the correct way to do so:

    $: util "execve+open+stat:/usr/bin/prog_b=/usr/bin/prog_b.old" ./prog_a
    

    where execve,open & stat are system calls. What is the name of this util?

    Was it helpful?

    Solution

    I just write a special FILE_PRELOAD utility to solve my problem.

    $: FILE_PRELOAD -C "execve+open+stat:/usr/bin/prog_b:/usr/bin/prog_b.old" ./prog_a
    

    it generates c++ code, then compiles it and then LD_PRELOAD the result lib.so file before run ./prog_a.

    Using it you can hook the next calls:

    1. open,fopen,fopen64
    2. opendir,mkdir,rmdir
    3. execve
    4. unlink,unlinkat
    5. stat,lstat,lstat64,_lxstat,_lxstat64,stat64
    6. _xstat,_xstat64,__fxstatat
    7. freopen,freopen64

    Please, run docs/tut.sh firstly (it's a tutorial for FP utility).

    OTHER TIPS

    The common solution is the symlink solution. It isn't dirty. Have a look at debian or Ubuntu for example. They have /etc/alternatives for that purpose.

    Here comes an example listing for the view command on Ubuntu:

    user@server ls -al /usr/bin/view
    lrwxrwxrwx 1 root root 22 Dez  5  2009 /usr/bin/view -> /etc/alternatives/view
    user@server ls -al /etc/alternatives/view
    lrwxrwxrwx 1 root root 18 Dez  5  2009 /etc/alternatives/view -> /usr/bin/vim.basic
    
    Licensed under: CC-BY-SA with attribution
    Not affiliated with StackOverflow
    scroll top