X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib_internal%2Futil-lockfile.c;fp=lib_internal%2Futil-lockfile.c;h=0000000000000000000000000000000000000000;hb=db5ef3f969fc6ad34aeb5903e44d0049b2e50791;hp=963c3b8ba880c749a9db9a84b37a4b9988f1a167;hpb=95e2774070e989fe9cf9f48dae5fa054e55e2a3e;p=util-vserver.git diff --git a/lib_internal/util-lockfile.c b/lib_internal/util-lockfile.c deleted file mode 100644 index 963c3b8..0000000 --- a/lib_internal/util-lockfile.c +++ /dev/null @@ -1,86 +0,0 @@ -// $Id: util-lockfile.c 1616 2004-07-02 23:34:52Z ensc $ --*- c -*-- - -// Copyright (C) 2004 Enrico Scholz -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "util-lockfile.h" -#include "errinfo.h" - -#include -#include -#include -#include -#include -#include - -static volatile sig_atomic_t alarm_flag = 0; - -static void -alarmFunc(int UNUSED sig) -{ - alarm_flag = 1; - signal(SIGALRM, alarmFunc); -} - -bool -lockfile(int *fd, char const *filename, int op, long timeout, - struct ErrorInformation *err) -{ - char const *errstr = 0; - void (*old_sighandler)(int) = 0; - - errstr = "open()"; - *fd = open(filename, O_CREAT|O_RDONLY|O_NOFOLLOW|O_NONBLOCK, 0644); - if (*fd==-1) goto err; - - if (timeout!=-1) { - errstr = "siginterrupt()"; - if (siginterrupt(SIGALRM, 1)==-1) goto err; - - errstr = "signal()"; - old_sighandler = signal(SIGALRM, alarmFunc); - if (old_sighandler==SIG_ERR) goto err; - - alarm(timeout); - } - - errstr = "flock()"; - while (flock(*fd, op)==-1) { - if ((errno!=EINTR && errno!=EINTR) || alarm_flag) goto err; - } - - if (timeout!=-1 && old_sighandler!=0) - signal(SIGALRM, old_sighandler); - - errstr = "fcntl()"; - if (fcntl(*fd, F_SETFD, FD_CLOEXEC)==-1) goto err; - - return true; - - err: - if (err) { - err->pos = errstr; - err->id = errno; - } - if (timeout!=-1 && old_sighandler!=0) - signal(SIGALRM, old_sighandler); - if (*fd!=-1) close(*fd); - return false; -}