rem: " pid number\n", pid_fn);
add: " pid number\n", pid_file);
context: int daemonize(char*  name){	FILE *pid_stream;	pid_t pid;	int r, p;	int pid_fn_len;	p=-1;	if (log_stderr==0)		openlog(name, LOG_PID|LOG_CONS, LOG_LOCAL1 /*LOG_DAEMON*/);		/* LOG_CONS, LOG_PERRROR ? */	if (chroot_dir&&(chroot(chroot_dir)<0)){		LOG(L_CRIT, "Cannot chroot to %s: %s\n", chroot_dir, strerror(errno));		goto error;	}		if (chdir(working_dir)<0){		LOG(L_CRIT,"cannot chdir to %s: %s\n", working_dir, strerror(errno));		goto error;	}	if (gid&&(setgid(gid)<0)){		LOG(L_CRIT, "cannot change gid to %d: %s\n", gid, strerror(errno));		goto error;	}		if(uid&&(setuid(uid)<0)){		LOG(L_CRIT, "cannot change uid to %d: %s\n", uid, strerror(errno));		goto error;	}	/* fork to become!= group leader*/	if ((pid=fork())<0){		LOG(L_CRIT, "Cannot fork:%s\n", strerror(errno));		goto error;	}	if (pid!=0){		/* parent process => exit*/		exit(0);	}	/* become session leader to drop the ctrl. terminal */	if (setsid()<0){		LOG(L_WARN, "setsid failed: %s\n",strerror(errno));	}	/* fork again to drop group  leadership */	if ((pid=fork())<0){		LOG(L_CRIT, "Cannot  fork:%s\n", strerror(errno));		goto error;	}	if (pid!=0){		/*parent process => exit */		exit(0);	}	/* added by noh: create a pid file for the main process */	if (pid_file!=0){		/* added port number; -jiri */		pid_fn_len = strlen(pid_file) + 5 /* long port number */ 			+ 1 /* dot */ + 1 /* ZT */ ;		pid_fn = malloc( pid_fn_len );		if (!pid_fn) {			LOG(L_ERR, "ERROR: There is really no memory for ser\n");			goto error;		}		if (snprintf(pid_fn, pid_fn_len, "%s.%d", pid_file, port_no )==-1) {			LOG(L_ERR, "ERROR: pidfile printig failed -- perhaps too high port?\n");			goto error;		}							if ((pid_stream=fopen(pid_fn, "r"))!=NULL){			fscanf(pid_stream, "%d", &p);			fclose(pid_stream);			if (p==-1){				LOG(L_CRIT, "pid file %s exists, but doesn't contain a valid"					" pid number\n", pid_fn);				goto error;			}			if (kill((pid_t)p, 0)==0 || errno==EPERM){				LOG(L_CRIT, "running process found in the pid file %s\n",					pid_fn);				goto error;			}else{				LOG(L_WARN, "pid file contains old pid, replacing pid\n");			}		}		pid=getpid();		if ((pid_stream=fopen(pid_fn, "w"))==NULL){			LOG(L_WARN, "unable to create pid file %s: %s\n", 				pid_fn, strerror(errno));			goto error;		}else{			fprintf(pid_stream, "%i\n", (int)pid);			fclose(pid_stream);		}	}		/* close any open file descriptors */	if (log_stderr==0)		for (r=0;r<MAX_FD; r++){			if ((r==3) && log_stderr)  continue;			close(r);		}	return  0;error:	return -1;}