Closed orbea closed 2 years ago
Agreed, there is a growing list of possible errors https://github.com/haampie/libtree/blob/4f16a1be6a591424a8b1b1658bb61a64495aee0d/libtree.c#L29-L48 when trying to parse an ELF file, it's just that this is not presented properly to the user.
There are also some hard-coded return 1
's, I see.
Here is another one, a non-valid text file...
$ ./libtree /usr/lib64/libgcc_s.so ; echo $?
1
$ file /usr/lib64/libgcc_s.so
/usr/lib64/libgcc_s.so: ASCII text
This is fixed on master now, let me know if it's helpful. It should show:
$ ./libtree CHANGELOG.md
Error [CHANGELOG.md]: Invalid ELF magic bytes
$ ./libtree -- -.o
Error [-.o]: Not an ET_EXEC or ET_DYN ELF file
$ ./libtree tests/03_direct_and_absolute_rpath/exe_a 1>/dev/null
Error [tests/03_direct_and_absolute_rpath/exe_a]: Not all dependencies were found
Added it to 3.0.0-rc4
Thanks that is better, but with commit 79649ee26a2a077f622438699cd9bc0296194369 I am seeing a problem when redirecting the output to a file with tee(1)
.
For example here is an excerpt from the output of running this on many libraries at once.
$./libtree /usr/lib64/libX*.so 2>&1 | tee /tmp/libtree.log
....
libXss.so.1
├── libX11.so.6 [ld.so.conf]
└── libXext.so.6 [ld.so.conf]
libXt.so.6
libXtst.Error [/usr/lib64/libXvMCgallium.so]: Could not open file
so.6
├── libX11.so.6 [ld.so.conf]
├── libXi.so.6 [ld.so.conf]
└── libXext.so.6 [ld.so.conf]
....
Notice how the error message is printed at the same time as other libraries breaking the log.
Okay, I've added flushing, so that should be gone.
Yes, that works well now with commit b0d955b96e8a9b592e0c238a78d797ab4d449118.
libXvMCW.so.1
├── libX11.so.6 [ld.so.conf]
├── libXv.so.1 [ld.so.conf]
└── libXext.so.6 [ld.so.conf]
Error [/usr/lib64/libXvMCgallium.so]: Could not open file
libXxf86dga.so.1
├── libX11.so.6 [ld.so.conf]
└── libXext.so.6 [ld.so.conf]
I also retested my examples locally.
# missing file
$ ./libtree foo ; echo $?
Error [foo]: Could not open file
31
# broken symlink
$ ./libtree /usr/lib64/libXvMCgallium.so ; echo $?
Error [/usr/lib64/libXvMCgallium.so]: Could not open file
31
# static archive
$ ./libtree /usr/lib64/libc.a ; echo $?
Error [/usr/lib64/libc.a]: Invalid ELF magic bytes
11
# text file
$ ./libtree /usr/lib64/libgcc_s.so ; echo $?
Error [/usr/lib64/libgcc_s.so]: Invalid ELF magic bytes
11
Seems much better now, thanks!
I think with all these fixes we're close to 3.0.0 then!
libtree: 4f16a1be6a591424a8b1b1658bb61a64495aee0d
There is lacking error handling in libtree, for example.
It would be good if there were appropriate warnings or error messages in these cases. Its currently not at all obvious why libtree fails when executing it on large number of files which happen to have such examples.