sudo ./main command throwing error

69 views
Skip to first unread message

Nitish Saboo

unread,
Jun 24, 2019, 12:48:21 PM6/24/19
to golang-nuts
Hi ,

I am using cgo in this project where I need the following given .so files.
After building the go code, I get the binary 'main'.

ubuntu@hexint09-ingest-0693b91d:/opt/tap-parsing/bin$ ls -lrt
total 17000
-rwxr-xr-x 1 parsing parsing 17405424 Jun 24 11:14 main

'./main' works fine whereas 'sudo ./main' throws the following error:

ubuntu@hexint09-ingest-0693b91d:/opt/tap-parsing/bin$ sudo ./main
./main: error while loading shared libraries: libsyslog-ng-3.6.so.0: cannot open shared object file: No such file or directory


Following is the LD_LIBRARY_PATH set to:
--------------------------------------------------------------
ubuntu@hexint09-ingest-0693b91d:/opt/tap-parsing/bin$ echo $LD_LIBRARY_PATH
 /opt/tap-parsing/dep/syslog/syslog-ng-3.6.2/install/lib/syslog-ng:/opt/tap-parsing/dep/syslog/syslog-ng-3.6.2/install/lib


ubuntu@hexint09-ingest-0693b91d:/opt/tap-parsing/bin$ cd /opt/tap-parsing/dep/syslog/syslog-ng-3.6.2/install/lib/
ubuntu@hexint09-ingest-0693b91d:/opt/tap-parsing/dep/syslog/syslog-ng-3.6.2/install/lib$ ls -lrt
total 2544
-rwxr-xr-x 1 parsing parsing 861259 Jun 24 11:14 libsyslog-ng.so
-rwxr-xr-x 1 parsing parsing   1405 Jun 24 11:14 libsyslog-ng.la
-rwxr-xr-x 1 parsing parsing 861259 Jun 24 11:14 libsyslog-ng-3.6.so.0.0.0
-rwxr-xr-x 1 parsing parsing 861259 Jun 24 11:14 libsyslog-ng-3.6.so.0
drwxr-xr-x 2 parsing parsing   4096 Jun 24 11:25 pkgconfig
drwxr-xr-x 3 parsing parsing   4096 Jun 24 11:25 syslog-ng

Parsing user details:
=================

ubuntu@hexint09-ingest-0693b91d:~$ cat /etc/passwd | grep parsing
parsing:x:1004:1006::/home/parsing:

ubuntu@hexint09-ingest-0693b91d:~$ cat /etc/group | grep parsing
parsing:x:1006:


makefile:
=======

.PHONY: all clean

all: main

main:./lib/syslog-node.so main.go ./lib/syslog-node1.h
go build -v -x main.go

./lib/syslog-node.so: ./lib/syslog-node.c ./lib/syslog-node1.h
gcc -L/usr/local/lib -lsyslog-ng -o ./lib/syslog-node.so -L/usr/local/lib/syslog-ng -ldbparser -c `pkg-config --libs --cflags glib-2.0` -I/usr/local/include/syslog-ng/ -I./lib/syslog-ng-3.6.2/ -I/usr/local/include/eventlog/ ./lib/syslog-node.c

clean:
rm main
rm ./lib/syslog-node.so


I understand I am missing a very small point here but couldn't just figure it out.
Can someone please guide me here ?


Thanks,
Ntiish

Marcin Romaszewicz

unread,
Jun 24, 2019, 1:33:08 PM6/24/19
to Nitish Saboo, golang-nuts
sudo does not preserve environment variables for security reasons, run:

sudo echo $LD_LIBRARY_PATH

You'll likely see that it's empty, unless you have a global system one set.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3cc0a8f8-8b39-4948-9084-55a0b6628399%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Stiller

unread,
Jun 24, 2019, 2:07:50 PM6/24/19
to Nitish Saboo, golang-nuts
Hi,

i think sudo kills the LD_LIBRARY_PATH variable.

But this is configurable, try something like:

Defaults env_keep += “LD_LIBRARY_PATH"

in /etc/sudoers and / or consult the sudo man page.

Best regards,

Michael
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3cc0a8f8-8b39-4948-9084-55a0b6628399%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
2scale GmbH, Schanzenstr. 20, 40549 Düsseldorf
Amtsgericht: Düsseldorf HRB 50718
Geschäftsführer: Georg von Zezschwitz, Dirk Vleugels
USt-IdNr.: DE 210936505





Michael Anderson

unread,
Jun 24, 2019, 2:15:22 PM6/24/19
to golan...@googlegroups.com

You could try:

sudo -E bash -c 'echo $LD_LIBRARY_PATH'

The -E is --preserve-env


On 6/24/19 12:32 PM, Marcin Romaszewicz wrote:
sudo echo $LD_LIBRARY_PATH

Nitish Saboo

unread,
Jun 25, 2019, 2:06:17 AM6/25/19
to Michael Anderson, golang-nuts
HI Michael,

Looks like it is still not preserving the env variable:

nsaboo@ubuntu:~/Documents/goworkspace/src/poc$ export LD_LIBRARY_PATH=/usr/local/lib/syslog-ng
nsaboo@ubuntu:~/Documents/goworkspace/src/poc$ sudo -E bash -c 'echo $LD_LIBRARY_PATH'

nsaboo@ubuntu:~/Documents/goworkspace/src/poc$ echo $LD_LIBRARY_PATH
/usr/local/lib/syslog-ng
nsaboo@ubuntu:~/Documents/goworkspace/src/poc$ 

Thanks,
Nitish

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Kurtis Rader

unread,
Jun 25, 2019, 2:26:55 AM6/25/19
to Nitish Saboo, golang-nuts
That means your "sudo" configuration doesn't allow the use of the `-E` flag; at least in that specific use case. Alternatively, your system doesn't preserve the value of `LD_LIBRARY_PATH` when the shell is invoked via `sudo -E` because the shell's startup scripts clobber that var.

I hope you recognize this isn't a Go issue. You'll need to figure out how to configure "sudo" on your system to meet your requirements and/or modify the bash startup scripts for the root account not overwrite the value of `LD_LIBRARY_PATH`.

On Mon, Jun 24, 2019 at 11:06 PM Nitish Saboo <nitish....@gmail.com> wrote:
Looks like it is still not preserving the env variable:

nsaboo@ubuntu:~/Documents/goworkspace/src/poc$ export LD_LIBRARY_PATH=/usr/local/lib/syslog-ng
nsaboo@ubuntu:~/Documents/goworkspace/src/poc$ sudo -E bash -c 'echo $LD_LIBRARY_PATH'

nsaboo@ubuntu:~/Documents/goworkspace/src/poc$ echo $LD_LIBRARY_PATH
/usr/local/lib/syslog-ng
nsaboo@ubuntu:~/Documents/goworkspace/src/poc$ 

--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Reply all
Reply to author
Forward
0 new messages