Re: [PATCH] Fix hang if $OLDPWD points to inaccessible directory
Chet Ramey wrote: This is all correct. The change was introduced for a reason, and accommodating a rare occurrence by backing it out would be non- productive. --- The reason?: Why does bash clear OLDPWD when a child script is started? OLDPWD is exported and passed to any children, but bash apparently clears OLDPWD whenever a child script is started... GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu) Can bash be fixed to preserve the value of any OLDPWD in its initial environment, like it does with PWD? --- I don't see a reason... I see a "want", but no real reason I'd agree it's a rare event to hit though, but when you do... Requires console access, but changing /etc/profile to insert a bad OLDPWD to a known down network location might not be considered a trivial occurrence to someone stressed out and trying to log in and find out why everyone logging in is hanging...
Re: [PATCH] Fix hang if $OLDPWD points to inaccessible directory
On Thu, 28 Sep 2017, Eduardo A. Bustamante López wrote: > On Thu, Sep 28, 2017 at 11:44:02AM +0200, Mikulas Patocka wrote: > [...] > > +++ bash/variables.c > > @@ -899,7 +899,7 @@ set_pwd () > > don't find OLDPWD in the environment, or it doesn't name a directory, > > make a dummy invisible variable for OLDPWD, and mark it as exported. > > */ > >temp_var = find_variable ("OLDPWD"); > > - if (temp_var == 0 || value_cell (temp_var) == 0 || file_isdir > > (value_cell (temp_var)) == 0) > > + if (temp_var == 0 || value_cell (temp_var) == 0) > > { > >temp_var = bind_variable ("OLDPWD", (char *)NULL, 0); > > This patch would revert the change introduced in: > > http://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=e6f5e0c858b7c0839d346d7d55e56894648c5a33 This patch doesn't revert the above change. It only removes a test if $OLDPWD is a directory. With this patch, if $OLDPWD points to a directory, there will be no change, and if $OLDPWD points to non-directory, it will not be cleared. > Which was prompted by the following bug report from John Wiersba: > https://lists.gnu.org/archive/html/bug-bash/2015-11/msg00115.html > > Correct me if I'm wrong, but a hanged sshfs mount will cause many more > issues, not only with OLDPWD. Hung mount shouldn't cause problems unless someone is accessing it. What happened to me - I use the autofs filesystem to automatically mount filesystems on various machines. I was on some autofs-mounted directory, I moved to the home directory (which is not on autofs) and I typed startx. Some times after that I shut down the remote machine that provided the autofs mount. The whole X session started to severely mibehave, starting various programs caused hangs, I couldn't even start an xterm with the shell, I couldn't even start the chome browser - the reason for the hangs was, that the OLDPWD variable pointing to the autofs directory ended up being propagated to the Xserver, to the desktop environment and to any program that was running within the X session. I caused serious trouble and I think it should be fixed. If I started Xwindow on the non-functioning autofs directory, it would be expected that I get hangs. However, I started Xwindow in the home directory that has nothing to do with autofs - and I got hangs. Mikulas > I tried the following: > > dualbus@ubuntu:~/test$ ls -l > total 4 > drwxr-xr-x 2 dualbus dualbus 4096 sep 28 10:05 host > dualbus@ubuntu:~/test$ sshfs $host: host > dualbus@ubuntu:~/test$ ls -ld host > drwxr-xr-x 1 dualbus dualbus 20480 sep 28 08:15 host > dualbus@ubuntu:~/test$ cd host > dualbus@ubuntu:~/test/host$ pwd > /home/dualbus/test/host > dualbus@ubuntu:~/test/host$ cd .. > dualbus@ubuntu:~/test$ df host | sed "s/$host//" > Filesystem 1K-blocks Used Available Use% Mounted on > : 20511592 13003368 6452528 67% /home/dualbus/test/host > dualbus@ubuntu:~/test$ sudo iptables -A OUTPUT -p tcp -d $host -j DROP > dualbus@ubuntu:~/test$ ls > ^C^C^C^C^C > > Also tried: > > cd ho # hangs > cd host # hangs > ls -l host # hangs > > So in my opinion, it's not worth to revert this change given that you'll have > many more troubles with a hanged network filesystem. >
Re: [PATCH] Fix hang if $OLDPWD points to inaccessible directory
On Fri, 29 Sep 2017, Mikulas Patocka wrote: > > > On Thu, 28 Sep 2017, Eduardo A. Bustamante López wrote: > > > On Thu, Sep 28, 2017 at 11:44:02AM +0200, Mikulas Patocka wrote: > > [...] > > > +++ bash/variables.c > > > @@ -899,7 +899,7 @@ set_pwd () > > > don't find OLDPWD in the environment, or it doesn't name a > > > directory, > > > make a dummy invisible variable for OLDPWD, and mark it as > > > exported. */ > > >temp_var = find_variable ("OLDPWD"); > > > - if (temp_var == 0 || value_cell (temp_var) == 0 || file_isdir > > > (value_cell (temp_var)) == 0) > > > + if (temp_var == 0 || value_cell (temp_var) == 0) > > > { > > >temp_var = bind_variable ("OLDPWD", (char *)NULL, 0); > > > > This patch would revert the change introduced in: > > > > http://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=e6f5e0c858b7c0839d346d7d55e56894648c5a33 > > This patch doesn't revert the above change. It only removes a test if > $OLDPWD is a directory. With this patch, if $OLDPWD points to a directory, > there will be no change, and if $OLDPWD points to non-directory, it will > not be cleared. > > > Which was prompted by the following bug report from John Wiersba: > > https://lists.gnu.org/archive/html/bug-bash/2015-11/msg00115.html > > > > Correct me if I'm wrong, but a hanged sshfs mount will cause many more > > issues, not only with OLDPWD. > > Hung mount shouldn't cause problems unless someone is accessing it. > > What happened to me - I use the autofs filesystem to automatically mount > filesystems on various machines. I was on some autofs-mounted directory, I > moved to the home directory (which is not on autofs) and I typed startx. > Some times after that I shut down the remote machine that provided the > autofs mount. > > The whole X session started to severely mibehave, starting various > programs caused hangs, I couldn't even start an xterm with the shell, I > couldn't even start the chome browser - the reason for the hangs was, that > the OLDPWD variable pointing to the autofs directory ended up being > propagated to the Xserver, to the desktop environment and to any program > that was running within the X session. I caused serious trouble and I > think it should be fixed. > > If I started Xwindow on the non-functioning autofs directory, it would be > expected that I get hangs. However, I started Xwindow in the home > directory that has nothing to do with autofs - and I got hangs. > > Mikulas Another problem is that various daemons change the working directory to "/", so that they don't keep the directory they were started from open - however they don't clear the $OLDPWD environment variable. So the $OLDPWD variable in a daemon could contain arbitrary garbage. If the $OLDPWD variable points to some network directory that is currently inaccessible, the daemon won't be able to start any bash scripts. Mikulas
Re: [PATCH] Fix hang if $OLDPWD points to inaccessible directory
On Fri, Sep 29, 2017 at 11:12:59AM +0200, Mikulas Patocka wrote: > This patch doesn't revert the above change. It only removes a test if > $OLDPWD is a directory. With this patch, if $OLDPWD points to a directory, > there will be no change, and if $OLDPWD points to non-directory, it will > not be cleared. You're right. It doesn't revert it, but it does make it less useful. > Hung mount shouldn't cause problems unless someone is accessing it. My reasoning is that if stat()'ing a directory causes everything to halt, then perhaps fix the source of that problem? There's no reason why bash should make this a special case.
Re: [PATCH] Fix hang if $OLDPWD points to inaccessible directory
On Fri, Sep 29, 2017 at 12:51:37AM -0700, L A Walsh wrote: [...] > Why does bash clear OLDPWD when a child script is started? > > OLDPWD is exported and passed to any children, but bash apparently clears > OLDPWD whenever a child script is started... > > GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu) > > Can bash be fixed to preserve the value of any OLDPWD in its initial > environment, like it does with PWD? Eh, 4.1? That's ~8 years old. Check the commit I linked, there's the fix you're asking for. > --- > > I don't see a reason... > I see a "want", but no real reason > > I'd agree it's a rare event to hit though, but when you do... > > Requires console access, but changing /etc/profile to > insert a bad OLDPWD to a known down network location might not be > considered a trivial occurrence to someone stressed out and trying to log > in and find out why everyone logging in is hanging... Why would logins hang? We're talking about OLDPWD here. OLDPWD is not set if you're not logged in. The reported scenario is: - You are in a network filesystem (let's call it /net/myuser) - chdir() somewhere else, e.g. /home/myuser (OLDPWD=/net/myuser, PWD=/home/myuser) - Then you unplug your computer, or the computer that provides the network share. - Then you start a new bash shell, which will hang because it'll try to stat($OLDPWD). To which the solution is: unmount the network share properly.
Re: [PATCH] Fix hang if $OLDPWD points to inaccessible directory
Eduardo � wrote: On Fri, Sep 29, 2017 at 12:51:37AM -0700, L A Walsh wrote: Why does bash clear OLDPWD when a child script is started? OLDPWD is exported and passed to any children, but bash apparently clears OLDPWD whenever a child script is started... GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu) Can bash be fixed to preserve the value of any OLDPWD in its initial environment, like it does with PWD? Eh, 4.1? That's ~8 years old. Check the commit I linked, there's the fix you're asking for. Check the bug report you linked in your initial response. I read the report as listed as the 'reason' for the change. The above was a quote from the bug report. Are you saying you saying the reason given was invalid? Requires console access, but changing /etc/profile to insert a bad OLDPWD to a known down network location might not be considered a trivial occurrence to someone stressed out and trying to log in and find out why everyone logging in is hanging... Why would logins hang? Simple -- OLDPWD is set in /etc/profile to a bad value. That causes problems for everyone logging in, including root. Granted it is a rare event, and granted it needs root-console access, but the paragraph described an annoying situation where someone set the value of OLDPWD in /etc/profile to a dead-network connection. Even as someone w/root access tries logging in to fix the problem, they are hit by the same problem -- which I was guessing might cause stress -- especially to the one trying to fix it. To which the solution is: unmount the network share properly. Obviously that's the end goal, I was pointing out how annoying it would be if someone modified /etc/profile to set OLDPWD to a hung-network connection. I was thinking about the remote possibility of that happening and the consequent "annoyed sysadmin" vs. the original bug report you cited being given as a reason for not clearing it upon startup. I'm not heavily for or against it, but would lean toward initializing it to a known value, at least, when starting a login shell.
Re: [PATCH] Fix hang if $OLDPWD points to inaccessible directory
On 9/29/17 5:12 AM, Mikulas Patocka wrote: > > > On Thu, 28 Sep 2017, Eduardo A. Bustamante López wrote: > >> On Thu, Sep 28, 2017 at 11:44:02AM +0200, Mikulas Patocka wrote: >> [...] >>> +++ bash/variables.c >>> @@ -899,7 +899,7 @@ set_pwd () >>> don't find OLDPWD in the environment, or it doesn't name a directory, >>> make a dummy invisible variable for OLDPWD, and mark it as exported. >>> */ >>>temp_var = find_variable ("OLDPWD"); >>> - if (temp_var == 0 || value_cell (temp_var) == 0 || file_isdir >>> (value_cell (temp_var)) == 0) >>> + if (temp_var == 0 || value_cell (temp_var) == 0) >>> { >>>temp_var = bind_variable ("OLDPWD", (char *)NULL, 0); >> >> This patch would revert the change introduced in: >> >> http://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=e6f5e0c858b7c0839d346d7d55e56894648c5a33 > > This patch doesn't revert the above change. It only removes a test if > $OLDPWD is a directory. With this patch, if $OLDPWD points to a directory, > there will be no change, and if $OLDPWD points to non-directory, it will > not be cleared. OLDPWD must be a directory, and while it's technically the user's responsibility to ensure that it is, the shell should only inherit it if it has a valid value. (As I said back in 2015, in the same way it inherits PWD only if it names the current directory.) > >> Which was prompted by the following bug report from John Wiersba: >> https://lists.gnu.org/archive/html/bug-bash/2015-11/msg00115.html >> >> Correct me if I'm wrong, but a hanged sshfs mount will cause many more >> issues, not only with OLDPWD. > > Hung mount shouldn't cause problems unless someone is accessing it. That's like saying a problem will only be a problem if someone makes it a problem. It really seems like you want bash to save you from a problem you introduced by yanking a remote mount out from underneath your system. It seems better to, say, specify that the automount operation is interruptible than to change the shell for what is a rare occurrence. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/