]> git.ozlabs.org Git - ccan/blobdiff - ccan/failtest/failtest.c
failtest: fix locking code.
[ccan] / ccan / failtest / failtest.c
index 77aea9a7de6e185226f07a63b7ecb47dadf3a93b..e2e6c64fec64d188fed1b92184fbf64ad9951fd1 100644 (file)
@@ -219,7 +219,7 @@ static void trace_str(const char *str)
 {
        ssize_t ret;
 
-       while ((ret = write(tracefd, str, strlen(str))) <= 0) {
+       while ((ret = write(tracefd, str, strlen(str))) > 0) {
                str += ret;
                if (!*str)
                        return;
@@ -983,7 +983,6 @@ int failtest_fcntl(int fd, const char *file, unsigned line, int cmd, ...)
        }
 
        p = add_history(FAILTEST_FCNTL, file, line, &call);
-       get_locks();
 
        if (should_fail(p)) {
                p->u.fcntl.ret = -1;
@@ -992,6 +991,7 @@ int failtest_fcntl(int fd, const char *file, unsigned line, int cmd, ...)
                else
                        p->error = EDEADLK;
        } else {
+               get_locks();
                p->u.fcntl.ret = fcntl(p->u.fcntl.fd, p->u.fcntl.cmd,
                                       &p->u.fcntl.arg.fl);
                if (p->u.fcntl.ret == -1)