SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm setting my CLASSPATH in /etc/profile.d/jre.sh. In a login shell, everything is fine. In an xterm window, the CLASSPATH consists of two of every intended entry. In jre.sh I am doing a
Code:
export CLASSPATH=$CLASSPATH:/many/paths/to/jars
So I'm guessing this is getting run twice in the xterm case. Can someone explain what's going on here and what I should do to remedy this? TIA
The fact that in a login shell the classpath looks fine tells me that I'm not doing anything stupid like exporting it twice. I suspect that /etc/profile.d/jre.sh is being run a second time when I open an xterm. I could fix this by changing
Code:
export CLASSPATH=$CLASSPATH:/many/paths/to/jars
to
Code:
export CLASSPATH=/many/paths/to/jars
But I'd like to know why this is happening just the same. Indeed before this export statement CLASSPATH is an empty string, but I'm not convinced this is generally true. Unless someone knows this is true . . .
What is the window manager / login environment? (kde, xfce, other?) Have you customized any of the session startup scripts?
My guess is that /etc/profile is running twice. Once from the Xsession startup file (or equivalent), at login time. The environment of that process is inherited by all your other session processes. Then your xterm is running /etc/profile itself, perhaps because it thinks it is a login shell. This would double up CLASSPATH, but also some others like MANPATH would have double JAVA_HOME/man entries. (Does MANPATH have this?)
I'm using gnomeslack for login and xfce for a window manager. I don't believe I've done any customization. MANPATH is not doubled up like CLASSPATH. As I've said, I put my CLASSPATH setting in /etc/profile.d/jre.sh but this script is run by /etc/profile, so I believe that /etc/profile is being run twice.
You might try grepping for instances of "CLASSPATH=" or "export CLASSPATH" in files throughout your system. An example might be:
Code:
grep -Erl 'CLASSPATH=' / 2>/dev/null
So it searched recursively from the / of the filesystem, and shows the filename where the occurrence happens. Check each file for instances of CLASSPATH="${CLASSPATH}:...blah..blah.." or CLASSPATH="$CLASSPATH:..blah..blah.."
I don't seem to have much in the way of "CLASSPATH" being set anywhere in my system, but as a sample of what the output would resemble, here I searched for "export PATH" and got expected results (and a few dozen others!):
There is a bug in the profile.d scripts that appends some paths instead of replacing them. I think it will be fixed in the next slackware release (or current soon).
In your example, each time something executes "source /etc/profile" CLASSPATH gets appended instead of replaced.
You have to prevent your shells from executing (for second time) "source /etc/profile", check your profile scripts (.bashrc, .bash_profile etc) so they don't do that.
The correct solution is to make the profile.d scripts create PATHs from scratch and not append.
GrapefruiTgirl: I tried doing a search for 'CLASSPATH=' but either it takes a really long time or my computer hung. Either way I did not get any output from the grep.
AppDeb: I'm glad to hear that the scripts in /etc/profile.d are supposed to create paths and not append to them and that is what I ended up doing: removing the append that I was doing on CLASSPATH. It looks OK now.
My .bashrc and .bash_profile do not source /etc/profile so that wasn't the problem. And now that it looks OK I don't think I'm affected by the bug you spoke of.
Unfortunately, I still don't understand what was going on. My jre.sh in /etc/profile.d must have been called a second time when I open a terminal window but I don't see how.
You might want to try adding some logging to jre.sh to confirm this. For example, add this
(date; echo "jre.sh is running in $$") >> /tmp/log
This will record the date and process ID. Log out and back in and look at the /tmp/log file. At least, it will confirm the file is running twice, and it might help track down why. (You may see two entries with the same PID, or a parent/child pair.)
If your xterm starts as a "login shell" it sources /etc/profile (and .profile in your home) on start, and that is the second time in your case, because Xorg has already been started from a login shell.
You have to start xterm as an "interactive shell" so that it doesn't source /etc/profile on startup.
The xfce terminal and the gnome terminal by default start an interactive shell (but in the options you have a choice for login shell). I don't know what xterm does.
update:
From the xterm manual page
Quote:
+ls This option indicates that the shell that is started should not
be a login shell (i.e., it will be a normal “subshell”).
So you can try starting it with "xterm +ls" and the profile should not be sourced for second time.
Fixing this problem by modifying /etc/profile.d/jre.sh to set CLASSPATH (rather than add to it) will cause breakage if and when some other script, run before jre.sh, needs to modify CLASSPATH.
One possible reason for the problem is that /etc/profile is run as normal when startin a login shell (including a graphical login shell) and then, when a non-login interactive shell is started (when starting xterm), ~/.bashrc is run as normal and sources /etc/profile -- resulting in running /etc/profile.d/jre.sh twice.
If this is the case, there are two solutions: either remove the sourcing of /etc/profile from .bashrc (preferred because it may not only be jre.sh+CLASSPATH that is going wrong) or modifying jre.sh to only add the directory to CLASSPATH if CLASSPATH does not already contain it.
Details of bash' startup file usage are in the man page and GNU Bash Reference
Last edited by catkin; 08-03-2010 at 03:25 AM.
Reason: Added ", run before jre.sh,"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.