Sfoglia il codice sorgente

use unistd.h daemon function

master
MEUNIER Thibaud 5 anni fa
parent
commit
75ca7ce46e
2 ha cambiato i file con 33 aggiunte e 1 eliminazioni
  1. +32
    -1
      src/daemonize.c
  2. +1
    -0
      tmp/daemond.log

+ 32
- 1
src/daemonize.c Vedi File

@ -48,7 +48,7 @@ void close_lock_file()
remove(LOCK_FILE);
}
void daemonize(){
void kamathvasudev_daemonize(){
int pid;
int i;
char str[10];
@ -85,3 +85,34 @@ void daemonize(){
atexit(close_lock_file);
}
void daemonize()
{
pid_t pid;
char str[10];
/*
* use unistd.h function
* - do change to root directory
* - close std streams
*/
daemon(1, 0);
/*
* Double fork method
*/
pid = fork();
if(pid < 0) exit(1);
if(pid > 0) exit(0);
umask(022);
lfp = open(LOCK_FILE,O_RDWR|O_CREAT,0640);
if(lfp < 0) { log_signal_message("daemond is allready running !\n");exit(1); }
if(lockf(lfp,F_TLOCK,0) < 0) { log_signal_message("daemond is allready running\n");exit(1); }
sprintf(str,"%d\n",getpid());
write(lfp,str,strlen(str));
atexit(close_lock_file);
}

+ 1
- 0
tmp/daemond.log Vedi File

@ -1 +1,2 @@
process 11096 signal 15 trapped
process 16565 signal 15 trapped

Caricamento…
Annulla
Salva