1 /* $Id: tstlockscope.c,v 1.2 2007-05-16 12:31:17 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 /** \file tstlockscope.c
24 \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 * indent-tabs-mode: nil
103 * vim: shiftwidth=4 tabstop=8 expandtab