Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Mar 2002 12:40:02 -0800 (PST)
From:      Maxim Konovalov <maxim@macomnet.ru>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/35929: A small bug in renice
Message-ID:  <200203152040.g2FKe2c60934@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/35929; it has been noted by GNATS.

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
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203152040.g2FKe2c60934>