From patchwork Sat Oct 14 07:07:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murphy Zhou X-Patchwork-Id: 10006265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 20F436037E for ; Sat, 14 Oct 2017 07:07:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEA5B291A9 for ; Sat, 14 Oct 2017 07:07:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1AE7291B8; Sat, 14 Oct 2017 07:07:38 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 6B47B291A9 for ; Sat, 14 Oct 2017 07:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750778AbdJNHHh (ORCPT ); Sat, 14 Oct 2017 03:07:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42534 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750772AbdJNHHg (ORCPT ); Sat, 14 Oct 2017 03:07:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A71E23680C for ; Sat, 14 Oct 2017 07:07:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A71E23680C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=xzhou@redhat.com Received: from localhost (dhcp-12-130.nay.redhat.com [10.66.12.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B1BE4F9FA; Sat, 14 Oct 2017 07:07:35 +0000 (UTC) From: Xiong Zhou To: fstests@vger.kernel.org Cc: Xiong Zhou Subject: [PATCH] ltp/fsstress: check mkdir(2) return value Date: Sat, 14 Oct 2017 15:07:17 +0800 Message-Id: <1507964837-10820-1-git-send-email-xzhou@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 14 Oct 2017 07:07:36 +0000 (UTC) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If mkdir(2) fails, the following chdir(2) would fail either. Although dirname and error message are printed, we don't know which operation has failed. Like this: +/test2/fsstress.1582: No such file or directory This trivial fix will check the return value and print detail error info if fail. Signed-off-by: Xiong Zhou --- ltp/fsstress.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 96f48b1..1962d14 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -493,7 +493,11 @@ int main(int argc, char **argv) exit(1); } - (void)mkdir(dirname, 0777); + if (mkdir((const char *)dirname, 0777) < 0) { + fprintf(stderr, "mkdir %s failed: %s\n", dirname, + strerror(errno)); + exit(1); + } if (logname && logname[0] != '/') { if (getcwd(rpath, sizeof(rpath)) < 0){ perror("getcwd failed"); @@ -503,7 +507,8 @@ int main(int argc, char **argv) rpath[0] = '\0'; } if (chdir(dirname) < 0) { - perror(dirname); + fprintf(stderr, "chdir %s failed: %s\n", dirname, + strerror(errno)); exit(1); } if (logname) { @@ -959,7 +964,11 @@ doproc(void) dividend = (operations + execute_freq) / (execute_freq + 1); sprintf(buf, "p%x", procid); - (void)mkdir(buf, 0777); + if (mkdir((const char *)buf, 0777) < 0) { + fprintf(stderr, "mkdir %s failed: %s\n", buf, + strerror(errno)); + exit(1); + } if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) { perror(buf); _exit(1);