]> git.ozlabs.org Git - ccan/blobdiff - ccan/failtest/failtest.c
various: add LICENSE comments.
[ccan] / ccan / failtest / failtest.c
index 851f2eabf043e4e3f8fa8c53cfe2056431a27220..d9a0849daf600d1518514df57b74c71be1b78709 100644 (file)
@@ -1,3 +1,4 @@
+/* Licensed under LGPL - see LICENSE file for details */
 #include "config.h"
 #include <stdarg.h>
 #include <string.h>
@@ -58,6 +59,8 @@ static pid_t lock_owner;
 static struct lock_info *locks = NULL;
 static unsigned int lock_num = 0;
 
+static pid_t orig_pid;
+
 static const char info_to_arg[] = "mceoxprwf";
 
 /* Dummy call used for failtest_undo wrappers. */
@@ -677,7 +680,7 @@ int failtest_open(const char *pathname,
        va_start(ap, line);
        call.flags = va_arg(ap, int);
        if (call.flags & O_CREAT) {
-               call.mode = va_arg(ap, mode_t);
+               call.mode = va_arg(ap, int);
                va_end(ap);
        }
        p = add_history(FAILTEST_OPEN, file, line, &call);
@@ -1024,10 +1027,19 @@ int failtest_fcntl(int fd, const char *file, unsigned line, int cmd, ...)
        return p->u.fcntl.ret;
 }
 
+pid_t failtest_getpid(const char *file, unsigned line)
+{
+       /* You must call failtest_init first! */
+       assert(orig_pid);
+       return orig_pid;
+}
+       
 void failtest_init(int argc, char *argv[])
 {
        unsigned int i;
 
+       orig_pid = getpid();
+               
        for (i = 1; i < argc; i++) {
                if (!strncmp(argv[i], "--failpath=", strlen("--failpath="))) {
                        failpath = argv[i] + strlen("--failpath=");
@@ -1042,6 +1054,11 @@ void failtest_init(int argc, char *argv[])
        gettimeofday(&start, NULL);
 }
 
+bool failtest_has_failed(void)
+{
+       return control_fd != -1;
+}
+
 void failtest_exit(int status)
 {
        if (failtest_exit_check) {