Subject: pkg/24217: Wrong use of usleep() in wget 1.9.1 pkg
To: None <gnats-bugs@gnats.netbsd.org>
From: None <jlouis@mongers.org>
List: netbsd-bugs
Date: 01/24/2004 20:25:59
>Number:         24217
>Category:       pkg
>Synopsis:       usleep() is used the wrong way in Wget 1.9.1 pkg
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 24 19:27:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        NetBSD 1.6ZH
>Organization:
	n/a
>Environment:
>Description:
	Wget 1.9.1 uses a number of calls to usleep() inside 
	src/retr.c. The sleeps are being used to implement the 
	--wait/-w option for waiting between retrievals of pages for 
	playing nice with the internet. 

 	Unfortunately, the good people has not read usleep(3), which
	says you must not call usleep with a value greater than 10**6.
	Instead their lines goes like:
		
		usleep(1000000L * opt.wait);

	which we but of course honor with a return value of -1 and an
	errno set at EINVAL. They do not check it though... Net result:
	no sleeping.

>How-To-Repeat:
	run wget --mirror --wait=30 http://some.site and see it does not
	wait.

>Fix:
	Apply the following patch to pkgsrc. I have not yet submitted
	the bug upstream to the GNU/FSF folks, since I want to be sure
	I am right here. If I am, I will gladly contact them and talk
	with them about the problem though. pkglint reported some bugs
	in SSL, but I think it is ok, since it seems to be in base.


diff -uNr wget.orig/Makefile wget/Makefile
--- wget.orig/Makefile	2004-01-24 20:07:00.000000000 +0100
+++ wget/Makefile	2004-01-24 20:11:51.000000000 +0100
@@ -1,6 +1,7 @@
 # $NetBSD: Makefile,v 1.69 2003/12/08 21:44:35 wiz Exp $
 
 DISTNAME=	wget-1.9.1
+PKGREVISION=	1
 CATEGORIES=	net
 MASTER_SITES=	${MASTER_SITE_GNU:=wget/}
 
diff -uNr wget.orig/distinfo wget/distinfo
--- wget.orig/distinfo	2004-01-24 20:07:00.000000000 +0100
+++ wget/distinfo	2004-01-24 20:12:52.000000000 +0100
@@ -2,5 +2,6 @@
 
 SHA1 (wget-1.9.1.tar.gz) = 0597a4f47b056e3e60cf7d08c9409d67358e7099
 Size (wget-1.9.1.tar.gz) = 1322378 bytes
+SHA1 (patch-af) = 1317d4f89e1e504e6a74a5abc6e1406c4e9a0d76
 SHA1 (patch-ag) = d13900b60f52cac6c71f701026e6de8b32f00354
 SHA1 (patch-ah) = 86a03b2d1c0c4849f7b6e69f973bcef427f78e0f
diff -uNr wget.orig/patches/patch-af wget/patches/patch-af
--- wget.orig/patches/patch-af	1970-01-01 01:00:00.000000000 +0100
+++ wget/patches/patch-af	2004-01-24 20:10:30.000000000 +0100
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- src/retr.c.orig	2003-10-11 15:57:11.000000000 +0200
++++ src/retr.c
+@@ -642,7 +642,7 @@ sleep_between_retrievals (int count)
+       if (count <= opt.waitretry)
+ 	sleep (count - 1);
+       else
+-	usleep (1000000L * opt.waitretry);
++	sleep (opt.waitretry);
+     }
+   else if (opt.wait)
+     {
+@@ -650,7 +650,7 @@ sleep_between_retrievals (int count)
+ 	/* If random-wait is not specified, or if we are sleeping
+ 	   between retries of the same download, sleep the fixed
+ 	   interval.  */
+-	usleep (1000000L * opt.wait);
++	sleep (opt.wait);
+       else
+ 	{
+ 	  /* Sleep a random amount of time averaging in opt.wait
+@@ -659,7 +659,7 @@ sleep_between_retrievals (int count)
+ 	  double waitsecs = 2 * opt.wait * random_float ();
+ 	  DEBUGP (("sleep_between_retrievals: avg=%f,sleep=%f\n",
+ 		   opt.wait, waitsecs));
+-	  usleep (1000000L * waitsecs);
++	  sleep (waitsecs);
+ 	}
+     }
+ }
>Release-Note:
>Audit-Trail:
>Unformatted:
 
 System: NetBSD sarah 1.6ZH NetBSD 1.6ZH (SARAH) #5: Fri Jan 23 22:56:58 CET 2004 root@sarah:/usr/src/sys/arch/i386/compile/SARAH i386
 Architecture: i386
 Machine: i386