Author: np
Date: Sat Oct  7 01:20:30 2017
New Revision: 324379
URL: https://svnweb.freebsd.org/changeset/base/324379

Log:
  cxgbetool(8): Do not create a large file devoid of useful content when
  the dumpstate ioctl fails.  Make the file world-readable while here.
  
  MFC after:    2 weeks
  Sponsored by: Chelsio Communications

Modified:
  head/usr.sbin/cxgbetool/cxgbetool.c

Modified: head/usr.sbin/cxgbetool/cxgbetool.c
==============================================================================
--- head/usr.sbin/cxgbetool/cxgbetool.c Fri Oct  6 23:05:55 2017        
(r324378)
+++ head/usr.sbin/cxgbetool/cxgbetool.c Sat Oct  7 01:20:30 2017        
(r324379)
@@ -1896,13 +1896,6 @@ dumpstate(int argc, const char *argv[])
                return (EINVAL);
        }
 
-       fd = open(fname, O_CREAT | O_TRUNC | O_EXCL | O_WRONLY,
-           S_IRUSR | S_IRGRP);
-       if (fd < 0) {
-               warn("open(%s)", fname);
-               return (errno);
-       }
-
        dump.wr_flash = 0;
        memset(&dump.bitmap, 0xff, sizeof(dump.bitmap));
        dump.len = 8 * 1024 * 1024;
@@ -1913,9 +1906,20 @@ dumpstate(int argc, const char *argv[])
        }
 
        rc = doit(CHELSIO_T4_CUDBG_DUMP, &dump);
+       if (rc != 0)
+               goto done;
+
+       fd = open(fname, O_CREAT | O_TRUNC | O_EXCL | O_WRONLY,
+           S_IRUSR | S_IRGRP | S_IROTH);
+       if (fd < 0) {
+               warn("open(%s)", fname);
+               rc = errno;
+               goto done;
+       }
        write(fd, dump.data, dump.len);
-       free(dump.data);
        close(fd);
+done:
+       free(dump.data);
        return (rc);
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to