/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/


#include	<stdlib.h>
#include	<limits.h>
#include	<fcntl.h>
#include	"memory_debug.h"
#include	"utils.h"
#include	"machine/fork_lock.h"
#include	"netutils.h"

extern int max_fid;

void
launch_devnull(char * proc)
{
char * buf;
int id;
int i;
int er;
	buf = d_alloc(1000);
	wlock_fork();
	id = fork();
	if ( id == 0 ) {
		for ( i = 1 ; i <= sys_param.max_fd ; i ++  ) {
		p1:
			er = close(i);
			if ( er < 0 && errno == EINTR )
				goto p1;
		}
		id = open("/dev/null",O_WRONLY);
		dup(id);
		sprintf(buf,"%s &",proc);
		system(buf);
		exit(0);
	}
	wunlock_fork();
	d_f_ree(buf);
}
