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>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/stat/iostat/iostat.c
          +++ new/usr/src/cmd/stat/iostat/iostat.c
↓ open down ↓ 21 lines elided ↑ open up ↑
  22   22  /*
  23   23   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   *
  26   26   * rewritten from UCB 4.13 83/09/25
  27   27   * rewritten from SunOS 4.1 SID 1.18 89/10/06
  28   28   */
  29   29  /*
  30   30   * Copyright (c) 2012 by Delphix. All rights reserved.
  31   31   * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
       32 + * Copyright 2016 James S. Blachly, MD. All rights reserved.
  32   33   */
  33   34  
  34   35  #include <stdio.h>
  35   36  #include <stdlib.h>
  36   37  #include <stdarg.h>
  37   38  #include <ctype.h>
  38   39  #include <unistd.h>
  39   40  #include <memory.h>
  40   41  #include <errno.h>
  41   42  #include <string.h>
↓ open down ↓ 1221 lines elided ↑ open up ↑
1263 1264  
1264 1265  /*
1265 1266   * Driver for doing the extended header formatting. Will produce
1266 1267   * the function stack needed to output an extended header based
1267 1268   * on the options selected.
1268 1269   */
1269 1270  
1270 1271  void
1271 1272  do_format(void)
1272 1273  {
1273      -        char    header[SMALL_SCRATCH_BUFLEN];
     1274 +        char    header[SMALL_SCRATCH_BUFLEN] = {0};
1274 1275          char    ch;
1275 1276          char    iosz;
1276 1277          const char    *fstr;
1277 1278  
1278 1279          disk_header[0] = 0;
1279 1280          ch = (do_interval ? 'i' : 's');
1280 1281          iosz = (do_megabytes ? 'M' : 'k');
1281 1282          if (do_disk & DISK_ERRORS) {
1282 1283                  if (do_raw == 0) {
1283 1284                          (void) sprintf(header, "s/w h/w trn tot ");
1284 1285                  } else
1285 1286                          (void) sprintf(header, "s/w,h/w,trn,tot");
1286      -        } else
1287      -                *header = NULL;
     1287 +        }
1288 1288          switch (do_disk & DISK_IO_MASK) {
1289 1289                  case DISK_OLD:
1290 1290                          if (do_raw == 0)
1291 1291                                  fstr = "%cp%c tp%c serv  ";
1292 1292                          else
1293 1293                                  fstr = "%cp%c,tp%c,serv";
1294 1294                          (void) snprintf(disk_header, sizeof (disk_header),
1295 1295                              fstr, iosz, ch, ch);
1296 1296                          break;
1297 1297                  case DISK_NEW:
↓ open down ↓ 16 lines elided ↑ open up ↑
1314 1314                                              "%cr/%c   %cw/%c wait actv  "
1315 1315                                              "svc_t  %%%%w  %%%%b %s",
1316 1316                                              iodevs_nl, iodevs_nl, "device",
1317 1317                                              ch, ch, iosz, ch, iosz, ch, header);
1318 1318                                  } else {
1319 1319                                          /* with -r option */
1320 1320                                          (void) snprintf(disk_header,
1321 1321                                              sizeof (disk_header),
1322 1322                                              "device,r/%c,w/%c,%cr/%c,%cw/%c,"
1323 1323                                              "wait,actv,svc_t,%%%%w,"
1324      -                                            "%%%%b,%s",
1325      -                                            ch, ch, iosz, ch, iosz, ch, header);
     1324 +                                            "%%%%b%s%s",
     1325 +                                            ch, ch, iosz, ch, iosz, ch,
     1326 +                                            *header == '\0' ? "" : ",",
     1327 +                                            header);
     1328 +                                        /*
     1329 +                                         * if no -e flag, header == '\0...'
     1330 +                                         * Ternary operator above is to prevent
     1331 +                                         * trailing comma in full disk_header
     1332 +                                         */
1326 1333                                  }
1327 1334                          } else {
1328 1335                                  /* with -n option */
1329 1336                                  if (do_raw == 0) {
1330 1337                                          fstr = "    r/%c    w/%c   %cr/%c   "
1331 1338                                              "%cw/%c wait actv wsvc_t asvc_t  "
1332 1339                                              "%%%%w  %%%%b %sdevice";
1333 1340                                  } else {
1334 1341                                          fstr = "r/%c,w/%c,%cr/%c,%cw/%c,"
1335 1342                                              "wait,actv,wsvc_t,asvc_t,"
1336 1343                                              "%%%%w,%%%%b,%sdevice";
     1344 +                                        /*
     1345 +                                         * if -rnxe, "tot" (from -e) and
     1346 +                                         * "device" are run together
     1347 +                                         * due to lack of trailing comma
     1348 +                                         * in 'header'. However, adding
     1349 +                                         * trailing comma to header at
     1350 +                                         * its definition leads to prob-
     1351 +                                         * lems elsewhere so it's added
     1352 +                                         * here in this edge case -rnxe
     1353 +                                         */
     1354 +                                        if (*header != '\0')
     1355 +                                                (void) strcat(header, ",");
1337 1356                                  }
1338 1357                                  (void) snprintf(disk_header,
1339 1358                                      sizeof (disk_header),
1340 1359                                      fstr, ch, ch, iosz, ch, iosz,
1341 1360                                      ch, header);
1342 1361                          }
1343 1362                          break;
1344 1363                  default:
1345 1364                          break;
1346 1365          }
↓ open down ↓ 406 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX