[PATCH] silent job monitor when 'set +m'

2009-11-07 Thread Jeff Chua


Chet,

The man page mentioned that 'set -m' should print 'a line containing their 
status upon their completion' ... which should imply 'set +m' should NOT 
print the status.


Attached is a patch to 'silent' bash so that it won't print the status 
when 'Monitor mode' is off (set +m).


If this is not the right place to do this, please suggest an alternative 
to silent bash when 'kill %!' is executed.



Thanks,
Jeff


--- bash/jobs.c.org 2009-11-06 20:26:13.0 +0800
+++ bash/jobs.c 2009-11-06 23:55:17.0 +0800
@@ -3489,8 +3489,12 @@
  signal_is_trapped (termsig) == 0)
{
  /* Don't print `0' for a line number. */
- fprintf (stderr, _(%s: line %d: ), get_name_for_error (), 
(line_number == 0) ? 1 : line_number);
- pretty_print_job (job, JLIST_NONINTERACTIVE, stderr);
+ if(job_control) {
+ fprintf (stderr, _(%s: line %d: ),
+   get_name_for_error (),
+   (line_number == 0) ? 1 : line_number);
+ pretty_print_job (job, JLIST_NONINTERACTIVE, stderr);
+ }
}
  else if (IS_FOREGROUND (job))
{




Re: [PATCH] silent job monitor when 'set +m'

2009-11-07 Thread Jeff Chua
On Sat, Nov 7, 2009 at 8:12 PM, Jan Schampera jan.schamp...@web.de wrote:

 A workaround is to diswon the monster. But yes, I also stumbled over
 this once. See
 http://bash-hackers.org/wiki/doku.php/snipplets/kill_bg_job_without_message


disown... that's new to me. Nice. At least it's an alternative to set
+m.

Thanks,
Jeff


Re: [PATCH] silent job monitor when 'set +m'

2009-11-07 Thread Chet Ramey
Jeff Chua wrote:
 
 Chet,
 
 The man page mentioned that 'set -m' should print 'a line containing
 their status upon their completion' ... which should imply 'set +m'
 should NOT print the status.

I'm confused about the circumstances you used to trigger this behavior,
since the code fragment you modified is never executed by an interactive
shell, and non-interactive shells don't have job control enabled by
default.  Are you saying you ran a script in which you enabled job
control, ran a job, turned job control off, then killed the job?

Bash and historical versions of sh report the status of jobs in a script
that exit as the result of being killed by a signal.  I'm not going to
change that.

Chet
-- 
``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: [PATCH] silent job monitor when 'set +m'

2009-11-07 Thread Jeff Chua
On Sun, Nov 8, 2009 at 5:25 AM, Chet Ramey chet.ra...@case.edu wrote:


 Are you saying you ran a script in which you enabled job
 control, ran a job, turned job control off, then killed the job?


No, I didn't turn off job control. I use set +m to turn of monitoring only
because I don't want to see any message about the job being terminated.


 Bash and historical versions of sh report the status of jobs in a script
 that exit as the result of being killed by a signal.  I'm not going to
 change that.


Isn't that the purpose of set +m ... to turn off monitoring?

Thanks,
Jeff


Re: [PATCH] silent job monitor when 'set +m'

2009-11-07 Thread Chet Ramey
Jeff Chua wrote:
 
 
 On Sun, Nov 8, 2009 at 5:25 AM, Chet Ramey chet.ra...@case.edu
 mailto:chet.ra...@case.edu wrote:
 
 
 Are you saying you ran a script in which you enabled job
 control, ran a job, turned job control off, then killed the job?
 
 
 No, I didn't turn off job control. I use set +m to turn of monitoring
 only because I don't want to see any message about the job being terminated.

I think you're confused about the distinction.  set -m and +m turn job
control on and off.  The `monitor' name is historical (ask Dave Korn
why he chose it).

 
 Bash and historical versions of sh report the status of jobs in a script
 that exit as the result of being killed by a signal.  I'm not going to
 change that.
 
 
 Isn't that the purpose of set +m ... to turn off monitoring?

Let's take a step back.  I don't think your patch does what you think it
does, since the code it changes doesn't get executed when the shell is
interactive.

What version of bash are you using?  Assuming you mean an interactive
shell, bash-4.0 behaves like I think you want:

$ ./bash
$ echo $BASH_VERSION
4.0.35(9)-release
$ echo $-
himBH
$ sleep 40 
[1] 19038
$ set +m
$ kill %1
$ fg %1
bash: fg: no job control
$ set -m
$ sleep 40 
[1] 19041
$ kill %1
$
[1]+  Terminated  sleep 40
$

Chet
-- 
``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/