From owner-svn-src-head@freebsd.org Sat Oct 7 01:20:31 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BBD62E2569C; Sat, 7 Oct 2017 01:20:31 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 89F7176F80; Sat, 7 Oct 2017 01:20:31 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v971KU9o069766; Sat, 7 Oct 2017 01:20:30 GMT (envelope-from np@FreeBSD.org) Received: (from np@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v971KUSU069765; Sat, 7 Oct 2017 01:20:30 GMT (envelope-from np@FreeBSD.org) Message-Id: <201710070120.v971KUSU069765@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: np set sender to np@FreeBSD.org using -f From: Navdeep Parhar Date: Sat, 7 Oct 2017 01:20:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324379 - head/usr.sbin/cxgbetool X-SVN-Group: head X-SVN-Commit-Author: np X-SVN-Commit-Paths: head/usr.sbin/cxgbetool X-SVN-Commit-Revision: 324379 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Oct 2017 01:20:31 -0000 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); }