]> git.ozlabs.org Git - ccan/commitdiff
failtest: override getpid() as well.
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 20 May 2011 06:20:58 +0000 (15:50 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 20 May 2011 06:20:58 +0000 (15:50 +0930)
TDB2 tracks locks using getpid(), and gets upset when we fork behind
its back.

ccan/failtest/failtest.c
ccan/failtest/failtest_override.h
ccan/failtest/failtest_proto.h

index 061d6e9e3fc911c12c88fe7b122a417287441133..e9f837364a84b55ed9853a287ab69884b5f92c0a 100644 (file)
@@ -58,6 +58,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. */
@@ -1024,10 +1026,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=");
index cfc180022643e18ae5ed50f537db550ba79caebc..dfcc62e0dd5f4ff5630cc727230a1361ce09ca0c 100644 (file)
 #undef fcntl
 #define fcntl(fd, ...) failtest_fcntl((fd), __FILE__, __LINE__, __VA_ARGS__)
 
+/* Replacement of getpid (since failtest will fork). */
+#undef getpid
+#define getpid() failtest_getpid(__FILE__, __LINE__)
+
 #include <ccan/failtest/failtest_proto.h>
 
 #endif /* CCAN_FAILTEST_OVERRIDE_H */
index 89a1e77f6e2fd9e024d3ff1831d4bf898ecca847..18576df62dd7e72852de19da0887a265fab7c2fb 100644 (file)
@@ -22,4 +22,5 @@ ssize_t failtest_pwrite(int fd, const void *buf, size_t count, off_t offset,
                        const char *file, unsigned line);
 int failtest_close(int fd, const char *file, unsigned line);
 int failtest_fcntl(int fd, const char *file, unsigned line, int cmd, ...);
+pid_t failtest_getpid(const char *file, unsigned line);
 #endif /* CCAN_FAILTEST_PROTO_H */