Print this page
15291 zfs-tests errno flaws exposed by 15220

@@ -22,10 +22,14 @@
 /*
  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
+/*
+ * Copyright 2022 MNX Cloud, Inc.
+ */
+
 #include "../file_common.h"
 #include <libgen.h>
 
 static unsigned char bigbuffer[BIGBUFFERSIZE];
 

@@ -57,10 +61,11 @@
         char            *operation = NULL;
         offset_t        noffset, offset = 0;
         int             verbose = 0;
         int             rsync = 0;
         int             wsync = 0;
+        int             exitcode;
 
         /*
          * Process Arguments
          */
         while ((c = getopt(argc, argv, "b:c:d:s:f:o:vwr")) != -1) {

@@ -164,19 +169,21 @@
         /*
          * Given an operation (create/overwrite/append), open the file
          * accordingly and perform a write of the appropriate type.
          */
         if ((bigfd = open(filename, oflag, 0666)) == -1) {
+                exitcode = errno;
                 (void) printf("open %s: failed [%s]%d. Aborting!\n", filename,
                     strerror(errno), errno);
-                exit(errno);
+                exit(exitcode);
         }
         noffset = llseek(bigfd, offset, SEEK_SET);
         if (noffset != offset) {
+                exitcode = errno;
                 (void) printf("llseek %s (%lld/%lld) failed [%s]%d.Aborting!\n",
                     filename, offset, noffset, strerror(errno), errno);
-                exit(errno);
+                exit(exitcode);
         }
 
         if (verbose) {
                 (void) printf("%s: block_size = %d, write_count = %d, "
                     "offset = %lld, data = %s%d\n", filename, block_size,

@@ -187,15 +194,16 @@
 
         for (i = 0; i < write_count; i++) {
                 ssize_t n;
 
                 if ((n = write(bigfd, &bigbuffer, block_size)) == -1) {
+                        exitcode = errno;
                         (void) printf("write failed (%ld), good_writes = %lld, "
                             "error: %s[%d]\n", (long)n, good_writes,
                             strerror(errno),
                             errno);
-                        exit(errno);
+                        exit(exitcode);
                 }
                 good_writes++;
         }
 
         if (verbose) {