From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from feline.systems ([99.23.220.214]) by ewsd; Sat Aug 11 17:09:23 EDT 2018 Date: Sat, 11 Aug 2018 21:09:18 +0000 From: BurnZeZ@feline.systems To: 9front@9front.org Subject: Re: [9front] time v2 Message-ID: <747997f27a1b65ae1bf34d957b0614a2@rebk.znet> In-Reply-To: <20180811204734.GB28541@wopr> References: <20180811204734.GB28541@wopr> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-sfmeeupghbhkphcxodqedpjgxv" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: plugin-scale dependency proxy locator This is a multi-part message in MIME format. --upas-sfmeeupghbhkphcxodqedpjgxv Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Clearly written by an idiot. Comparing segattach to -1 will break on architectures where pointers require more than 32-bits. (possibly other situations too(?)) Corrected diff attached. --upas-sfmeeupghbhkphcxodqedpjgxv Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit diff -r 5c5acc9ab7a5 sys/src/cmd/time.c --- a/sys/src/cmd/time.c Sat Aug 11 16:19:32 2018 +0200 +++ b/sys/src/cmd/time.c Sat Aug 11 21:02:13 2018 +0000 @@ -14,16 +14,22 @@ long l; char *p; char err[ERRMAX]; + vlong *t0, t1; + enum { SEC = 1000000000ULL }; if(argc <= 1){ fprint(2, "usage: time command\n"); exits("usage"); } + if((t0 = segattach(SG_CEXEC, "shared", nil, sizeof(*t0))) == (void*)-1) + sysfatal("segattach: %r"); + *t0 = 0; switch(fork()){ case -1: error("fork"); case 0: + *t0 = nsec(); exec(argv[1], &argv[1]); if(argv[1][0] != '/' && strncmp(argv[1], "./", 2) && strncmp(argv[1], "../", 3)){ @@ -43,12 +49,14 @@ goto loop; error("wait"); } + t1 = nsec(); l = w->time[0]; add("%ld.%.2ldu", l/1000, (l%1000)/10); l = w->time[1]; add("%ld.%.2lds", l/1000, (l%1000)/10); l = w->time[2]; add("%ld.%.2ldr", l/1000, (l%1000)/10); + add("%lld.%.9lldt", (t1-*t0)/SEC, (t1-*t0)%SEC); add("\t"); for(i=1; i