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
This commit is contained in:
Navdeep Parhar 2017-10-07 01:20:30 +00:00
parent 709939a7b7
commit 313a64359d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=324379

View File

@ -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);
}