9front - general discussion about 9front
 help / color / mirror / Atom feed
From: BurnZeZ@feline.systems
To: 9front@9front.org
Subject: Re: [9front] time v2
Date: Sat, 11 Aug 2018 21:09:18 +0000	[thread overview]
Message-ID: <747997f27a1b65ae1bf34d957b0614a2@rebk.znet> (raw)
In-Reply-To: <20180811204734.GB28541@wopr>

[-- Attachment #1: Type: text/plain, Size: 185 bytes --]

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.

[-- Attachment #2: Type: text/plain, Size: 1019 bytes --]

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<argc; i++){
 		add("%s", argv[i], 0);

  reply	other threads:[~2018-08-11 21:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-11 20:47 Kurt H Maier
2018-08-11 21:09 ` BurnZeZ [this message]
2018-08-12  5:39 Alex Musolino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=747997f27a1b65ae1bf34d957b0614a2@rebk.znet \
    --to=burnzez@feline.systems \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).