add some linux oplock test code
authorStefan Metzmacher <metze@samba.org>
Tue, 7 Jul 2009 15:29:05 +0000 (17:29 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 7 Jul 2009 15:29:05 +0000 (17:29 +0200)
metze

oplocks/linux_oplock1.c [new file with mode: 0644]

diff --git a/oplocks/linux_oplock1.c b/oplocks/linux_oplock1.c
new file mode 100644 (file)
index 0000000..06976e9
--- /dev/null
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#define __USE_GNU 1
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+
+static void sig_io(int sig)
+{
+       printf("got sigio\n");
+}
+
+int main(int argc, const char *argv[])
+{
+       int fd1;
+       int fd2;
+       int ret;
+
+       signal(SIGIO, sig_io);
+       signal(SIGIO, SIG_IGN);
+
+       errno = 0;
+       fd1 = open("tmp1.dat", O_CREAT|O_RDWR);
+//     fd1 = open("tmp1.dat", O_CREAT|O_RDONLY);
+       printf("fd1[%d]: %s\n", fd1, strerror(errno));
+
+       errno = 0;
+       ret = fcntl(fd1, F_SETLEASE, F_WRLCK);
+//     ret = fcntl(fd1, F_SETLEASE, F_RDLCK);
+       printf("ret[%d]: %s\n", ret, strerror(errno));
+
+       errno = 0;
+//     fd2 = open("tmp1.dat", O_CREAT|O_RDWR|O_NONBLOCK);
+//     fd2 = open("tmp1.dat", O_CREAT|O_RDONLY|O_NONBLOCK);
+//     printf("fd2[%d]: %s\n", fd2, strerror(errno));
+
+       errno = 0;
+/*     ret = flock(fd1, LOCK_EX);
+       ret = flock(fd1, LOCK_SH);
+       printf("ret[%d]: %s\n", ret, strerror(errno));
+*/
+
+       errno = 0;
+//     ret = fcntl(fd1, F_SETLEASE, F_WRLCK);
+//     ret = fcntl(fd1, F_SETLEASE, F_RDLCK);
+//     ret = fcntl(fd1, F_SETLEASE, F_UNLCK);
+//     printf("ret[%d]: %s\n", ret, strerror(errno));
+
+       errno = 0;
+//     fd2 = open("tmp1.dat", O_CREAT|O_RDWR|O_NONBLOCK);
+//     printf("fd2[%d]: %s\n", fd2, strerror(errno));
+
+       errno = 0;
+//     ret = fcntl(fd2, F_SETLEASE, F_WRLCK);
+//     ret = fcntl(fd2, F_SETLEASE, F_RDLCK);
+//     printf("ret[%d]: %s\n", ret, strerror(errno));
+
+
+       sleep(50000);
+
+       return 0;
+}