Number of open files error
Andy Polyakov
appro at fy.chalmers.se
Sun Aug 15 14:06:49 GMT 1999
Hi, everybody!
> > > [1999/08/12 14:29:22, 1] smbd/files.c:file_init(216)
> > > file_init: Information only: requested 10000 open files, 246 are
> > > available.
> >
> > ... on a Solaris 2.51-machine (sparc).
Speaking of which...
>
> It's just telling you how many open files each smbd
> will be able to have, in case you have problems and
> need to increase it.
^^^^^^^^ There is a flaw in Solaris stdio. It was inherited
all the way from earliest SunOS (and BSD?) releases and was considered
by Sun as a feature, not bug ever since. For more details examine
attached patch (it's 2.0.4b based, but the problem is present and ought
to be fixed in all versions including 2.1.0-prealpha). The catch is that
some libc functions may "secretly" call stdio and that's why you have to
play this (or similar:-) trick in order to be on the safe side...
Cheers. Andy.
----------------------------------------------------------------------------
*** ./source/lib/system.c.orig Tue May 18 17:45:37 1999
--- ./source/lib/system.c Mon May 24 20:04:24 1999
***************
*** 268,273 ****
--- 268,295 ----
#endif
}
+ #if defined(SUNOS4) || (defined(SUNOS5) && !defined(__sparcv9))
+ /*
+ * Under SunOS/32 the member of FILE structure that keeps the UNIX
file
+ * descriptor is only 8 bits wide:-( This means that stdio will fail
+ * *miserably* if first 256 file descriptors are exhausted by calls to
+ * open(2) and creat(2). In order to avoid this let's try to shuffle
file
+ * descriptors obtained from mentioned system calls over when we start
+ * approaching the limit.
+ * Andy <appro at fy.chalmers.se>
+ */
+ #define KEEP_SOME_FD_FOR_STDIO 32
+ #define SHUFFLE_OVER_256(fd) \
+ if (fd < 256 && fd > 256-KEEP_SOME_FD_FOR_STDIO) { \
+ int fdd; \
+ if ((fdd = fcntl(fd,F_DUPFD,256)) >= 256) \
+ close(fd), fd = fdd; \
+ }
+ /*
+ * Other OS that would suffer from this is IRIX 5.x and earlier.
+ */
+ #endif
+
/*******************************************************************
A creat() wrapper that will deal with 64 bit filesizes.
********************************************************************/
***************
*** 274,288 ****
int sys_creat(const char *path, mode_t mode)
{
#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CREAT64)
! return creat64(path, mode);
#else
/*
* If creat64 isn't defined then ensure we call a potential open64.
* JRA.
*/
! return sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
#endif
}
/*******************************************************************
--- 296,315 ----
int sys_creat(const char *path, mode_t mode)
{
+ int fd;
#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CREAT64)
! fd = creat64(path, mode);
#else
/*
* If creat64 isn't defined then ensure we call a potential open64.
* JRA.
*/
! fd = sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
#endif
+ #ifdef SHUFFLE_OVER_256
+ SHUFFLE_OVER_256(fd);
+ #endif
+ return fd;
}
/*******************************************************************
***************
*** 291,301 ****
int sys_open(const char *path, int oflag, mode_t mode)
{
#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPEN64)
! return open64(path, oflag, mode);
#else
! return open(path, oflag, mode);
#endif
}
/*******************************************************************
--- 318,333 ----
int sys_open(const char *path, int oflag, mode_t mode)
{
+ int fd;
#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPEN64)
! fd = open64(path, oflag, mode);
#else
! fd = open(path, oflag, mode);
#endif
+ #ifdef SHUFFLE_OVER_256
+ SHUFFLE_OVER_256(fd);
+ #endif
+ return fd;
}
/*******************************************************************
More information about the samba-ntdom
mailing list