[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Porting uptimed: Usage of daemon and replacement of NOFILE
From: |
Svante Signell |
Subject: |
Porting uptimed: Usage of daemon and replacement of NOFILE |
Date: |
Tue, 01 Nov 2011 11:49:48 +0100 |
Hi,
In package uptimed-0.3.16 the following function is defined:
void bg(void)
{
int i;
/* Simple fork to run proces in the background. */
switch(fork())
{
case 0:
break;
case -1:
perror("fork failed"); exit(1);
default:
exit(0);
}
if (-1==setsid()) {
perror("setsid failed"); exit(1);
}
/* Close probably all file descriptors */
for (i = 0; i<NOFILE; i++)
close(i);
/* Be nice to umount */
chdir("/");
}
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.
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
#define NCARGS 131072
- Porting uptimed: Usage of daemon and replacement of NOFILE,
Svante Signell <=
Re: Porting uptimed: Usage of daemon and replacement of NOFILE, Michael Banck, 2011/11/01