From anarcat@anarcat.dyndns.org  Sun Sep 23 11:38:59 2001
Return-Path: <anarcat@anarcat.dyndns.org>
Received: from tomts19-srv.bellnexxia.net (tomts19.bellnexxia.net [209.226.175.73])
	by hub.freebsd.org (Postfix) with ESMTP id 14A3237B409
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 23 Sep 2001 11:38:59 -0700 (PDT)
Received: from khan.anarcat.dyndns.org ([65.92.169.79])
          by tomts19-srv.bellnexxia.net
          (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP
          id <20010923183843.RLMJ3504.tomts19-srv.bellnexxia.net@khan.anarcat.dyndns.org>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Sun, 23 Sep 2001 14:38:43 -0400
Received: from shall.anarcat.dyndns.org (shall.anarcat.dyndns.org [192.168.0.1])
	by khan.anarcat.dyndns.org (Postfix) with ESMTP id B0B971A7C
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 23 Sep 2001 14:38:38 -0400 (EDT)
Received: by shall.anarcat.dyndns.org (Postfix, from userid 1000)
	id B13B320B4A; Sun, 23 Sep 2001 14:38:32 -0400 (EDT)
Message-Id: <20010923183832.B13B320B4A@shall.anarcat.dyndns.org>
Date: Sun, 23 Sep 2001 14:38:32 -0400 (EDT)
From: The Anarcat <anarcat@anarcat.dyndns.org>
Reply-To: The Anarcat <anarcat@anarcat.dyndns.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: PATCH: fetch(1) prints d/l status even if in background
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         30764
>Category:       bin
>Synopsis:       PATCH: fetch(1) prints d/l status even if in background
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 23 11:40:01 PDT 2001
>Closed-Date:    Thu Oct 11 03:52:08 PDT 2001
>Last-Modified:  Thu Oct 11 03:52:21 PDT 2001
>Originator:     The Anarcat
>Release:        FreeBSD 4.4-STABLE i386
>Organization:
Nada, Inc.
>Environment:
System: FreeBSD shall.anarcat.dyndns.org 4.4-STABLE FreeBSD 4.4-STABLE #7: Sat Sep 15 00:41:38 EDT 2001 anarcat@shall.anarcat.dyndns.org:/usr/obj/usr/src/sys/SHALL i386

>Description:

The fetch(1) utility (used mainly to fetch ports distfiles) features a
display of the current progress of the download. 

When you put fetch(1) in background, it keeps on clobbering the terminal
with that status, which is really annoying. ftp(1) on the other hand,
gracefully checks if it's the foreground process before doing that.

Some might consider this a feature, I call it a bug. :)

>How-To-Repeat:

$ fetch ftp://ftp11.freebsd.org/pub/FreeBSD/ports/packages/Latest/samba.tgz &

>Fix:

I stole the code from ftp(1), so there should be any problems...

--- /usr/src/usr.bin/fetch/fetch.c	Tue Aug 21 13:15:38 2001
+++ fetch.c	Sun Sep 23 14:36:58 2001
@@ -42,6 +42,8 @@
 #include <sysexits.h>
 #include <unistd.h>
 
+#include <sys/ioctl.h>
+
 #include <fetch.h>
 
 #define MINBUFSIZE	4096
@@ -117,6 +119,19 @@
 {
     struct timeval now;
     
+    static pid_t pgrp = -1;
+    int ctty_pgrp;
+
+    if (pgrp == -1)
+            pgrp = getpgrp();
+
+    /*
+     * do not print display (ie return) if we're not foreground process
+     */
+    if (ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) == -1 ||
+        ctty_pgrp != (int)pgrp)
+        return;
+
     if (!v_tty || !v_level)
 	return;
     
This works well here.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: des 
Responsible-Changed-When: Sun Sep 23 14:34:40 PDT 2001 
Responsible-Changed-Why:  
fetch(1) is mine. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30764 
State-Changed-From-To: open->feedback 
State-Changed-By: des 
State-Changed-When: Sun Sep 23 15:03:45 PDT 2001 
State-Changed-Why:  
Functionally similar patch applied to -CURRENT, awaiting MFC. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30764 

From: The Anarcat <anarcat@anarcat.dyndns.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/30764: PATCH: fetch(1) prints d/l status even if in background
Date: Wed, 10 Oct 2001 15:39:49 -0400

 --v9Ux+11Zm5mwPlX6
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 this pr can be closed, MFC'd on:
 
 Revision 1.10.2.16, Sat Oct 6 00:53:25 2001 UTC
 
 A.
 
 --v9Ux+11Zm5mwPlX6
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iEYEARECAAYFAjvEpAIACgkQttcWHAnWiGeP9wCfRLMGW8oHE+DfBJUzevkPc0yM
 BIAAn3k6F2yKTU1SBk1kDA9LEScLzOIp
 =Z+90
 -----END PGP SIGNATURE-----
 
 --v9Ux+11Zm5mwPlX6--
State-Changed-From-To: feedback->closed 
State-Changed-By: des 
State-Changed-When: Thu Oct 11 03:52:08 PDT 2001 
State-Changed-Why:  
Fixed. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30764 
>Unformatted:
