| Summary: | A small bug in renice | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Alexander S. Usov <lex> |
| Component: | bin | Assignee: | Maxim Konovalov <maxim> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | Unspecified | ||
| Hardware: | Any | ||
| OS: | Any | ||
|
Description
Alexander S. Usov
2002-03-15 19:20:00 UTC
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
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 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
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 Fixed in -current in rev. 1.10 usr.bin/renice/renice.c. Responsible Changed From-To: freebsd-bugs->maxim I will MFC the fix. State Changed From-To: patched->closed Change has been MFC'd. |