Unable to load libsctp.so for non root user
I have a Linux application that uses the libsctp.so library. When I run it as root, it runs 开发者_StackOverflowfine.
But when I run it as an ordinary user, it gives the following error:
error while loading shared libraries: libsctp.so.1: cannot open shared object file: No such file or directory
But, when I do ldd as ordinary user, it is able to see the library:
[sanjeev@devtest6 src]$ ldd myapp
... ... libsctp.so.1 => /usr/local/lib/libsctp.so.1 (0x00d17000)
[sanjeev@devtest6 src]$ ls -lL /usr/local/lib/libsctp.so.1
-rwxrwxrwx 1 root root 27430 2009-06-29 11:26 /usr/local/lib/libsctp.so.1
[sanjeev@devtest6 src]$
What could be wrong? How is the ldd is able to find libsctp.so, but when actually running the app, it is not able to find the same library?
EDIT: Just observed that this problem appears only if setuid bit is set for myapp.
I had the same exception on Ubuntu 18.04, after executing the following code:
SctpServerChannel s = SctpServerChannel.open();
The issue was solved after running:
sudo apt-get install libsctp1
Fixed the problem. I added a new file in /etc/ld.so.conf.d with the followng name:
libsctp.so.1.conf
The contents of libsctp.so.1.conf is as follows:
/usr/local/lib/
And then ran
/sbin/ldconfig
, after which my app ran successfully.
Explanation: Since the setuid bit was set, the program is executed as root, for whom LD_LIBRARY_PATH is not available. Hence it is not able to find libsctp.so. I was not aware of this because when I login as root, .bashrc gets executed and LD_LIBRARY_PATH becomes available.
It could be because of environment setting difference.
You may need to add /usr/local/lib/
to LIBRARY_PATH or kind of.
You can recieve that error if a shared library that libsctp.so
itself depends on is not found (yes, it is a little confusing). Try ldd
on the library itself:
ldd /usr/local/lib/libsctp.so.1
Are you setting LD_LIBRARY_PATH
before switching to root user or after that? When you run ldd
as root does it still find all dependent libraries?
dmitry@debian:~$ echo $LD_LIBRARY_PATH dmitry@debian:~$ export LD_LIBRARY_PATH=/usr/local/lib dmitry@debian:~$ echo $LD_LIBRARY_PATH /usr/local/lib dmitry@debian:~$ su Password: debian:/home/dmitry# echo $LD_LIBRARY_PATH debian:/home/dmitry#
精彩评论