#include "wrap.h"
#define MYDOMAIN_FLAG "/tmp/.mydomain_log"
void domain_end(){
Unlink(MYDOMAIN_FLAG);
}
int domain_init(){
int fd;
fd=open(MYDOMAIN_FLAG,O_RDWR|O_CREAT|O_EXCL|O_APPEND,0600);
if(fd==-1)
err_sys(errno,"domain faild, %s",MYDOMAIN_FLAG);
Dup2(fd,1);
Dup2(fd,2);
return fd;
}
int work(int argc,char **argv){
while(1){
sleep(60);
err_msg("one loop....");
}
return 0;
}
int start_domain(int argc,char **argv,int (*work)(int argc,char **argv)){
pid_t pid;
int fd,ecode;
fd=domain_init();
if(Fork()==0){
if(Fork()==0){
Atexit(domain_end);
err_msg("domain has ran sucessfully....");
ecode=work(argc,argv);
exit(ecode);
}
exit(0);
}
Wait(NULL);
return 0;
}
int main(int argc,char **argv){
return start_domain(argc,argv,work);
}