From patchwork Fri Dec 7 06:23:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10717507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A2E2814E2 for ; Fri, 7 Dec 2018 06:23:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D0012EB3B for ; Fri, 7 Dec 2018 06:23:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E5AF2EB67; Fri, 7 Dec 2018 06:23:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C74682EB3B for ; Fri, 7 Dec 2018 06:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725985AbeLGGXi (ORCPT ); Fri, 7 Dec 2018 01:23:38 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:41088 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbeLGGXi (ORCPT ); Fri, 7 Dec 2018 01:23:38 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wB76IwSw149215; Fri, 7 Dec 2018 06:23:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=FwPRgh+fHgPQoYOrKPR+70hjf00HoHLhgIpSh6YBQTo=; b=0bHezb7paEN3PhwGT7TAXINBJS1RMBj6hfLhmbX+UAGnZmY3Fce9tdNBH+VPdRNaNjCC zw15GLpwW41wRTJuhYGbXr+RZ7JtkC9/izOnHNGelH2k74pHjklUg9/M8LCwuGJz2bTB Qq/rJcxV2vnlYz3x482UVDs7Jf2Lqe+dG5Zuljm401I+KhrqKpg6YTieV8/OMrEGP5Sd VEIYhL0E+9AmRRj3bD5qpuX6yFolUQKmPxMWjO1269I9cMXwO+ddDn2zgsl2niLDum8+ TsTlynEx3e8rsm5RK8C8yk8JmQdlVLwC+cMrAh7xduMo51JWD+A1QAzh5C1YpTfng0K3 aA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2p3hquc4n9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 Dec 2018 06:23:36 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wB76NYmc016505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 7 Dec 2018 06:23:35 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wB76NYZF025786; Fri, 7 Dec 2018 06:23:34 GMT Received: from localhost (/10.159.153.113) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 06 Dec 2018 22:23:34 -0800 Subject: [PATCH 02/12] fsstress: check system call return values From: "Darrick J. Wong" To: guaneryu@gmail.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Allison Henderson , fstests@vger.kernel.org Date: Thu, 06 Dec 2018 22:23:32 -0800 Message-ID: <154416381284.15344.6497982978936980932.stgit@magnolia> In-Reply-To: <154416379233.15344.4377231692638417530.stgit@magnolia> References: <154416379233.15344.4377231692638417530.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9099 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=775 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812070054 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Check the return values of various system calls and blow up if something went wrong. Signed-off-by: Darrick J. Wong Reviewed-By: Allison Henderson --- ltp/fsstress.c | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 8d0734fc..af5d125f 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -733,7 +733,7 @@ append_pathname(pathname_t *name, char *str) /* attempting to append to a dir a zero length path */ if (len && *str == '/' && name->len == 0) { fprintf(stderr, "fsstress: append_pathname failure\n"); - chdir(homedir); + assert(chdir(homedir) == 0); abort(); /* NOTREACHED */ } @@ -765,7 +765,7 @@ attr_list_path(pathname_t *name, separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = attr_list_path(&newname, buffer, buffersize, flags, cursor); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -784,7 +784,7 @@ attr_remove_path(pathname_t *name, const char *attrname, int flags) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = attr_remove_path(&newname, attrname, flags); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -805,7 +805,7 @@ attr_set_path(pathname_t *name, const char *attrname, const char *attrvalue, if (chdir(buf) == 0) { rval = attr_set_path(&newname, attrname, attrvalue, valuelength, flags); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -819,7 +819,7 @@ check_cwd(void) if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino) return; - chdir(homedir); + assert(chdir(homedir) == 0); fprintf(stderr, "fsstress: check_cwd failure\n"); abort(); /* NOTREACHED */ @@ -858,7 +858,7 @@ creat_path(pathname_t *name, mode_t mode) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = creat_path(&newname, mode); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -996,11 +996,15 @@ doproc(void) } } errout: - chdir(".."); + assert(chdir("..") == 0); free(homedir); if (cleanup) { + int ret; + sprintf(cmd, "rm -rf %s", buf); - system(cmd); + ret = system(cmd); + if (ret != 0) + perror("cleaning up"); cleanup_flist(); } } @@ -1216,7 +1220,7 @@ lchown_path(pathname_t *name, uid_t owner, gid_t group) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = lchown_path(&newname, owner, group); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1240,7 +1244,7 @@ link_path(pathname_t *name1, pathname_t *name2) if (strcmp(buf1, buf2) == 0) { if (chdir(buf1) == 0) { rval = link_path(&newname1, &newname2); - chdir(".."); + assert(chdir("..") == 0); } } else { if (strcmp(buf1, "..") == 0) @@ -1260,7 +1264,7 @@ link_path(pathname_t *name1, pathname_t *name2) append_pathname(&newname2, name2->path); if (chdir(buf1) == 0) { rval = link_path(&newname1, &newname2); - chdir(".."); + assert(chdir("..") == 0); } } else { free_pathname(&newname1); @@ -1268,7 +1272,7 @@ link_path(pathname_t *name1, pathname_t *name2) append_pathname(&newname1, name1->path); if (chdir(buf2) == 0) { rval = link_path(&newname1, &newname2); - chdir(".."); + assert(chdir("..") == 0); } } } @@ -1290,7 +1294,7 @@ lstat64_path(pathname_t *name, struct stat64 *sbuf) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = lstat64_path(&newname, sbuf); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1326,7 +1330,7 @@ mkdir_path(pathname_t *name, mode_t mode) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = mkdir_path(&newname, mode); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1345,7 +1349,7 @@ mknod_path(pathname_t *name, mode_t mode, dev_t dev) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = mknod_path(&newname, mode, dev); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1386,7 +1390,7 @@ open_path(pathname_t *name, int oflag) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = open_path(&newname, oflag); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1405,7 +1409,7 @@ opendir_path(pathname_t *name) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = opendir_path(&newname); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1446,7 +1450,7 @@ readlink_path(pathname_t *name, char *lbuf, size_t lbufsiz) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = readlink_path(&newname, lbuf, lbufsiz); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1470,7 +1474,7 @@ rename_path(pathname_t *name1, pathname_t *name2) if (strcmp(buf1, buf2) == 0) { if (chdir(buf1) == 0) { rval = rename_path(&newname1, &newname2); - chdir(".."); + assert(chdir("..") == 0); } } else { if (strcmp(buf1, "..") == 0) @@ -1490,7 +1494,7 @@ rename_path(pathname_t *name1, pathname_t *name2) append_pathname(&newname2, name2->path); if (chdir(buf1) == 0) { rval = rename_path(&newname1, &newname2); - chdir(".."); + assert(chdir("..") == 0); } } else { free_pathname(&newname1); @@ -1498,7 +1502,7 @@ rename_path(pathname_t *name1, pathname_t *name2) append_pathname(&newname1, name1->path); if (chdir(buf2) == 0) { rval = rename_path(&newname1, &newname2); - chdir(".."); + assert(chdir("..") == 0); } } } @@ -1520,7 +1524,7 @@ rmdir_path(pathname_t *name) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = rmdir_path(&newname); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1603,7 +1607,7 @@ stat64_path(pathname_t *name, struct stat64 *sbuf) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = stat64_path(&newname, sbuf); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1627,7 +1631,7 @@ symlink_path(const char *name1, pathname_t *name) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = symlink_path(name1, &newname); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1646,7 +1650,7 @@ truncate64_path(pathname_t *name, off64_t length) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = truncate64_path(&newname, length); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval; @@ -1665,7 +1669,7 @@ unlink_path(pathname_t *name) separate_pathname(name, buf, &newname); if (chdir(buf) == 0) { rval = unlink_path(&newname); - chdir(".."); + assert(chdir("..") == 0); } free_pathname(&newname); return rval;