From nobody@FreeBSD.org  Fri Mar 15 11:18:48 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 0202F37B402
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Mar 2002 11:18:48 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g2FJIl159626;
	Fri, 15 Mar 2002 11:18:47 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200203151918.g2FJIl159626@freefall.freebsd.org>
Date: Fri, 15 Mar 2002 11:18:47 -0800 (PST)
From: "Alexander S. Usov" <lex@itv.kiev.ua>
To: freebsd-gnats-submit@FreeBSD.org
Subject: A small bug in renice
X-Send-Pr-Version: www-1.0

>Number:         35929
>Category:       bin
>Synopsis:       A small bug in renice
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    maxim
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 15 11:20:00 PST 2002
>Closed-Date:    Mon Jun 17 17:14:07 PDT 2002
>Last-Modified:  Mon Jun 17 17:14:07 PDT 2002
>Originator:     Alexander S. Usov
>Release:        4.5-Stable
>Organization:
ITV
>Environment:
FreeBSD darkini.itv 4.5-STABLE FreeBSD 4.5-STABLE #0: Sun Feb  3 17:52:08 EET 2002
>Description:
      renice 10 -j pid works a little strange:
===%renice 10 -j $$
0: old priority 0, new priority 10     
62742: old priority 0, new priority 10 
>How-To-Repeat:
      try it
>Fix:
      
>Release-Note:
>Audit-Trail:

From: Maxim Konovalov <maxim@macomnet.ru>
To: "Alexander S. Usov" <lex@itv.kiev.ua>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/35929: A small bug in renice
Date: Fri, 15 Mar 2002 23:36:35 +0300 (MSK)

 Could you please try a patch below (mostly from NetBSD):
 
 Index: renice.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/renice/renice.c,v
 retrieving revision 1.7
 diff -u -r1.7 renice.c
 --- renice.c	3 Dec 2001 21:18:12 -0000	1.7
 +++ renice.c	15 Mar 2002 20:31:46 -0000
 @@ -56,8 +56,9 @@
  #include <string.h>
  #include <pwd.h>
 
 -int donice __P((int, int, int));
 -static void usage __P((void));
 +static int	getnum(const char *, const char *, int *);
 +static int	donice(int, int, int);
 +static void	usage(void);
 
  /*
   * Change the priority (nice) of processes
 @@ -75,7 +76,8 @@
  	argc--, argv++;
  	if (argc < 2)
  		usage();
 -	prio = atoi(*argv);
 +	if (getnum("priority", *argv, &prio))
 +		return 1;
  	argc--, argv++;
  	if (prio > PRIO_MAX)
  		prio = PRIO_MAX;
 @@ -95,7 +97,7 @@
  			continue;
  		}
  		if (which == PRIO_USER) {
 -			register struct passwd *pwd = getpwnam(*argv);
 +			struct passwd *pwd = getpwnam(*argv);
 
  			if (pwd == NULL) {
  				warnx("%s: unknown user", *argv);
 @@ -103,7 +105,8 @@
  			}
  			who = pwd->pw_uid;
  		} else {
 -			who = atoi(*argv);
 +			if (getnum("pid", *argv, &who))
 +				continue;
  			if (who < 0) {
  				warnx("%s: bad value", *argv);
  				continue;
 @@ -114,21 +117,35 @@
  	exit(errs != 0);
  }
 
 -static void
 -usage()
 +static int
 +getnum(const char *com, const char *str, int *val)
  {
 -	fprintf(stderr,
 -"usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\n");
 -	exit(1);
 +	long v;
 +	char *ep;
 +
 +	v = strtol(str, &ep, NULL);
 +
 +	if (*ep) {
 +		warnx("Bad %s argument: %s", com, str);
 +		return 1;
 +	}
 +	if ((v == LONG_MIN || v == LONG_MAX) && errno == ERANGE) {
 +		warn("Invalid %s argument: %s", com, str);
 +		return 1;
 +	}
 +
 +	*val = (int)v;
 +	return 0;
  }
 
 -int
 +static int
  donice(which, who, prio)
  	int which, who, prio;
  {
  	int oldprio;
 
 -	errno = 0, oldprio = getpriority(which, who);
 +	errno = 0;
 +	oldprio = getpriority(which, who);
  	if (oldprio == -1 && errno) {
  		warn("%d: getpriority", who);
  		return (1);
 @@ -137,6 +154,15 @@
  		warn("%d: setpriority", who);
  		return (1);
  	}
 -	printf("%d: old priority %d, new priority %d\n", who, oldprio, prio);
 +	(void)printf("%d: old priority %d, new priority %d\n", who, oldprio,
 +	     prio);
  	return (0);
 +}
 +
 +static void
 +usage()
 +{
 +	(void)fprintf(stderr,
 +"usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\n");
 +	exit(1);
  }
 
 -- 
 Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
 phone: +7 (095) 796-9079, mailto:maxim@macomnet.ru
 

From: "Crist J. Clark" <cjc@FreeBSD.ORG>
To: "Alexander S. Usov" <lex@itv.kiev.ua>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/35929: A small bug in renice
Date: Sat, 16 Mar 2002 11:40:39 -0800

 On Fri, Mar 15, 2002 at 11:18:47AM -0800, Alexander S. Usov wrote:
 > 
 > >Number:         35929
 > >Category:       bin
 > >Synopsis:       A small bug in renice
 > >Confidential:   no
 > >Severity:       non-critical
 > >Priority:       medium
 > >Responsible:    freebsd-bugs
 > >State:          open
 > >Quarter:        
 > >Keywords:       
 > >Date-Required:
 > >Class:          sw-bug
 > >Submitter-Id:   current-users
 > >Arrival-Date:   Fri Mar 15 11:20:00 PST 2002
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     Alexander S. Usov
 > >Release:        4.5-Stable
 > >Organization:
 > ITV
 > >Environment:
 > FreeBSD darkini.itv 4.5-STABLE FreeBSD 4.5-STABLE #0: Sun Feb  3 17:52:08 EET 2002
 > >Description:
 >       renice 10 -j pid works a little strange:
 > ===%renice 10 -j $$
 > 0: old priority 0, new priority 10     
 > 62742: old priority 0, new priority 10 
 
 Nothing too surprising here. '-j' is not a valid flag to renice(8). It
 is being interpreted as an integer. atoi(3) return a value of 0 for
 "-j".
 -- 
 Crist J. Clark                     |     cjclark@alum.mit.edu
                                    |     cjclark@jhu.edu
 http://people.freebsd.org/~cjc/    |     cjc@freebsd.org

From: "Alexander S. Usov" <lex@itv.kiev.ua>
To: "Crist J. Clark" <cjc@FreeBSD.ORG>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re[2]: bin/35929: A small bug in renice
Date: Sun, 17 Mar 2002 16:31:24 +0200

 Hello Crist,
 
 Saturday, March 16, 2002, 9:40:39 PM, you wrote:
 
 >> >Description:
 >>       renice 10 -j pid works a little strange:
 >> ===%renice 10 -j $$
 >> 0: old priority 0, new priority 10     
 >> 62742: old priority 0, new priority 10 
 
 CJC> Nothing too surprising here. '-j' is not a valid flag to renice(8). It
 CJC> is being interpreted as an integer. atoi(3) return a value of 0 for
 CJC> "-j".
 
 IMHO "renice: illegal option -j" looks better :)
 
 -- 
 Best regards,
  Alexander
 

From: "Alexander S. Usov" <lex@itv.kiev.ua>
To: Maxim Konovalov <maxim@macomnet.ru>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re[2]: bin/35929: A small bug in renice
Date: Sun, 17 Mar 2002 18:03:41 +0200

 Hello Maxim,
 
 Friday, March 15, 2002, 10:36:35 PM, you wrote:
 
 
 MK> Could you please try a patch below (mostly from NetBSD):
 
 It doesn't match my version of renice.c (FreeBSD 4.5-STABLE)
 
 -- 
 Best regards,
  Alexander
 
State-Changed-From-To: open->patched 
State-Changed-By: maxim 
State-Changed-When: Wed Apr 10 04:15:45 PDT 2002 
State-Changed-Why:  
Fixed in -current in rev. 1.10 usr.bin/renice/renice.c.  


Responsible-Changed-From-To: freebsd-bugs->maxim 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Wed Apr 10 04:15:45 PDT 2002 
Responsible-Changed-Why:  
I will MFC the fix. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=35929 
State-Changed-From-To: patched->closed 
State-Changed-By: tjr 
State-Changed-When: Mon Jun 17 17:12:45 PDT 2002 
State-Changed-Why:  
Change has been MFC'd. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=35929 
>Unformatted:
