On Tue, 2011-11-01 at 13:34 +0100, Guillem Jover wrote:
> 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)
Updated code snippet below, OK?
void bg(void)
{
int i, fdmax;
/* 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 */
#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);
/* Be nice to umount */
chdir("/");
}