svn commit: r303108 - in user/pho/stress2/testcases: lockf lockf2
Peter Holm
pho at FreeBSD.org
Wed Jul 20 18:27:43 UTC 2016
Author: pho
Date: Wed Jul 20 18:27:42 2016
New Revision: 303108
URL: https://svnweb.freebsd.org/changeset/base/303108
Log:
Handle EINTR + style fixes.
Sponsored by: EMC / Isilon Storage Division
Modified:
user/pho/stress2/testcases/lockf/lockf.c
user/pho/stress2/testcases/lockf2/lockf2.c
Modified: user/pho/stress2/testcases/lockf/lockf.c
==============================================================================
--- user/pho/stress2/testcases/lockf/lockf.c Wed Jul 20 18:26:48 2016 (r303107)
+++ user/pho/stress2/testcases/lockf/lockf.c Wed Jul 20 18:27:42 2016 (r303108)
@@ -30,28 +30,32 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
#include <sys/param.h>
#include <sys/wait.h>
-#include <signal.h>
-#include <errno.h>
+
#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
#include <stress.h>
-char file[128];
+pid_t pid;
int fd;
int freespace;
-pid_t pid;
+char file[128];
int
get(void) {
- int sem;
- if (lockf(fd, F_LOCK, 0) == -1)
+ int r, sem;
+
+ do {
+ r = lockf(fd, F_LOCK, 0);
+ } while (r == -1 && errno == EINTR);
+ if (r == -1)
err(1, "lockf(%s, F_LOCK)", file);
if (read(fd, &sem, sizeof(sem)) != sizeof(sem))
err(1, "get: read(%d)", fd);
@@ -64,8 +68,12 @@ get(void) {
void
incr(void) {
- int sem;
- if (lockf(fd, F_LOCK, 0) == -1)
+ int r, sem;
+
+ do {
+ r = lockf(fd, F_LOCK, 0);
+ } while (r == -1 && errno == EINTR);
+ if (r == -1)
err(1, "lockf(%s, F_LOCK)", file);
if (read(fd, &sem, sizeof(sem)) != sizeof(sem))
err(1, "incr: read(%d)", fd);
Modified: user/pho/stress2/testcases/lockf2/lockf2.c
==============================================================================
--- user/pho/stress2/testcases/lockf2/lockf2.c Wed Jul 20 18:26:48 2016 (r303107)
+++ user/pho/stress2/testcases/lockf2/lockf2.c Wed Jul 20 18:27:42 2016 (r303108)
@@ -36,15 +36,15 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/types.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/param.h>
#include <strings.h>
-#include <errno.h>
-#include <err.h>
+#include <unistd.h>
#include <stress.h>
@@ -103,9 +103,9 @@ cleanup(void)
int
test(void)
{
- int i;
off_t pos;
off_t size;
+ int i, r;
if ((fd = open(file, O_RDWR, 0600)) == -1)
err(1, "open(%s)", file);
@@ -117,7 +117,10 @@ test(void)
size = random_int(1, 1024 * 1024 - pos);
if (size > 64)
size = 64;
- if (lockf(fd, F_LOCK, size) == -1)
+ do {
+ r = lockf(fd, F_LOCK, size);
+ } while (r == -1 && errno == EINTR);
+ if (r == -1)
err(1, "lockf(%s, F_LOCK)", file);
size = random_int(1, size);
if (lockf(fd, F_ULOCK, size) == -1)
More information about the svn-src-user
mailing list