Home | History | Annotate | Line # | Download | only in dmesg
dmesg.c revision 1.27.40.4
      1  1.27.40.4  pgoyette /*	$NetBSD: dmesg.c,v 1.27.40.4 2018/11/26 01:52:14 pgoyette Exp $	*/
      2        1.1       cgd /*-
      3        1.6       cgd  * Copyright (c) 1991, 1993
      4        1.6       cgd  *	The Regents of the University of California.  All rights reserved.
      5        1.1       cgd  *
      6        1.1       cgd  * Redistribution and use in source and binary forms, with or without
      7        1.1       cgd  * modification, are permitted provided that the following conditions
      8        1.1       cgd  * are met:
      9        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     10        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     11        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     13        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     14       1.22       agc  * 3. Neither the name of the University nor the names of its contributors
     15        1.1       cgd  *    may be used to endorse or promote products derived from this software
     16        1.1       cgd  *    without specific prior written permission.
     17        1.1       cgd  *
     18        1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     19        1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20        1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21        1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     22        1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23        1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24        1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25        1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26        1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27        1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28        1.1       cgd  * SUCH DAMAGE.
     29        1.1       cgd  */
     30        1.1       cgd 
     31       1.11     lukem #include <sys/cdefs.h>
     32        1.1       cgd #ifndef lint
     33       1.26     lukem __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
     34       1.26     lukem  The Regents of the University of California.  All rights reserved.");
     35        1.1       cgd #endif /* not lint */
     36        1.1       cgd 
     37        1.1       cgd #ifndef lint
     38        1.8       cgd #if 0
     39        1.6       cgd static char sccsid[] = "@(#)dmesg.c	8.1 (Berkeley) 6/5/93";
     40        1.8       cgd #else
     41  1.27.40.4  pgoyette __RCSID("$NetBSD: dmesg.c,v 1.27.40.4 2018/11/26 01:52:14 pgoyette Exp $");
     42        1.8       cgd #endif
     43        1.1       cgd #endif /* not lint */
     44        1.1       cgd 
     45       1.17    simonb #include <sys/param.h>
     46        1.1       cgd #include <sys/msgbuf.h>
     47       1.17    simonb #include <sys/sysctl.h>
     48        1.6       cgd 
     49        1.7       cgd #include <err.h>
     50  1.27.40.3  pgoyette #include <ctype.h>
     51        1.6       cgd #include <fcntl.h>
     52  1.27.40.1  pgoyette #include <time.h>
     53        1.6       cgd #include <kvm.h>
     54        1.1       cgd #include <nlist.h>
     55        1.6       cgd #include <stdio.h>
     56       1.17    simonb #include <stddef.h>
     57        1.1       cgd #include <stdlib.h>
     58        1.5       jtc #include <unistd.h>
     59        1.6       cgd #include <vis.h>
     60        1.1       cgd 
     61       1.20    simonb #ifndef SMALL
     62  1.27.40.3  pgoyette #include <langinfo.h>
     63  1.27.40.3  pgoyette #include <locale.h>
     64  1.27.40.3  pgoyette 
     65       1.27     joerg static struct nlist nl[] = {
     66        1.6       cgd #define	X_MSGBUF	0
     67       1.25  christos 	{ .n_name = "_msgbufp" },
     68       1.25  christos 	{ .n_name = NULL },
     69        1.1       cgd };
     70        1.1       cgd 
     71  1.27.40.3  pgoyette static const char *radix;
     72  1.27.40.3  pgoyette 
     73       1.27     joerg __dead static void	usage(void);
     74        1.1       cgd 
     75        1.6       cgd #define	KREAD(addr, var) \
     76        1.6       cgd 	kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var)
     77  1.27.40.3  pgoyette 
     78  1.27.40.3  pgoyette static const char *
     79  1.27.40.3  pgoyette fmtydhmsf(char *b, size_t l, intmax_t t, long nsec, int ht)
     80  1.27.40.3  pgoyette {
     81  1.27.40.3  pgoyette 	intmax_t s, m, h;
     82  1.27.40.3  pgoyette 	int z;
     83  1.27.40.3  pgoyette 	int prec;
     84  1.27.40.3  pgoyette 	size_t o;
     85  1.27.40.3  pgoyette 
     86  1.27.40.3  pgoyette 	s = t % 60;
     87  1.27.40.3  pgoyette 	t /= 60;
     88  1.27.40.3  pgoyette 
     89  1.27.40.3  pgoyette 	m = t % 60;
     90  1.27.40.3  pgoyette 	t /= 60;
     91  1.27.40.3  pgoyette 
     92  1.27.40.3  pgoyette 	h = t;
     93  1.27.40.3  pgoyette 
     94  1.27.40.3  pgoyette 	z = 0;
     95  1.27.40.3  pgoyette 	o = 0;
     96  1.27.40.3  pgoyette 
     97  1.27.40.3  pgoyette #define APPENDFMT(fmt, ...)  \
     98  1.27.40.3  pgoyette     do { \
     99  1.27.40.3  pgoyette 	    z = snprintf(b + o, l - o, fmt, __VA_ARGS__); \
    100  1.27.40.3  pgoyette 	    if (z == -1) \
    101  1.27.40.3  pgoyette 		    return b; \
    102  1.27.40.3  pgoyette 	    o += (size_t)z; \
    103  1.27.40.3  pgoyette 	    if (o >= l) \
    104  1.27.40.3  pgoyette 		    return b; \
    105  1.27.40.3  pgoyette     } while (/*CONSTCOND*/0)
    106  1.27.40.3  pgoyette 
    107  1.27.40.3  pgoyette #define APPEND(a) \
    108  1.27.40.3  pgoyette     do if (a) \
    109  1.27.40.3  pgoyette 	APPENDFMT("%jd%c", a, toupper((unsigned char)__STRING(a)[0])); \
    110  1.27.40.3  pgoyette     while (/*CONSTCOND*/0)
    111  1.27.40.3  pgoyette #define APPENDS(a, pr, ms) \
    112  1.27.40.3  pgoyette     APPENDFMT("%jd%s%.*ld%c", a, radix, pr, ms, \
    113  1.27.40.3  pgoyette 	toupper((unsigned char)__STRING(a)[0]))
    114  1.27.40.3  pgoyette 
    115  1.27.40.3  pgoyette 	APPENDFMT("%s", "P");
    116  1.27.40.3  pgoyette 	APPENDFMT("%s", "T");
    117  1.27.40.3  pgoyette 	APPEND(h);
    118  1.27.40.3  pgoyette 	APPEND(m);
    119  1.27.40.3  pgoyette 	if (nsec)
    120  1.27.40.3  pgoyette 		nsec = (nsec + 500000) / 1000000;	/* now milliseconds */
    121  1.27.40.3  pgoyette 	prec = 3;
    122  1.27.40.3  pgoyette 	if (nsec && ht == 2) {
    123  1.27.40.3  pgoyette 		while (prec > 0 && (nsec % 10) == 0)
    124  1.27.40.3  pgoyette 			--prec, nsec /= 10;
    125  1.27.40.3  pgoyette 	}
    126  1.27.40.3  pgoyette 	if (nsec || ht > 2)
    127  1.27.40.3  pgoyette 		APPENDS(s, prec, nsec);
    128  1.27.40.3  pgoyette 	else
    129  1.27.40.3  pgoyette 		APPEND(s);
    130  1.27.40.3  pgoyette 	return b;
    131  1.27.40.3  pgoyette }
    132  1.27.40.3  pgoyette 
    133  1.27.40.3  pgoyette static void
    134  1.27.40.3  pgoyette pnsec(long nsec, long fsec, int scale)
    135  1.27.40.3  pgoyette {
    136  1.27.40.3  pgoyette 	if (scale > 6)
    137  1.27.40.3  pgoyette 		printf("%6.6ld", (nsec + 499) / 1000);
    138  1.27.40.3  pgoyette 	else
    139  1.27.40.3  pgoyette 		printf("%*.*ld%.*s", scale, scale, fsec, 6 - scale, "000000");
    140  1.27.40.3  pgoyette }
    141       1.24       dsl #endif
    142        1.6       cgd 
    143        1.6       cgd int
    144       1.18    simonb main(int argc, char *argv[])
    145        1.1       cgd {
    146       1.17    simonb 	struct kern_msgbuf cur;
    147  1.27.40.1  pgoyette 	int ch, newl, log, i;
    148  1.27.40.1  pgoyette 	size_t tstamp, size;
    149       1.20    simonb 	char *p, *bufdata;
    150  1.27.40.1  pgoyette 	char buf[5];
    151       1.20    simonb #ifndef SMALL
    152  1.27.40.1  pgoyette 	char tbuf[64];
    153       1.20    simonb 	char *memf, *nlistf;
    154  1.27.40.4  pgoyette 	struct timespec boottime;
    155  1.27.40.2  pgoyette 	struct timespec lasttime;
    156  1.27.40.2  pgoyette 	intmax_t sec;
    157  1.27.40.2  pgoyette 	long nsec, fsec;
    158  1.27.40.2  pgoyette 	int scale;
    159  1.27.40.2  pgoyette 	int deltas, quiet, humantime;
    160  1.27.40.2  pgoyette 	bool frac;
    161  1.27.40.3  pgoyette 
    162  1.27.40.1  pgoyette 	static const int bmib[] = { CTL_KERN, KERN_BOOTTIME };
    163  1.27.40.1  pgoyette 	size = sizeof(boottime);
    164  1.27.40.1  pgoyette 
    165  1.27.40.3  pgoyette 	(void)setlocale(LC_ALL, "");
    166  1.27.40.3  pgoyette 	radix = nl_langinfo(RADIXCHAR);
    167  1.27.40.3  pgoyette 	if (radix == NULL)
    168  1.27.40.3  pgoyette 		radix = ".";	/* could also select "," */
    169  1.27.40.3  pgoyette 
    170  1.27.40.1  pgoyette 	boottime.tv_sec = 0;
    171  1.27.40.4  pgoyette 	boottime.tv_nsec = 0;
    172  1.27.40.2  pgoyette 	lasttime.tv_sec = 0;
    173  1.27.40.2  pgoyette 	lasttime.tv_nsec = 0;
    174  1.27.40.2  pgoyette 	deltas = quiet = humantime = 0;
    175  1.27.40.1  pgoyette 
    176  1.27.40.3  pgoyette 	(void)sysctl(bmib, 2, &boottime, &size, NULL, 0);
    177        1.1       cgd 
    178        1.6       cgd 	memf = nlistf = NULL;
    179  1.27.40.2  pgoyette 	while ((ch = getopt(argc, argv, "dM:N:tT")) != -1)
    180        1.1       cgd 		switch(ch) {
    181  1.27.40.2  pgoyette 		case 'd':
    182  1.27.40.2  pgoyette 			deltas = 1;
    183  1.27.40.2  pgoyette 			break;
    184        1.1       cgd 		case 'M':
    185        1.6       cgd 			memf = optarg;
    186        1.1       cgd 			break;
    187        1.1       cgd 		case 'N':
    188        1.6       cgd 			nlistf = optarg;
    189        1.1       cgd 			break;
    190  1.27.40.1  pgoyette 		case 't':
    191  1.27.40.2  pgoyette 			quiet = 1;
    192  1.27.40.2  pgoyette 			break;
    193  1.27.40.2  pgoyette 		case 'T':
    194  1.27.40.3  pgoyette 			humantime++;
    195  1.27.40.1  pgoyette 			break;
    196        1.1       cgd 		case '?':
    197        1.1       cgd 		default:
    198        1.1       cgd 			usage();
    199        1.1       cgd 		}
    200        1.1       cgd 	argc -= optind;
    201        1.1       cgd 	argv += optind;
    202  1.27.40.2  pgoyette 	if (quiet && humantime)
    203  1.27.40.2  pgoyette 		err(EXIT_FAILURE, "-t cannot be used with -T");
    204        1.1       cgd 
    205       1.19    simonb 	if (memf == NULL) {
    206       1.20    simonb #endif
    207  1.27.40.1  pgoyette 		static const int mmib[2] = { CTL_KERN, KERN_MSGBUF };
    208       1.17    simonb 
    209  1.27.40.1  pgoyette 		if (sysctl(mmib, 2, NULL, &size, NULL, 0) == -1 ||
    210       1.24       dsl 		    (bufdata = malloc(size)) == NULL ||
    211  1.27.40.1  pgoyette 		    sysctl(mmib, 2, bufdata, &size, NULL, 0) == -1)
    212       1.17    simonb 			err(1, "can't get msgbuf");
    213       1.17    simonb 
    214       1.17    simonb 		/* make a dummy struct msgbuf for the display logic */
    215       1.24       dsl 		cur.msg_bufx = 0;
    216       1.24       dsl 		cur.msg_bufs = size;
    217       1.20    simonb #ifndef SMALL
    218       1.17    simonb 	} else {
    219       1.17    simonb 		kvm_t *kd;
    220       1.17    simonb 		struct kern_msgbuf *bufp;
    221       1.17    simonb 
    222       1.17    simonb 		/*
    223       1.17    simonb 		 * Read in message buffer header and data, and do sanity
    224       1.17    simonb 		 * checks.
    225       1.17    simonb 		 */
    226       1.17    simonb 		kd = kvm_open(nlistf, memf, NULL, O_RDONLY, "dmesg");
    227       1.17    simonb 		if (kd == NULL)
    228       1.17    simonb 			exit (1);
    229       1.17    simonb 		if (kvm_nlist(kd, nl) == -1)
    230       1.17    simonb 			errx(1, "kvm_nlist: %s", kvm_geterr(kd));
    231       1.17    simonb 		if (nl[X_MSGBUF].n_type == 0)
    232       1.17    simonb 			errx(1, "%s: msgbufp not found", nlistf ? nlistf :
    233       1.17    simonb 			    "namelist");
    234       1.17    simonb 		if (KREAD(nl[X_MSGBUF].n_value, bufp))
    235       1.17    simonb 			errx(1, "kvm_read: %s (0x%lx)", kvm_geterr(kd),
    236       1.17    simonb 			    nl[X_MSGBUF].n_value);
    237       1.17    simonb 		if (kvm_read(kd, (long)bufp, &cur,
    238       1.17    simonb 		    offsetof(struct kern_msgbuf, msg_bufc)) !=
    239       1.17    simonb 		    offsetof(struct kern_msgbuf, msg_bufc))
    240       1.17    simonb 			errx(1, "kvm_read: %s (0x%lx)", kvm_geterr(kd),
    241       1.17    simonb 			    (unsigned long)bufp);
    242       1.17    simonb 		if (cur.msg_magic != MSG_MAGIC)
    243       1.17    simonb 			errx(1, "magic number incorrect");
    244       1.17    simonb 		bufdata = malloc(cur.msg_bufs);
    245       1.17    simonb 		if (bufdata == NULL)
    246       1.17    simonb 			errx(1, "couldn't allocate space for buffer data");
    247       1.17    simonb 		if (kvm_read(kd, (long)&bufp->msg_bufc, bufdata,
    248       1.17    simonb 		    cur.msg_bufs) != cur.msg_bufs)
    249       1.17    simonb 			errx(1, "kvm_read: %s", kvm_geterr(kd));
    250       1.17    simonb 		kvm_close(kd);
    251       1.17    simonb 		if (cur.msg_bufx >= cur.msg_bufs)
    252       1.17    simonb 			cur.msg_bufx = 0;
    253       1.17    simonb 	}
    254       1.20    simonb #endif
    255        1.1       cgd 
    256        1.1       cgd 	/*
    257       1.14     enami 	 * The message buffer is circular; start at the write pointer
    258       1.14     enami 	 * (which points the oldest character), and go to the write
    259       1.14     enami 	 * pointer - 1 (which points the newest character).  I.e, loop
    260       1.14     enami 	 * over cur.msg_bufs times.  Unused area is skipped since it
    261       1.14     enami 	 * contains nul.
    262        1.1       cgd 	 */
    263  1.27.40.2  pgoyette #ifndef SMALL
    264  1.27.40.2  pgoyette 	frac = false;
    265  1.27.40.2  pgoyette 	scale = 0;
    266  1.27.40.2  pgoyette #endif
    267  1.27.40.1  pgoyette 	for (tstamp = 0, newl = 1, log = i = 0, p = bufdata + cur.msg_bufx;
    268       1.14     enami 	    i < cur.msg_bufs; i++, p++) {
    269  1.27.40.2  pgoyette 
    270       1.24       dsl #ifndef SMALL
    271       1.12       leo 		if (p == bufdata + cur.msg_bufs)
    272       1.12       leo 			p = bufdata;
    273  1.27.40.1  pgoyette #define ADDC(c)				\
    274  1.27.40.2  pgoyette     do {				\
    275  1.27.40.1  pgoyette 	if (tstamp < sizeof(tbuf) - 1)	\
    276  1.27.40.1  pgoyette 		tbuf[tstamp++] = (c);	\
    277  1.27.40.2  pgoyette 	if (frac)			\
    278  1.27.40.2  pgoyette 		scale++;		\
    279  1.27.40.2  pgoyette     } while (/*CONSTCOND*/0)
    280  1.27.40.1  pgoyette #else
    281  1.27.40.1  pgoyette #define ADDC(c)
    282       1.24       dsl #endif
    283        1.1       cgd 		ch = *p;
    284        1.1       cgd 		if (ch == '\0')
    285        1.1       cgd 			continue;
    286  1.27.40.1  pgoyette 		/* Skip "\n<.*>" syslog sequences. */
    287  1.27.40.1  pgoyette 		/* Gather timestamp sequences */
    288  1.27.40.1  pgoyette 		if (newl) {
    289  1.27.40.2  pgoyette #ifndef SMALL
    290  1.27.40.2  pgoyette 			int j;
    291  1.27.40.2  pgoyette #endif
    292  1.27.40.2  pgoyette 
    293  1.27.40.1  pgoyette 			switch (ch) {
    294  1.27.40.1  pgoyette 			case '[':
    295  1.27.40.2  pgoyette #ifndef SMALL
    296  1.27.40.2  pgoyette 				frac = false;
    297  1.27.40.2  pgoyette 				scale = 0;
    298  1.27.40.2  pgoyette #endif
    299  1.27.40.1  pgoyette 				ADDC(ch);
    300  1.27.40.1  pgoyette 				continue;
    301  1.27.40.1  pgoyette 			case '<':
    302  1.27.40.1  pgoyette 				log = 1;
    303  1.27.40.1  pgoyette 				continue;
    304  1.27.40.1  pgoyette 			case '>':
    305  1.27.40.1  pgoyette 				log = 0;
    306  1.27.40.1  pgoyette 				continue;
    307  1.27.40.1  pgoyette 			case ']':
    308  1.27.40.2  pgoyette #ifndef SMALL
    309  1.27.40.2  pgoyette 				frac = false;
    310  1.27.40.2  pgoyette #endif
    311  1.27.40.1  pgoyette 				ADDC(ch);
    312  1.27.40.1  pgoyette 				ADDC('\0');
    313  1.27.40.1  pgoyette 				tstamp = 0;
    314  1.27.40.1  pgoyette #ifndef SMALL
    315  1.27.40.2  pgoyette 				sec = fsec = 0;
    316  1.27.40.2  pgoyette 				switch (sscanf(tbuf, "[%jd.%ld]", &sec, &fsec)){
    317  1.27.40.2  pgoyette 				case EOF:
    318  1.27.40.2  pgoyette 				case 0:
    319  1.27.40.2  pgoyette 					/*???*/
    320  1.27.40.2  pgoyette 					continue;
    321  1.27.40.2  pgoyette 				case 1:
    322  1.27.40.2  pgoyette 					fsec = 0;
    323  1.27.40.2  pgoyette 					break;
    324  1.27.40.2  pgoyette 				case 2:
    325  1.27.40.2  pgoyette 					break;
    326  1.27.40.2  pgoyette 				default:
    327  1.27.40.2  pgoyette 					/* Help */
    328  1.27.40.2  pgoyette 					continue;
    329  1.27.40.2  pgoyette 				}
    330  1.27.40.2  pgoyette 
    331  1.27.40.2  pgoyette 				for (nsec = fsec, j = 9 - scale; --j >= 0; )
    332  1.27.40.2  pgoyette 					nsec *= 10;
    333  1.27.40.2  pgoyette 				if (!quiet || deltas)
    334  1.27.40.2  pgoyette 					printf("[");
    335  1.27.40.3  pgoyette 				if (humantime == 1) {
    336  1.27.40.1  pgoyette 					time_t t;
    337  1.27.40.1  pgoyette 					struct tm tm;
    338  1.27.40.1  pgoyette 
    339  1.27.40.1  pgoyette 					t = boottime.tv_sec + sec;
    340  1.27.40.4  pgoyette 					if (nsec + boottime.tv_nsec >=
    341  1.27.40.4  pgoyette 					    ( 1L		/* 1 second */
    342  1.27.40.4  pgoyette 						 * 1000L	/* ms */
    343  1.27.40.4  pgoyette 						 * 1000L	/* us */
    344  1.27.40.4  pgoyette 						 * 1000L	/* ns */ ))
    345  1.27.40.4  pgoyette 							t++;
    346  1.27.40.4  pgoyette 
    347  1.27.40.1  pgoyette 					if (localtime_r(&t, &tm) != NULL) {
    348  1.27.40.1  pgoyette 						strftime(tbuf, sizeof(tbuf),
    349  1.27.40.2  pgoyette 						    "%a %b %e %H:%M:%S %Z %Y",
    350  1.27.40.3  pgoyette 						    &tm);
    351  1.27.40.2  pgoyette 						printf("%s", tbuf);
    352  1.27.40.1  pgoyette 					}
    353  1.27.40.3  pgoyette 				} else if (humantime > 1) {
    354  1.27.40.3  pgoyette 					const char *fp = fmtydhmsf(tbuf,
    355  1.27.40.3  pgoyette 					    sizeof(tbuf), sec, fsec, humantime);
    356  1.27.40.3  pgoyette 					if (fp) {
    357  1.27.40.3  pgoyette 						printf("%s", fp);
    358  1.27.40.3  pgoyette 					}
    359  1.27.40.2  pgoyette 				} else if (!quiet) {
    360  1.27.40.3  pgoyette 					printf(" %5jd%s", sec, radix);
    361  1.27.40.3  pgoyette 					pnsec(nsec, fsec, scale);
    362  1.27.40.2  pgoyette 				}
    363  1.27.40.2  pgoyette 				if (deltas) {
    364  1.27.40.2  pgoyette 					struct timespec nt = { sec, nsec };
    365  1.27.40.2  pgoyette 					struct timespec dt;
    366  1.27.40.2  pgoyette 
    367  1.27.40.2  pgoyette 					timespecsub(&nt, &lasttime, &dt);
    368  1.27.40.2  pgoyette 					if (humantime || !quiet)
    369  1.27.40.2  pgoyette 						printf(" ");
    370  1.27.40.3  pgoyette 					printf("<% 4jd%s%6.6ld>",
    371  1.27.40.3  pgoyette 					    (intmax_t)dt.tv_sec, radix,
    372  1.27.40.3  pgoyette 					    (dt.tv_nsec+499) / 1000);
    373  1.27.40.2  pgoyette 					lasttime = nt;
    374  1.27.40.2  pgoyette 				}
    375  1.27.40.2  pgoyette 				if (!quiet || deltas)
    376  1.27.40.2  pgoyette 					printf("] ");
    377  1.27.40.1  pgoyette #endif
    378  1.27.40.1  pgoyette 				continue;
    379  1.27.40.1  pgoyette 			case ' ':
    380  1.27.40.1  pgoyette 				if (!tstamp)
    381  1.27.40.3  pgoyette 					continue;
    382  1.27.40.1  pgoyette 				/*FALLTHROUGH*/
    383  1.27.40.1  pgoyette 			default:
    384  1.27.40.1  pgoyette 				if (tstamp) {
    385  1.27.40.1  pgoyette 				    ADDC(ch);
    386  1.27.40.2  pgoyette #ifndef SMALL
    387  1.27.40.2  pgoyette 				    if (ch == '.')
    388  1.27.40.2  pgoyette 					frac = true;
    389  1.27.40.2  pgoyette #endif
    390  1.27.40.1  pgoyette 				    continue;
    391  1.27.40.1  pgoyette 				}
    392  1.27.40.1  pgoyette 				if (log)
    393  1.27.40.1  pgoyette 					continue;
    394  1.27.40.1  pgoyette 				break;
    395  1.27.40.1  pgoyette 			}
    396  1.27.40.1  pgoyette 			newl = 0;
    397  1.27.40.1  pgoyette 		}
    398        1.6       cgd 		newl = ch == '\n';
    399       1.21  augustss 		(void)vis(buf, ch, VIS_NOSLASH, 0);
    400       1.24       dsl #ifndef SMALL
    401        1.6       cgd 		if (buf[1] == 0)
    402        1.6       cgd 			(void)putchar(buf[0]);
    403        1.6       cgd 		else
    404       1.24       dsl #endif
    405        1.6       cgd 			(void)printf("%s", buf);
    406       1.12       leo 	}
    407        1.1       cgd 	if (!newl)
    408        1.1       cgd 		(void)putchar('\n');
    409  1.27.40.1  pgoyette 	return EXIT_SUCCESS;
    410        1.1       cgd }
    411        1.1       cgd 
    412       1.24       dsl #ifndef SMALL
    413       1.27     joerg static void
    414       1.18    simonb usage(void)
    415        1.1       cgd {
    416       1.15     enami 
    417  1.27.40.2  pgoyette 	(void)fprintf(stderr, "Usage: %s [-dTt] [-M core] [-N system]\n",
    418  1.27.40.1  pgoyette 		getprogname());
    419  1.27.40.1  pgoyette 	exit(EXIT_FAILURE);
    420        1.1       cgd }
    421       1.24       dsl #endif
    422