Re: Finding the last foreground command in the current session

2015-06-10 Thread Stephane Chazelas
2015-06-09 19:44:44 +, Debarshi Ray:
> Hey Stephane,
> 
> On Fri, May 22, 2015 at 02:38:31PM +0100, Stephane Chazelas wrote:
> > Can you not just do a tcgetpgrp() periodically
> 
> If by "periodically" you mean "polling", then no, I don't want to do
> that.  I know a few terminal emulators do that, but it is bad for
> power consumption and battery life.
> 
> (We already use tcgetpgrp for checking if there is a foreground
> process when the user clicks the 'x' buton.)

just a few thoughts

If it's for human interaction then 1/10s resolution is more than
enough and tcgetpgrp is just one system call. You could always
do it upon a specific escape sequence sent by PS1 (if you were
going to rely on the bash-specific PROMPT_COMMAND anyway), or
stop doing it 1/2 second after the last user input or pty
activity if you want to avoid it when the terminal is idle.

-- 
Stephane




Please improve documentation of "history -a"

2015-06-10 Thread Reuben Thomas
At least in bash 4.3, the documentation for history -a says:

  Append the new history lines (history lines entered since the
  beginning of the current Bash session) to the history file.

This is unfortunately misleading, since it suggests that the technique of
adding "history -a" to one's PROMPT_COMMAND, as suggested here:

http://heyrod.com/snippet/s/always-append-bash-history.html

​would append to one's history file many copies of the lines entered since
the beginning of the current session. Fortunately it doesn't do that, but
rather appends lines that have not yet been appended. I suggest making this
clear, and also mentioning the PROMPT_COMMAND trick, as I look forward to
losing far fewer useful commands from my global history by having them
instantly saved, and not lost when a long-running terminal hangs and must
be killed, or the machine running out of power etc.

-
​​
-
http://rrt.sc3d.org


[PATCH] document the -p invocation flag

2015-06-10 Thread Adam Endrodi

--- bash-4.2/doc/bash.1.orig2015-06-10 15:09:04.0 +0200
+++ bash-4.2/doc/bash.1 2015-06-10 15:19:55.0 +0200
@@ -117,6 +117,18 @@
 This option allows the positional parameters to be set
 when invoking an interactive shell.
 .TP
+.B \-p
+If the
+.B \-p
+is
+.B not
+present and the real and effective user or group IDs mismatch on startup,
+the effective user and group IDs are set to the real ones.  This behavior
+can be disabled with this flag, but see 
+.SM
+.B "INVOCATION"
+for notes about setuid invocation.
+.TP
 .B \-D
 A list of all double-quoted strings preceded by \fB$\fP
 is printed on the standard output.

-- 
QED



Re: Bug in bash 4.3.30 with --disable-job-control

2015-06-10 Thread Chet Ramey
On 6/2/15 1:07 PM, Roy Keene wrote:
> All,
> 
> There is a bug of some sort in bash 4.3.30 (and likely others) when
> compiled with --disable-job-control on Linux/x86_64.

I can't reproduce this on RHEL 6 or Fedora 22 with bash-4.3.39.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Bug in bash 4.3.30 with --disable-job-control

2015-06-10 Thread Eduardo A . Bustamante López
On Wed, Jun 10, 2015 at 11:00:51AM -0400, Chet Ramey wrote:
> On 6/2/15 1:07 PM, Roy Keene wrote:
> > All,
> > 
> > There is a bug of some sort in bash 4.3.30 (and likely others) when
> > compiled with --disable-job-control on Linux/x86_64.
> 
> I can't reproduce this on RHEL 6 or Fedora 22 with bash-4.3.39.

I can reliably reproduce this in 4.3.30 and in branch `master' of the latest
git:


# Bash from `master'

  dualbus@hp ...src/gnu/bash % time ./bash -ic 'until : | { ! :; }; do :; done; 
echo x'
  x
  ./bash -ic 'until : | { ! :; }; do :; done; echo x'  2.08s user 3.72s system 
48% cpu 12.011 total
  dualbus@hp ...src/gnu/bash % ./bash --version
  GNU bash, version 4.3.39(1)-release (x86_64-unknown-linux-gnu)
  Copyright (C) 2013 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later 
  
  This is free software; you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.


# Bash from FTP

  dualbus@hp ~/Downloads/bash-4.3.30
   % time ./bash -c 'until : | { ! :; }; do :; done; echo x'
  ^C./bash -c 'until : | { ! :; }; do :; done; echo x'  3.10s user 18.81s 
system 41% cpu 52.893 total
  dualbus@hp ~/Downloads/bash-4.3.30
   % time ./bash -ic 'until : | { ! :; }; do :; done; echo x'
  x
  ./bash -ic 'until : | { ! :; }; do :; done; echo x'  1.97s user 3.53s system 
52% cpu 10.427 total
  dualbus@hp ~/Downloads/bash-4.3.30
   % ./bash --version
  GNU bash, version 4.3.30(1)-release (x86_64-unknown-linux-gnu)
  Copyright (C) 2013 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later 
  
  This is free software; you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.


I compiled both with:

  CFLAGS='-O0 -g' ./configure --disable-job-control

Notice that it doesn't happen if you don't use the interactive mode.

All this is on GNU/Linux (debian sid):

  dualbus@hp ~ % uname -a
  Linux hp 3.14-2-amd64 #1 SMP Debian 3.14.15-2 (2014-08-09) x86_64 GNU/Linux


I can reproduce it on OpenBSD:

  $ ./bash --version
  GNU bash, version 4.3.30(1)-release (x86_64-unknown-openbsd5.6)
  Copyright (C) 2013 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later 
  
  This is free software; you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.
  $ time ./bash -ic 'until : | { ! :; }; do :; done; echo x'
  x
  0m0.39s real 0m0.06s user 0m0.28s system
  $ time ./bash -c 'until : | { ! :; }; do :; done; echo x'  
  ^C^C^C^C0m11.27s real 0m2.25s user 0m6.87s system
  $ uname -a
  OpenBSD openbsd.my.domain 5.6 GENERIC#310 amd64


And NetBSD:

  [dual...@faeroes.sdf.org]$ ./bash --version
  GNU bash, version 4.3.30(1)-release (x86_64-unknown-netbsd6.1.)
  Copyright (C) 2013 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later 
  
  This is free software; you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.
  [dual...@faeroes.sdf.org]$ time ./bash -ic 'until : | { ! :; }; do :; done; 
echo x'
  x
  
  real0m27,27s
  user0m9,72s
  sys 0m12,24s
  [dual...@faeroes.sdf.org]$ uname -a
  NetBSD faeroes 6.1_STABLE NetBSD 6.1_STABLE (SDF6.amd64) #0: Sun Dec 21 
18:11:22 UTC 2014  
root@bjork:/spare/netbsd/usr/src/sys/arch/amd64/compile/SDF6.amd64 amd64


I tried digging into the issue with strace/ltrace, but I couldn't find any 
pattern.

-- 
Eduardo Bustamante
https://dualbus.me/



Re: Bug in bash 4.3.30 with --disable-job-control

2015-06-10 Thread Chet Ramey
On 6/10/15 12:55 PM, Eduardo A. Bustamante López wrote:

> Notice that it doesn't happen if you don't use the interactive mode.

Thanks.  This might be the key.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/