Date: Sat, 5 Sep 2009 22:35:51 +0200 From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: Mel Flynn <mel.flynn+fbsd.fs@mailing.thruhere.net> Cc: freebsd-fs@freebsd.org, freebsd-geom@freebsd.org Subject: Re: Patch to allow gmirror to set priority of a disk Message-ID: <20090905203551.GK1665@garage.freebsd.pl> In-Reply-To: <200909052225.06185.mel.flynn%2Bfbsd.fs@mailing.thruhere.net> References: <200909030000.11961.mel.flynn%2Bfbsd.fs@mailing.thruhere.net> <200909052111.27667.mel.flynn%2Bfbsd.fs@mailing.thruhere.net> <20090905192251.GJ1665@garage.freebsd.pl> <200909052225.06185.mel.flynn%2Bfbsd.fs@mailing.thruhere.net>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090905203551.GK1665>
