From 371a31d946c1055e8b7f7d9cec2b7f617206aeaf Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 20 May 2011 15:50:58 +0930 Subject: [PATCH] failtest: override getpid() as well. TDB2 tracks locks using getpid(), and gets upset when we fork behind its back. --- ccan/failtest/failtest.c | 11 +++++++++++ ccan/failtest/failtest_override.h | 4 ++++ ccan/failtest/failtest_proto.h | 1 + 3 files changed, 16 insertions(+) diff --git a/ccan/failtest/failtest.c b/ccan/failtest/failtest.c index 061d6e9e..e9f83736 100644 --- a/ccan/failtest/failtest.c +++ b/ccan/failtest/failtest.c @@ -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="); diff --git a/ccan/failtest/failtest_override.h b/ccan/failtest/failtest_override.h index cfc18002..dfcc62e0 100644 --- a/ccan/failtest/failtest_override.h +++ b/ccan/failtest/failtest_override.h @@ -58,6 +58,10 @@ #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 #endif /* CCAN_FAILTEST_OVERRIDE_H */ diff --git a/ccan/failtest/failtest_proto.h b/ccan/failtest/failtest_proto.h index 89a1e77f..18576df6 100644 --- a/ccan/failtest/failtest_proto.h +++ b/ccan/failtest/failtest_proto.h @@ -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 */ -- 2.39.2