clouseau: Handle error cases when daemonizing.
Finishing what Hermet started here. Checking the return values and return if we meet an error case. And yes, I did that because the failure in buildbot annoyed me but checking for this retrun values makes actually sense. SVN revision: 78759
This commit is contained in:
parent
500c76369c
commit
c02ca8ed83
|
@ -73,7 +73,7 @@ _daemon_cleanup(void)
|
|||
|
||||
void daemonize(void)
|
||||
{
|
||||
int i,lfp, ret;
|
||||
int i,lfp;
|
||||
char str[10];
|
||||
time_t currentTime;
|
||||
|
||||
|
@ -88,15 +88,16 @@ void daemonize(void)
|
|||
setsid(); /* obtain a new process group */
|
||||
for (i=getdtablesize();i>=0;--i) close(i); /* close all descriptors */
|
||||
i=open("/dev/null",O_RDWR);
|
||||
ret = dup(i); ret = dup(i); /* handle standart I/O */
|
||||
if (dup(i) == -1) return; /* handle standart I/O */
|
||||
if (dup(i) == -1) return; /* handle standart I/O */
|
||||
umask(027); /* set newly created file permissions */
|
||||
ret = chdir(RUNNING_DIR); /* change running directory */
|
||||
if (chdir(RUNNING_DIR) == -1) return; /* change running directory */
|
||||
lfp=open(LOCK_FILE,O_RDWR|O_CREAT,0640);
|
||||
if (lfp<0) exit(1); /* can not open */
|
||||
if (lockf(lfp,F_TLOCK,0)<0) exit(0); /* can not lock */
|
||||
/* first instance continues */
|
||||
sprintf(str,"%d\n",getpid());
|
||||
ret = write(lfp,str,strlen(str)); /* record pid to lockfile */
|
||||
if (write(lfp,str,strlen(str)) == -1) return; /* record pid to lockfile */
|
||||
signal(SIGCHLD,SIG_IGN); /* ignore child */
|
||||
signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
|
||||
signal(SIGTTOU,SIG_IGN);
|
||||
|
|
Loading…
Reference in New Issue