From owner-svn-src-head@freebsd.org Fri Jun 22 11:02:40 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AFE0A10173BF; Fri, 22 Jun 2018 11:02:40 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6279E8BA2E; Fri, 22 Jun 2018 11:02:40 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from ivaldir.etoilebsd.net (etoilebsd.net [178.32.217.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: bapt) by smtp.freebsd.org (Postfix) with ESMTPSA id 03EDEF0B2; Fri, 22 Jun 2018 11:02:40 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: by ivaldir.etoilebsd.net (Postfix, from userid 1001) id 7FC4D896FF; Fri, 22 Jun 2018 13:02:38 +0200 (CEST) Date: Fri, 22 Jun 2018 13:02:38 +0200 From: Baptiste Daroussin To: Eitan Adler Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r335539 - head/usr.bin/top Message-ID: <20180622110238.v7gwug4hebuclwb6@ivaldir.net> References: <201806220921.w5M9L21k031794@repo.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pab43qwvq364jsma" Content-Disposition: inline In-Reply-To: <201806220921.w5M9L21k031794@repo.freebsd.org> User-Agent: NeoMutt/20180512 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jun 2018 11:02:40 -0000 --pab43qwvq364jsma Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jun 22, 2018 at 09:21:02AM +0000, Eitan Adler wrote: > Author: eadler > Date: Fri Jun 22 09:21:01 2018 > New Revision: 335539 > URL: https://svnweb.freebsd.org/changeset/base/335539 >=20 > Log: > top(1): reimplement header formatting as sbuf > =20 > The current header formatting is a giant format string that changes > global state during the format process. > =20 > Make the following changes: > - use sbuf to build up the header rather than use the above > pseudo-dynamic one > - Change name length to 10 > - Reduce size of RES and SIZE by making humanize more aggressive > - Restore a version number line to the copyright. This may be required > by the copyright (and may not be; its unclear) > =20 > This is also a pre-req to implementing TOPCOLOR from newer versions of > top(1) > =20 > Discussed with: allanjude, rpolka, danfe, rgrimes > Differential Revision: https://reviews.freebsd.org/D15801 >=20 > Modified: > head/usr.bin/top/Makefile > head/usr.bin/top/commands.c > head/usr.bin/top/machine.c > head/usr.bin/top/machine.h > head/usr.bin/top/utils.c >=20 > Modified: head/usr.bin/top/Makefile > =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=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/usr.bin/top/Makefile Fri Jun 22 09:20:50 2018 (r335538) > +++ head/usr.bin/top/Makefile Fri Jun 22 09:21:01 2018 (r335539) > @@ -16,5 +16,5 @@ NO_WERROR=3D > .endif > CFLAGS.clang=3D-Wno-error=3Dincompatible-pointer-types-discards-qualifie= rs -Wno-error=3Dcast-qual > =20 > -LIBADD=3D ncursesw m kvm jail util > +LIBADD=3D ncursesw m kvm jail util sbuf > .include >=20 > Modified: head/usr.bin/top/commands.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=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/usr.bin/top/commands.c Fri Jun 22 09:20:50 2018 (r335538) > +++ head/usr.bin/top/commands.c Fri Jun 22 09:21:01 2018 (r335539) > @@ -1,5 +1,6 @@ > /* > * Top users/processes display for Unix > + * Version 3 > * > * This program may be freely redistributed, > * but this entire comment MUST remain intact. >=20 > Modified: head/usr.bin/top/machine.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=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/usr.bin/top/machine.c Fri Jun 22 09:20:50 2018 (r335538) > +++ head/usr.bin/top/machine.c Fri Jun 22 09:21:01 2018 (r335539) > @@ -22,6 +22,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -49,18 +50,14 @@ > #include "layout.h" > =20 > #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) > -#define SMPUNAMELEN 13 > -#define UPUNAMELEN 15 > =20 > extern struct timeval timeout; > static int smpmode; > enum displaymodes displaymode; > -static int namelength =3D 8; > +static const int namelength =3D 10; > /* TOP_JID_LEN based on max of 999999 */ > -#define TOP_JID_LEN 7 > -#define TOP_SWAP_LEN 6 > -static int jidlength; > -static int swaplength; > +#define TOP_JID_LEN 6 > +#define TOP_SWAP_LEN 5 > static int cmdlengthdelta; > =20 > /* get_process_info passes back a handle. This is what it looks like: */ > @@ -92,24 +89,12 @@ static const char io_header[] =3D > static const char io_Proc_format[] =3D > "%5d%*s %-*.*s %6ld %6ld %6ld %6ld %6ld %6ld %6.2f%% %.*s"; > =20 > -/* XXX: build up header instead of statically defining them. > - * This will also allow for a "format string" to be supplied > - * as an argument to top(1) instead of having predefined options */ > -static const char smp_header_thr_and_pid[] =3D > - " %s%*s %-*.*s THR PRI NICE SIZE RES%*s STATE C TIME %7s = COMMAND"; > -static const char smp_header_id_only[] =3D > - " %s%*s %-*.*s PRI NICE SIZE RES%*s STATE C TIME %7s COMM= AND"; > static const char smp_Proc_format[] =3D > - "%5d%*s %-*.*s %s%3d %4s%7s %6s%*.*s %-6.6s %2d%7s %6.2f%% %.*s"; > + "%5d%*s %-*.*s %s%3d %4s%6s %5s%*.*s %-6.6s %2d%7s %6.2f%% %.*s"; > =20 > -static char up_header_thr_and_pid[] =3D > - " %s%*s %-*.*s THR PRI NICE SIZE RES%*s STATE TIME %7s COM= MAND"; > -static char up_header_id_only[] =3D > - " %s%*s %-*.*s PRI NICE SIZE RES%*s STATE TIME %7s COMMAN= D"; > static char up_Proc_format[] =3D > - "%5d%*s %-*.*s %s%3d %4s%7s %6s%*.*s %-6.6s%.0d%7s %6.2f%% %.*s"; > + "%5d%*s %-*.*s %s%3d %4s%6s %5s%*.*s %-6.6s%.0d%7s %6.2f%% %.*s"; > =20 > - > /* process state names for the "STATE" column of the display */ > /* the extra nulls in the string "run" are for adding a slash and > the processor number when needed */ > @@ -325,12 +310,6 @@ machine_init(struct statics *statics) > NULL, 0) =3D=3D 0 && carc_en =3D=3D 1) > carc_enabled =3D 1; > =20 > - namelength =3D MAXLOGNAME; > - if (smpmode && namelength > SMPUNAMELEN) > - namelength =3D SMPUNAMELEN; > - else if (namelength > UPUNAMELEN) > - namelength =3D UPUNAMELEN; > - > kd =3D kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open"); > if (kd =3D=3D NULL) > return (-1); > @@ -407,63 +386,46 @@ machine_init(struct statics *statics) > return (0); > } > =20 > -const char * > +char * > format_header(const char *uname_field) > { > - static char Header[128]; > - const char *prehead; > + static struct sbuf* header =3D NULL; > =20 > - if (ps.jail) > - jidlength =3D TOP_JID_LEN + 1; /* +1 for extra left space. */ > - else > - jidlength =3D 0; > + /* clean up from last time. */ > + if (header !=3D NULL) { > + sbuf_delete(header); wouldn't it be better with a sbuf_clear here? if !=3D null: clear else new_auto Best regards, Bapt --pab43qwvq364jsma Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEgOTj3suS2urGXVU3Y4mL3PG3PloFAlss1zMACgkQY4mL3PG3 Plr3+xAAy3vP0xawm6PnS98anYh1xgp4tCa1GODxnyw7CiNHk0qFONiI3hsh/y/y Nvn7HOQhz3B42RM1J83aMC/PAK/THHw991Jld8jdbiQKfF2FitGod9NpqP8UL50W KjhKh6smHGLq3+weMcSA9zrBYPHSlTwspL11AzDVfyIdwBOwNL0iGtw7nrC0P4us cuY9nSbFk37Ex4tCQ5fgAuqZ14+ms29Y23CsTqOZ5Ov7bwGYQ9JLtOoo9QsnL3cm /VYibmbCchpIVgCteMUFvyMP/Wun4IeBPuDud7101nwxDuZMytaVSwLbNrY/cncD V/deMa3em63oGE6C374kH+/gDTaxLiPlEkrwXgf0DPXJYbqiwO01EBfiAGyde99p 8K2wYyOOWEf5bvo9xejF4E28aLd/7LZ1OndF9RZtyWP9EVl3GyUW5WP9cv/UyTHs aXxp6WkKw1i27tF/0EnXpTQIm84o19S7cTd7KK3gfR/tO30ogLQktR0l8YKEF3hF Zpr28qzBMI1wB+/FhLgQx63wfJEnb9BOM0Ys7M24CO5kXGWYeRw13dyRc9opa+4Q GtDO8tUfV8+2ZUT5/rLiTGeN0Ei5Z+mhn8/PqgZjRMHoT6hWG462mmPBLOhmov0I oWoZ2NiYjlgojwxszHlk1q4d+C+3jtNei9Ug7cMaUHVxwzOSIK4= =gju3 -----END PGP SIGNATURE----- --pab43qwvq364jsma--