All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: guaneryu@gmail.com, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org
Subject: [PATCH 02/12] fsstress: check system call return values
Date: Thu, 22 Nov 2018 09:58:40 -0800	[thread overview]
Message-ID: <154290952081.1218.5326269464784776136.stgit@magnolia> (raw)
In-Reply-To: <154290950237.1218.9937108728673485814.stgit@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

Check the return values of various system calls and blow up if something
went wrong.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 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;

  parent reply	other threads:[~2018-11-23  4:39 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-22 17:58 [PATCH v3 00/12] xfstests: add copy/dedupe/clone to fsx/fsstress Darrick J. Wong
2018-11-22 17:58 ` [PATCH 01/12] fsstress: fix compiler warnings Darrick J. Wong
2018-11-24 18:22   ` Allison Henderson
2018-11-22 17:58 ` Darrick J. Wong [this message]
2018-11-24 18:22   ` [PATCH 02/12] fsstress: check system call return values Allison Henderson
2018-11-22 17:58 ` [PATCH 03/12] fsx: shut up compiler warnings Darrick J. Wong
2018-11-24 18:23   ` Allison Henderson
2018-11-22 17:58 ` [PATCH 04/12] fsx: always check buffer after each operation Darrick J. Wong
2018-11-24 18:24   ` Allison Henderson
2018-11-22 17:58 ` [PATCH 05/12] fsx: use an enum to define the operation commands Darrick J. Wong
2018-11-24 18:23   ` Allison Henderson
2018-11-22 17:59 ` [PATCH 06/12] fsx: add five-argument logging function Darrick J. Wong
2018-11-24 18:23   ` Allison Henderson
2018-11-22 17:59 ` [PATCH 07/12] fsx: add FICLONERANGE support Darrick J. Wong
2018-11-22 17:59 ` [PATCH 08/12] fsx: add FIDEDUPERANGE support Darrick J. Wong
2018-11-22 17:59 ` [PATCH 09/12] fsstress: add copy_file_range support Darrick J. Wong
2018-11-22 17:59 ` [PATCH 10/12] fsx: " Darrick J. Wong
2018-11-22 17:59 ` [PATCH 11/12] common/dump: disable copyrange Darrick J. Wong
2018-11-22 17:59 ` [PATCH 12/12] generic: long fsx soak tests Darrick J. Wong
2018-11-25 16:27   ` Eryu Guan
2018-11-26 20:50     ` Darrick J. Wong
2018-12-07  6:23 [PATCH v4 00/12] xfstests: add copy/dedupe/clone to fsx/fsstress Darrick J. Wong
2018-12-07  6:23 ` [PATCH 02/12] fsstress: check system call return values Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=154290952081.1218.5326269464784776136.stgit@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=fstests@vger.kernel.org \
    --cc=guaneryu@gmail.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.