LD_LIBRARY_PATH unset by screen

12

3

Running screen in bash wipes the variable LD_LIBRARY_PATH. I've done some reading and it seems that this is expected behaviour, but I need to get around it.

The workaround is adding the LD_LIBRARY_PATH declaration to ~/.bashrc. In my case, LD_LIBRARY_PATH gets changed a lot between the launch of the shell and when I invoke screen, so I need to get the current value of LD_LIBRARY_PATH into the screen session.

Andrew Wood

Posted 2011-01-20T14:52:58.293

Reputation: 1 139

you have export LD_KLIBRARY_PATH before run screen? – kinnou02 – 2011-01-20T14:56:30.443

Superuser question. – karlphillip – 2011-01-20T14:57:25.763

Sorry, can I somehow move it over, or should I delete and repost? – None – 2011-01-20T15:07:44.377

If you get five close votes, it will be bumped there automatically. One more to go! – Thomas – 2011-01-20T17:29:29.890

Answers

14

screen doesn't unset the environment variable; it is removed by Linux itself.

On most systems, the /usr/bin/screen executable is installed with the setgid bit for utmp group, in order to be able to modify the utmp database. It also uses setgid to control access to the socket directory (/var/run/screen/).

On Linux, when a setuid (or setgid) program is ran, it does not receive certain environment variables (including LD_LIBRARY_PATH, several other LD_* variables, and HOSTALIASES), in order to reduce the possible attack points: Otherwise you could write a small library and trick su or sudo into calling your "improved" functions that way.


You can remove the setgid bit from screen, but you will have to make the socket directory fully accessible by everyone (mode 0777). It shouldn't be a security risk, though, as screen also checks the attacher's UID itself.

However, you should not make the utmp database world-writable.

user1686

Posted 2011-01-20T14:52:58.293

Reputation: 283 655

(Note: I am not quite sure whether the environment variables are removed by the kernel, or by ld-linux.so, or by glibc runtime.) – user1686 – 2014-10-03T07:53:28.277

Worked really fine. These are the commands that need to be done: chgrp root $(which screen) and chmod 777 /var/run/screen. You can test with this small bash script: while true; do echo $LD_LIBRARY_PATH; sleep 2; done You will see that the path is successfully displayed. Thanks grawity. – lepe – 2015-12-04T09:31:14.830

7

In your .screenrc, you can use the setenv command to set a value in screen's environment.

setenv LD_LIBRARY_PATH $LD_LIBRARY_PATH_SCREEN

This is set before your shell is started. Obviously LD_LIBRARY_PATH_SCREEN needs to be set before you start screen.

Droj

Posted 2011-01-20T14:52:58.293

Reputation: 309

1

See grawity's answer -- LD_LIBRARY_PATH is a special variable in this context. Even if this worked (setenv doesn't need to '=', btw) it wouldn't be very helpful to rename the environment variable we're trying to set; programs would still be looking at the canonical name (see http://stackoverflow.com/questions/13974069/setting-environment-variables-in-screenrc).

– Andrew Wood – 2013-11-06T14:07:37.573

Than's for the correction. I fixed the syntax and had forgotten that I had a different variable in the environment starting screen. The _SCREEN one can be set in your rc file or in a wrapper script that starts screen. – Droj – 2013-11-27T19:53:55.933

1

Try exporting the environment variable you are interested in.

export LD_LIBRARY_PATH

Benjamin Bannier

Posted 2011-01-20T14:52:58.293

Reputation: 13 999