2 * gcc -ldl -D _GNU_SOURCE -shared -fPIC -o ignore_read_lock.so ignore_read_lock.c
18 #define MIN(a,b) (((a)<(b))?(a):(b))
21 int fcntl(int fd
, int cmd
, ...)
25 void* arg
= va_arg(vargs
, void*);
26 void* arg2
= va_arg(vargs
, void*);
28 struct flock
*lk
= arg
;
30 int (*orig_fcntl
)(int, int, ...) = dlsym(RTLD_NEXT
, __func__
);
31 int result
= orig_fcntl(fd
, cmd
, arg
, arg2
);
33 //warnx("cmd = %d l_type = %d result = %d errno = %d", cmd, lk->l_type, result, errno);
35 if(cmd
== F_SETLK64
&& lk
->l_type
== F_RDLCK
&& result
!= SUCCESS
&& errno
== EAGAIN
)
37 char linkpath
[PATH_MAX
];
39 sprintf(linkpath
, "/proc/self/fd/%d", fd
);
40 ssize_t sz
= readlink(linkpath
, path
, PATH_MAX
);
41 path
[MIN(sz
, PATH_MAX
-1)] = '\0';
42 warnx("%s: failed to acquire read lock, passing by", path
);