Fix bug #8974 - Kernel oplocks are broken when uid(file) != uid(process).
[samba.git] / source3 / smbd / oplock_linux.c
index c60c74517717da2eea9ae4d7bf007a99734094fa..ff5d5961b7b9dc18f1b89c0672d7dc06efb7122a 100644 (file)
@@ -74,9 +74,22 @@ int linux_setlease(int fd, int leasetype)
 {
        int ret;
 
+       /* First set the signal handler. */
+       if (linux_set_lease_sighandler(fd) == -1) {
+               return -1;
+       }
        ret = fcntl(fd, F_SETLEASE, leasetype);
        if (ret == -1 && errno == EACCES) {
                set_effective_capability(LEASE_CAPABILITY);
+               /*
+                * Bug 8974 - work around Linux kernel bug
+                * https://bugzilla.kernel.org/show_bug.cgi?id=43336.
+                * "fcntl(F_SETLEASE) resets signal number when
+                *  called multiple times"
+                */
+               if (linux_set_lease_sighandler(fd) == -1) {
+                       return -1;
+               }
                ret = fcntl(fd, F_SETLEASE, leasetype);
        }