Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

intercept open does not work #847

Closed
markus2330 opened this issue Jul 21, 2016 · 12 comments
Closed

intercept open does not work #847

markus2330 opened this issue Jul 21, 2016 · 12 comments
Assignees
Labels
Milestone

Comments

@markus2330
Copy link
Contributor

When doing what the example says, intercept does not intercept (on debian jessie):

$ kdb export /preload/open ini
~\/testfile = ~/testreplacement
$ LD_PRELOAD=~build/lib/libelektraintercept.so cat ~/testfile
testfile

open is correctly intercepted, the problem seems to be the matching with ~, maybe zsh has some different behaviour? Can you also try kdb export? Giving full paths everything works.

@markus2330 markus2330 added the bug label Jul 21, 2016
@markus2330 markus2330 added this to the 0.8.18 milestone Jul 21, 2016
@markus2330
Copy link
Contributor Author

And it has compile warnings:

src/bindings/intercept/intercept.c:221:14: warning: ISO C forbids conversion of object pointer to function pointer type [-Wpedantic]
  orig_open = (orig_open_f_type)dlsym (RTLD_NEXT, "open");
              ^
src/bindings/intercept/intercept.c: In function ‘open64’:
src/bindings/intercept/intercept.c:259:16: warning: ISO C forbids conversion of object pointer to function pointer type [-Wpedantic]
  orig_open64 = (orig_open_f_type)dlsym (RTLD_NEXT, "open64");
                ^

@tom-wa
Copy link
Contributor

tom-wa commented Jul 21, 2016

thomas@Skipper ~ % echo $SHELL
/bin/zsh
thomas@Skipper ~ % kdb export /preload ini
[open]
~\/.zshrc = ~/.zshrc-other
~\/.zshrc/readonly = 1
~\/testfile = ~/testreplacement
thomas@Skipper ~ % cat ~/testfile
cat: /home/thomas/testfile: Datei oder Verzeichnis nicht gefunden
thomas@Skipper ~ % cat ~/testreplacement
replacement
thomas@Skipper ~ % LD_PRELOAD=/usr/local/lib/libelektraintercept.so cat ~/testfile
replacement

@markus2330
Copy link
Contributor Author

kdb export /preload ini seems to be identical, so maybe it is a zsh version thing zsh 5.0.7 (x86_64-pc-linux-gnu)? Has libelektraintercept.so problems when working from the build-folder? Do you have another idea? Can you write a shellrecorder test suite, it might be easier to reproduce this way.

Btw. libelektraintercept.so is a very generic name, what about changing it to libelektraintercept-open.so and libelektraintercept-getenv.so?

A small wrapper script such as scripts/elektrify-getenv.in would be nice, too.

@tom-wa
Copy link
Contributor

tom-wa commented Jul 21, 2016

just tried it on all my boxes (all running zsh), and for me it works on all.
but it seems like you have some custom expansion for ~ like in ~build ?
i'm running zsh 5.2 (x86_64-debian-linux-gnu)

for me even ~\/..\/.\/thomas\/.zshrc = ~/../.././home/thomas/./.zshrc-other works just fine

@tom-wa
Copy link
Contributor

tom-wa commented Jul 21, 2016

i've just built and installed it on a clean debian stable box running zsh 5.0.7 (i586-pc-linux-gnu)

thomas@Kowalski ~/libelektra/build
 % kdb export /preload ini
[open]
~\/.zshrc/readonly = 1
~\/testfile = ~/testreplacement
~\/..\/.\/thomas\/.zshrc = ~/../.././home/thomas/./.zshrc-other
thomas@Kowalski ~/libelektra/build
 % vim ~/preload.ini
thomas@Kowalski ~/libelektra/build
 % kdb export /preload ini
[open]
~\/testfile = ~/testreplacement
~\/..\/.\/thomas\/.zshrc = ~/../.././home/thomas/./.zshrc-other
thomas@Kowalski ~/libelektra/build
 % cat ~/testfile
testfile
thomas@Kowalski ~/libelektra/build
 % cat ~/testreplacement
testreplacement
thomas@Kowalski ~/libelektra/build
 % cat ~/.zshrc-other
zshrc-other
thomas@Kowalski ~/libelektra/build
 % LD_PRELOAD=/usr/local/lib/libelektraintercept.so cat ~/testfile
testreplacement
thomas@Kowalski ~/libelektra/build
 % LD_PRELOAD=/usr/local/lib/libelektraintercept.so cat ~/.zshrc
zshrc-other

@markus2330
Copy link
Contributor Author

Seems to have nothing to do with zsh config (same problem in zsh -f) nor zsh itself (same problem in bash), but I can reproduce it on another machine too:

markusbyte% kdb set /preload/open/\~\\/testfile "~/testreplacement"
Using name user/preload/open/~\/testfile
Set string to ~/testreplacement
markusbyte% LD_PRELOAD=/home/markus/Projekte/Elektra/build/lib/libelektraintercept.so cat ~/testfile
testfile
markusbyte% kdb export /preload ini
[open]
~\/testfile = ~/testreplacement
markusbyte% cat testfile 
testfile
markusbyte% cat testreplacement 
testreplacement

markus@markusbyte:~> bash 
markus@markusbyte:~$ kdb set /preload/open/\~\\/testfile "~/testreplacement"
Using name user/preload/open/~\/testfile
Set string to ~/testreplacement
markus@markusbyte:~$ kdb export /preload ini
[open]
~\/testfile = ~/testreplacement
markus@markusbyte:~$ LD_PRELOAD=/home/markus/Projekte/Elektra/build/lib/libelektraintercept.so cat ~/testfile
testfile

I think the most likely problem is some typo in the example (I already fixed two problems), please try to source the example and write some shellrecorder tests.

markus2330 pushed a commit that referenced this issue Jul 21, 2016
@tom-wa
Copy link
Contributor

tom-wa commented Jul 21, 2016

i really can't reprocude the problem here. on none of my boxes.

thomas@Private ~ % kdb set /preload/open/\~\\/testfile "~/testreplacement"
Using name user/preload/open/~\/testfile
Create a new key user/preload/open/~\/testfile with string ~/testreplacement
thomas@Private ~ % kdb export /preload
[open]
~\/testfile = ~/testreplacement
thomas@Private ~ % echo testfile > ~/testfile
thomas@Private ~ % echo testreplacement > ~/testreplacement
thomas@Private ~ % LD_PRELOAD=/path/to/libelektraintercept.so cat ~/testfile
ERROR: ld.so: object '/path/to/libelektraintercept.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
testfile
thomas@Private ~ % LD_PRELOAD=/usr/local/lib/libelektraintercept.so cat ~/testfile                                           
testreplacement

@markus2330
Copy link
Contributor Author

markus2330 commented Jul 21, 2016

Ok, the problem is that the key /preload/open must exist which does on your machines (because you use ini as default), but does not when another default storage plugin is used.

Please update the example and add shell recorder tests.

@markus2330
Copy link
Contributor Author

(and fix warnings), then we can close the issue

@markus2330
Copy link
Contributor Author

I hope @sanssecours finds a solution for such problems, different behaviour in storage plugins is really a pain.

This was referenced Jul 21, 2016
@tom-wa
Copy link
Contributor

tom-wa commented Jul 22, 2016

(and fix warnings), then we can close the issue

is it ok if i just use pragma to turn warnings off for those 2 lines ? it seems like the behaviour/use of dlsym is actually undefined behaviour according to the man page.

@markus2330
Copy link
Contributor Author

There are other places that already fix the problem. You can use memcpy or a union.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants