Date: Mon, 15 Apr 2002 22:26:40 +1000 (EST) From: Joshua Goodall <joshua@roughtrade.net> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/37096: Fixes to fsdb command-line handling [patch] Message-ID: <20020415122640.7BE253E2A@green.shallow.net>
next in thread | raw e-mail | index | archive | help
>Number: 37096 >Category: bin >Synopsis: Fixes to fsdb command-line handling [patch] >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Apr 15 05:30:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Joshua Goodall >Release: FreeBSD 5.0-CURRENT i386 >Organization: >Environment: System: FreeBSD gold.shallow.net 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Mon Apr 15 17:55:08 EST 2002 joshua@green.shallow.net:/usr/obj/usr/current/sys/GENERIC i386 >Description: fsdb(8) tries to handle the case where the last argument to a command is slurped in whitespace-n-all. Unfortunately, it's applied across the board, with hilarious results : fsdb (inum: 2)> ls foo Segmentation fault (core dumped) # This patch fixes that by setting a new flag FL_ST for commands as appropriate. Plus, for some reason, fsdb sometimes reports argc's, sometimes argc-1 in usage lines. argc is an implementation detail which != count of arguments; this patch trivially fixes the cases seen. Tested with today's -current. >How-To-Repeat: >Fix: Index: sbin/fsdb/fsdb.c =================================================================== RCS file: /cvs/src/sbin/fsdb/fsdb.c,v retrieving revision 1.24 diff -u -r1.24 fsdb.c --- sbin/fsdb/fsdb.c 21 Mar 2002 13:10:52 -0000 1.24 +++ sbin/fsdb/fsdb.c 15 Apr 2002 12:06:43 -0000 @@ -150,8 +150,8 @@ { "?", "Print out help", 1, 1, FL_RO, helpfn }, { "inode", "Set active inode to INUM", 2, 2, FL_RO, focus }, { "clri", "Clear inode INUM", 2, 2, FL_WR, zapi }, - { "lookup", "Set active inode by looking up NAME", 2, 2, FL_RO, focusname }, - { "cd", "Set active inode by looking up NAME", 2, 2, FL_RO, focusname }, + { "lookup", "Set active inode by looking up NAME", 2, 2, FL_RO | FL_ST, focusname }, + { "cd", "Set active inode by looking up NAME", 2, 2, FL_RO | FL_ST, focusname }, { "back", "Go to previous active inode", 1, 1, FL_RO, back }, { "active", "Print active inode", 1, 1, FL_RO, active }, { "print", "Print active inode", 1, 1, FL_RO, active }, @@ -160,11 +160,11 @@ { "downlink", "Decrement link count", 1, 1, FL_WR, downlink }, { "linkcount", "Set link count to COUNT", 2, 2, FL_WR, linkcount }, { "ls", "List current inode as directory", 1, 1, FL_RO, ls }, - { "rm", "Remove NAME from current inode directory", 2, 2, FL_WR, rm }, - { "del", "Remove NAME from current inode directory", 2, 2, FL_WR, rm }, - { "ln", "Hardlink INO into current inode directory as NAME", 3, 3, FL_WR, ln }, + { "rm", "Remove NAME from current inode directory", 2, 2, FL_WR | FL_ST, rm }, + { "del", "Remove NAME from current inode directory", 2, 2, FL_WR | FL_ST, rm }, + { "ln", "Hardlink INO into current inode directory as NAME", 3, 3, FL_WR | FL_ST, ln }, { "chinum", "Change dir entry number INDEX to INUM", 3, 3, FL_WR, chinum }, - { "chname", "Change dir entry number INDEX to NAME", 3, 3, FL_WR, chname }, + { "chname", "Change dir entry number INDEX to NAME", 3, 3, FL_WR | FL_ST, chname }, { "chtype", "Change type of current inode to TYPE", 2, 2, FL_WR, newtype }, { "chmod", "Change mode of current inode to MODE", 2, 2, FL_WR, chmode }, { "chlen", "Change length of current inode to LENGTH", 2, 2, FL_WR, chlen }, @@ -187,11 +187,11 @@ struct cmdtable *cmdtp; printf("Commands are:\n%-10s %5s %5s %s\n", - "command", "min argc", "max argc", "what"); + "command", "min args", "max args", "what"); for (cmdtp = cmds; cmdtp->cmd; cmdtp++) printf("%-10s %5u %5u %s\n", - cmdtp->cmd, cmdtp->minargc, cmdtp->maxargc, cmdtp->helptxt); + cmdtp->cmd, cmdtp->minargc-1, cmdtp->maxargc-1, cmdtp->helptxt); return 0; } @@ -254,7 +254,8 @@ else if (cmd_argc >= cmdp->minargc && cmd_argc <= cmdp->maxargc) rval = (*cmdp->handler)(cmd_argc, cmd_argv); - else if (cmd_argc >= cmdp->minargc) { + else if (cmd_argc >= cmdp->minargc && + (cmdp->flags & FL_ST) == FL_ST) { strcpy(line, elline); cmd_argv = recrack(line, &cmd_argc, cmdp->maxargc); rval = (*cmdp->handler)(cmd_argc, cmd_argv); Index: sbin/fsdb/fsdb.h =================================================================== RCS file: /cvs/src/sbin/fsdb/fsdb.h,v retrieving revision 1.7 diff -u -r1.7 fsdb.h --- sbin/fsdb/fsdb.h 21 Mar 2002 13:10:52 -0000 1.7 +++ sbin/fsdb/fsdb.h 15 Apr 2002 10:54:25 -0000 @@ -48,6 +48,7 @@ unsigned int flags; #define FL_RO 0x0000 /* for symmetry */ #define FL_WR 0x0001 /* wants to write */ +#define FL_ST 0x0002 /* resplit final string if argc > maxargc */ int (*handler)(int argc, char *argv[]); }; extern struct dinode *curinode; Index: sbin/fsdb/fsdbutil.c =================================================================== RCS file: /cvs/src/sbin/fsdb/fsdbutil.c,v retrieving revision 1.16 diff -u -r1.16 fsdbutil.c --- sbin/fsdb/fsdbutil.c 21 Mar 2002 13:10:52 -0000 1.16 +++ sbin/fsdb/fsdbutil.c 15 Apr 2002 11:48:34 -0000 @@ -96,7 +96,7 @@ { if (cmdp->minargc == cmdp->maxargc) warnx("command `%s' takes %u arguments, got %u", cmdp->cmd, - cmdp->minargc-1, argc); + cmdp->minargc-1, argc-1); else warnx("command `%s' takes from %u to %u arguments", cmdp->cmd, cmdp->minargc-1, cmdp->maxargc-1); >Release-Note: >Audit-Trail: >Unformatted: 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?20020415122640.7BE253E2A>