X-Git-Url: https://git.hcoop.net/hcoop/debian/courier-authlib.git/blobdiff_plain/426e783363e20f878a4df0131ac76e294cf0948c..64ff59baf3361c2591d52e52bdddabebfcd21e4c:/liblock/lockdaemon.c?ds=inline diff --git a/liblock/lockdaemon.c b/liblock/lockdaemon.c index 8f75f36..5ff83a1 100644 --- a/liblock/lockdaemon.c +++ b/liblock/lockdaemon.c @@ -1,5 +1,5 @@ /* -** Copyright 2000-2006 Double Precision, Inc. See COPYING for +** Copyright 2000-2007 Double Precision, Inc. See COPYING for ** distribution information. */ @@ -7,6 +7,7 @@ #include "liblock.h" #include #include +#include #include #include #include @@ -30,9 +31,31 @@ #include #endif +#ifndef OPEN_MAX +#ifdef HAVE_SYSCONF +#ifdef _SC_OPEN_MAX +#define OPEN_MAX (my_open_max()) + +static int my_open_max() +{ + long n=sysconf(_SC_OPEN_MAX); + + if (n == -1) + n=64; + return n; +} + +#endif +#endif +#endif + +#ifndef OPEN_MAX +#define OPEN_MAX 64 +#endif + #define exit(_a_) _exit(_a_) -static const char rcsid[]="$Id: lockdaemon.c,v 1.10 2006/05/28 15:29:52 mrsam Exp $"; +static const char rcsid[]="$Id: lockdaemon.c,v 1.13 2007/09/26 02:36:59 mrsam Exp $"; static int start1(const char *, int); @@ -145,12 +168,15 @@ int lockfd; lockfd=open(lockfile, O_RDWR|O_CREAT, 0600); } - if (lockfd < 0) + if (lockfd < 0 || dup2(lockfd, OPEN_MAX-1) != OPEN_MAX-1) { perror(lockfile); exit(1); } + close(lockfd); + lockfd=OPEN_MAX-1; + #ifdef FD_CLOEXEC if (fcntl(lockfd, F_SETFD, FD_CLOEXEC) < 0) {