From owner-freebsd-fs@FreeBSD.ORG Sat Sep 5 20:36:00 2009 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0302B106568D; Sat, 5 Sep 2009 20:36:00 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: from mail.garage.freebsd.pl (chello087206049004.chello.pl [87.206.49.4]) by mx1.freebsd.org (Postfix) with ESMTP id 47F3B8FC08; Sat, 5 Sep 2009 20:35:58 +0000 (UTC) Received: by mail.garage.freebsd.pl (Postfix, from userid 65534) id 4647B45F22; Sat, 5 Sep 2009 22:35:57 +0200 (CEST) Received: from localhost (chello087206049004.chello.pl [87.206.49.4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.garage.freebsd.pl (Postfix) with ESMTP id 7213F456B1; Sat, 5 Sep 2009 22:35:50 +0200 (CEST) Date: Sat, 5 Sep 2009 22:35:51 +0200 From: Pawel Jakub Dawidek To: Mel Flynn Message-ID: <20090905203551.GK1665@garage.freebsd.pl> References: <200909030000.11961.mel.flynn+fbsd.fs@mailing.thruhere.net> <200909052111.27667.mel.flynn+fbsd.fs@mailing.thruhere.net> <20090905192251.GJ1665@garage.freebsd.pl> <200909052225.06185.mel.flynn+fbsd.fs@mailing.thruhere.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OGLMwEELQbPC02lM" Content-Disposition: inline In-Reply-To: <200909052225.06185.mel.flynn+fbsd.fs@mailing.thruhere.net> User-Agent: Mutt/1.4.2.3i X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc X-OS: FreeBSD 8.0-CURRENT i386 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on mail.garage.freebsd.pl X-Spam-Level: X-Spam-Status: No, score=-0.6 required=4.5 tests=BAYES_00,RCVD_IN_SORBS_DUL autolearn=no version=3.0.4 Cc: freebsd-fs@freebsd.org, freebsd-geom@freebsd.org Subject: Re: Patch to allow gmirror to set priority of a disk X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Sep 2009 20:36:00 -0000 --OGLMwEELQbPC02lM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Sep 05, 2009 at 10:25:05PM +0200, Mel Flynn wrote: > On Saturday 05 September 2009 21:22:51 Pawel Jakub Dawidek wrote: >=20 > > And tech core geom(8) utility to split usage based on \n. > > usage_command() function from sbin/geom/core/geom.c would have to be > > modified. If you agree with this idea, would you also like to work on > > this? >=20 > Yes and see attached. Since utility exists after displaying usage, I didn= 't=20 > take the trouble of freeing ptr, but if this is preferred then I'll add t= he=20 > line. I think it would be good to free memory just to make it elegant. > % geom mirror foo > geom: Unknown command: foo. > usage: geom mirror activate [-v] name prov ... > geom mirror clear [-v] prov ... > geom mirror configure[-adfFhnv] [-b balance] [-s slice] name > geom mirror configure -p priority name prov >=20 > --=20 > Mel > Index: sbin/geom/core/geom.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- sbin/geom/core/geom.c (revision 196868) > +++ sbin/geom/core/geom.c (working copy) > @@ -98,11 +98,23 @@ > struct g_option *opt; > unsigned i; > =20 > - fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name); > if (cmd->gc_usage !=3D NULL) { > - fprintf(stderr, " %s\n", cmd->gc_usage); > + char *pos, *ptr; > + > + ptr =3D strdup(cmd->gc_usage); > + while ((pos =3D strchr(ptr, '\n')) !=3D NULL) { Wouldn't it be easier to use strsep(3)? > + *pos =3D '\0'; > + fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name); > + fprintf(stderr, "%s\n", ptr); Why to split this into two fprintfs? There is also space missing before %s. > + ptr =3D pos + 1; > + } > + /* Tail or no \n at all */ > + fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name); > + fprintf(stderr, " %s\n", ptr); > return; > } > + > + fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name); > if ((cmd->gc_flags & G_FLAG_VERBOSE) !=3D 0) > fprintf(stderr, " [-v]"); > for (i =3D 0; ; i++) { With strsep(3) it would look like this: if (cmd->gc_usage !=3D NULL) { char *cur, *ptr, *tofree; tofree =3D ptr =3D strdup(cmd->gc_usage); while ((cur =3D strsep(&ptr, "\n")) !=3D NULL) { if (*cur =3D=3D '\0') continue; fprintf(stderr, "%s %s %s %s\n", prefix, comm, cmd->gc_name, cur); } free(tofree); return; } --=20 Pawel Jakub Dawidek http://www.wheel.pl pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! --OGLMwEELQbPC02lM Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFKosunForvXbEpPzQRAljRAJ9TdBhx47uuQOr8uppEKG51v/miVwCg76sb czv02Cs0aNf7RZhQKcjvkCA= =G0aC -----END PGP SIGNATURE----- --OGLMwEELQbPC02lM--