1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 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"
40 const char *scope = "unknown";
42 static int file_lock(int fd, int type, int cmd)
46 area.l_whence = SEEK_SET;
47 area.l_len = area.l_start = 0L;
49 return fcntl(fd, cmd, &area);
52 void *run_func(void *arg)
54 if (file_lock(fd, F_WRLCK, F_SETLK) == -1)
63 pthread_t child_thread;
65 fd = open("my.LCK", (O_CREAT|O_RDWR), 0666);
70 yaz_log(YLOG_FATAL|YLOG_ERRNO, "open");
74 r = file_lock(fd, F_WRLCK, F_SETLKW);
78 yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcnt");
83 pthread_create(&child_thread, 0 /* attr */, run_func, 0);
84 pthread_join(child_thread, 0);
86 yaz_log(YLOG_LOG, "fcntl lock scope: %s", scope);
89 int main(int argc, char **argv)
91 YAZ_CHECK_INIT(argc, argv);
101 * c-file-style: "Stroustrup"
102 * indent-tabs-mode: nil
104 * vim: shiftwidth=4 tabstop=8 expandtab