Print this page
6623 iostat -exrn has missing comma (field separator) in header
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
@@ -27,10 +27,11 @@
* rewritten from SunOS 4.1 SID 1.18 89/10/06
*/
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2016 James S. Blachly, MD. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -1268,11 +1269,11 @@
*/
void
do_format(void)
{
- char header[SMALL_SCRATCH_BUFLEN];
+ char header[SMALL_SCRATCH_BUFLEN] = {0};
char ch;
char iosz;
const char *fstr;
disk_header[0] = 0;
@@ -1281,12 +1282,11 @@
if (do_disk & DISK_ERRORS) {
if (do_raw == 0) {
(void) sprintf(header, "s/w h/w trn tot ");
} else
(void) sprintf(header, "s/w,h/w,trn,tot");
- } else
- *header = NULL;
+ }
switch (do_disk & DISK_IO_MASK) {
case DISK_OLD:
if (do_raw == 0)
fstr = "%cp%c tp%c serv ";
else
@@ -1319,12 +1319,19 @@
/* with -r option */
(void) snprintf(disk_header,
sizeof (disk_header),
"device,r/%c,w/%c,%cr/%c,%cw/%c,"
"wait,actv,svc_t,%%%%w,"
- "%%%%b,%s",
- ch, ch, iosz, ch, iosz, ch, header);
+ "%%%%b%s%s",
+ ch, ch, iosz, ch, iosz, ch,
+ *header == '\0' ? "" : ",",
+ header);
+ /*
+ * if no -e flag, header == '\0...'
+ * Ternary operator above is to prevent
+ * trailing comma in full disk_header
+ */
}
} else {
/* with -n option */
if (do_raw == 0) {
fstr = " r/%c w/%c %cr/%c "
@@ -1332,10 +1339,22 @@
"%%%%w %%%%b %sdevice";
} else {
fstr = "r/%c,w/%c,%cr/%c,%cw/%c,"
"wait,actv,wsvc_t,asvc_t,"
"%%%%w,%%%%b,%sdevice";
+ /*
+ * if -rnxe, "tot" (from -e) and
+ * "device" are run together
+ * due to lack of trailing comma
+ * in 'header'. However, adding
+ * trailing comma to header at
+ * its definition leads to prob-
+ * lems elsewhere so it's added
+ * here in this edge case -rnxe
+ */
+ if (*header != '\0')
+ (void) strcat(header, ",");
}
(void) snprintf(disk_header,
sizeof (disk_header),
fstr, ch, ch, iosz, ch, iosz,
ch, header);