1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /** \file tstlockscope.c
21 \brief tests scope of fcntl locks.. Either "process" or "thread"
37 const char *scope = "unknown";
39 static int file_lock(int fd, int type, int cmd)
43 area.l_whence = SEEK_SET;
44 area.l_len = area.l_start = 0L;
46 return fcntl(fd, cmd, &area);
49 void *run_func(void *arg)
51 if (file_lock(fd, F_WRLCK, F_SETLK) == -1)
60 pthread_t child_thread;
62 fd = open("my.LCK", (O_CREAT|O_RDWR), 0666);
67 yaz_log(YLOG_FATAL|YLOG_ERRNO, "open");
71 r = file_lock(fd, F_WRLCK, F_SETLKW);
75 yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcnt");
80 pthread_create(&child_thread, 0 /* attr */, run_func, 0);
81 pthread_join(child_thread, 0);
83 yaz_log(YLOG_LOG, "fcntl lock scope: %s", scope);
86 int main(int argc, char **argv)
88 YAZ_CHECK_INIT(argc, argv);
98 * c-file-style: "Stroustrup"
99 * indent-tabs-mode: nil
101 * vim: shiftwidth=4 tabstop=8 expandtab