[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Porting uptimed: Usage of daemon and replacement of NOFILE
From: |
Guillem Jover |
Subject: |
Re: Porting uptimed: Usage of daemon and replacement of NOFILE |
Date: |
Tue, 1 Nov 2011 22:30:09 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Tue, 2011-11-01 at 15:57:53 +0100, Svante Signell wrote:
> Updated code snippet below, OK?
>
> void bg(void)
> {
> int i, fdmax;
[...]
> /* Close probably all file descriptors */
> #ifdef __USE_BSD
> if ((fdmax = getdtablesize()) == -1) exit(1);
> #else
> if ((fdmax = sysconf(_SC_OPEN_MAX)) == -1) exit(1);
> #endif
> for (i = 0; i<fdmax; i++)
> close(i);
[...]
> }
__USE_BSD is an internal macro used by glibc and should not be relied
on. Add a check to configure.ac instead, something like this:
AC_CHECK_FUNCS([getdtablesize])
and then use HAVE_GETDTABLESIZE. Also if there's no limit (-1) it's a
bit harsh to exit(1). I'd code this for example like:
,---
void bg(void)
{
int i, fdmax;
[...]
#ifdef HAVE_GETDTABLESIZE
fdmax = getdtablesize();
#else
fdmax = sysconf(_SC_OPEN_MAX);
#endif
if (fdmax <= 0)
fdmax = 3;
for (i = 0; i < fdmax; i++)
close(i);
[...]
}
`---
regards,
guillem
Re: Porting uptimed: Usage of daemon and replacement of NOFILE, Michael Banck, 2011/11/01