NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/39710: db(1) does not return appropiate return value when removing unexistent keys
>Number: 39710
>Category: bin
>Synopsis: db(1) does not return appropiate return value when removing
>unexistent keys
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Oct 07 00:45:00 +0000 2008
>Originator: Juan RP
>Release: Latest and greatest
>Organization:
>Environment:
NetBSD sasha 4.99.72 NetBSD 4.99.72 (MASTER) #99: Fri Oct 3 18:18:57 CEST 2008
juan@sasha:/home/juan/build/amd64/obj/sys/arch/amd64/compile/MASTER amd64
>Description:
$ db -w btree blah.db foo blobbing
Added key `foo'
$ echo $?
0
$ db -d btree blah.db foo
Deleted key `foo'
$ echo $?
0
$ db -d btree blah.db foo
db: Unknown key `foo'
$ echo $?
0
$
And the code confirms that r hasn't been changed in this case:
int
db_del(char *keystr)
{
DBT key;
int r = 0;
db_makekey(&key, keystr, 1, (flags & F_DECODE_KEY ? 1 : 0));
switch (db->del(db, &key, 0)) {
case -1:
if (! (flags & F_QUIET))
warn("Error deleting key `%s'", keystr);
r = 1;
break;
case 0:
if (! (flags & F_QUIET))
printf("Deleted key `%s'\n", keystr);
break;
case 1:
warnx("Unknown key `%s'", keystr);
break;
}
if (flags & F_DECODE_KEY)
free(key.data);
return (r);
}
The patch provided also hides those printfs/warns if -q is set...
or isn't the intended behaviour?
>How-To-Repeat:
>Fix:
Index: db.c
===================================================================
RCS file: /cvsroot/src/usr.bin/db/db.c,v
retrieving revision 1.20
diff -b -u -p -r1.20 db.c
--- db.c 5 Sep 2008 07:55:33 -0000 1.20
+++ db.c 7 Oct 2008 00:36:21 -0000
@@ -446,6 +446,7 @@ db_del(char *keystr)
db_makekey(&key, keystr, 1, (flags & F_DECODE_KEY ? 1 : 0));
switch (db->del(db, &key, 0)) {
case -1:
+ if (! (flags & F_QUIET))
warn("Error deleting key `%s'", keystr);
r = 1;
break;
@@ -454,7 +455,9 @@ db_del(char *keystr)
printf("Deleted key `%s'\n", keystr);
break;
case 1:
+ if (! (flags & F_QUIET))
warnx("Unknown key `%s'", keystr);
+ r = 1;
break;
}
if (flags & F_DECODE_KEY)
Home |
Main Index |
Thread Index |
Old Index