file-lock.c revision 9e86ad9eb313004cd4c8b5427daeb4c241b57af6
/*
file-lock.c - Simple way to lock whole file descriptor
Copyright (c) 2002 Timo Sirainen
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "lib.h"
#include "file-lock.h"
#include <signal.h>
{
/* we need fcntl() to stop with EINTR */
i_fatal("kill(): %m");
}
{
return 0;
return -1;
if (got_alarm) {
return 0;
}
}
return 1;
}
{
}
{
#ifdef HAVE_SIGACTION
#endif
int ret;
#ifdef HAVE_SIGACTION
i_fatal("sigemptyset(): %m");
i_fatal("sigaction(): %m");
}
#else
/* at least Linux blocks raise(SIGHUP) inside SIGALRM
handler if it's added with signal().. sigaction() should
be pretty much everywhere though, so this code is pretty
useless. */
#endif
}
alarm(0);
#ifdef HAVE_SIGACTION
i_fatal("sigaction(): %m");
}
#else
#endif
}
return ret;
}