[Top][All Lists]

[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 13:34:22 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, 2011-11-01 at 11:49:48 +0100, Svante Signell wrote:
> In package uptimed-0.3.16 the following function is defined:
> void bg(void)
> {
>         /* Close probably all file descriptors */
>         for (i = 0; i<NOFILE; i++)
>                 close(i);
> }

> Two questions arrives after discussing with braunr on IRC:
> 1) Can bg() safely be replaced with daemon()? It is not yet in any posix
> standard.

I don't think daemon() is portable enough, Solaris for example does
not have it.

> 2) If not, what to replace NOFILE with in the code for bg()?
> NOFILE is defined for Linux in /usr/include/sys/param.h but is not
> recommended: 
> /* The following are not really correct but it is a value we used for a
>    long time and which seems to be usable.  People should not use NOFILE
>    and NCARGS anyway.  */
> #define NOFILE          256

The code is trying to close all possible open descriptors, to get the
actual max number, you can either use getdtablesize() or
sysconf(_SC_OPEN_MAX), depending on the first being available or not.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]