suppression double close dans init_blockchain
This commit is contained in:
@@ -0,0 +1 @@
|
||||
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f 0
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -2,5 +2,6 @@
|
||||
#define __MY_DAEMONIZE_H__
|
||||
|
||||
void daemonize();
|
||||
void log_signal_message(char*, char*);
|
||||
|
||||
#endif
|
||||
|
||||
+31
-18
@@ -10,7 +10,7 @@
|
||||
|
||||
#define RUNNING_DIR "/tmp"
|
||||
#define LOCK_FILE "/tmp/daemond.lock"
|
||||
#define LOG_FILE "daemond.log"
|
||||
#define LOG_FILE "/tmp/daemond.log"
|
||||
|
||||
/*
|
||||
* daemon.c
|
||||
@@ -33,35 +33,48 @@
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
void log_signal_message(char *filename,char *message){
|
||||
FILE *logfile;
|
||||
logfile = fopen(filename,"a");
|
||||
if(!logfile) return;
|
||||
fprintf(logfile,"%s",message);
|
||||
fclose(logfile);
|
||||
}
|
||||
|
||||
int lfp;
|
||||
void close_lock_file()
|
||||
{
|
||||
close(lfp);
|
||||
remove(LOCK_FILE);
|
||||
}
|
||||
|
||||
void daemonize(){
|
||||
int i,lfp;
|
||||
int pid;
|
||||
int i;
|
||||
char str[10];
|
||||
|
||||
if(getppid() == 1)
|
||||
return;
|
||||
pid = getppid();
|
||||
if(pid == 1) return;
|
||||
|
||||
i = fork();
|
||||
pid = fork();
|
||||
if(pid < 0) exit(1);
|
||||
if(pid > 0) exit(0);
|
||||
|
||||
if(i < 0)
|
||||
exit(1);
|
||||
if(i > 0)
|
||||
exit(0);
|
||||
setsid();
|
||||
|
||||
for(i = getdtablesize(); i >= 0; --i)
|
||||
close(i);
|
||||
for(i = getdtablesize(); i >= 0; --i) close(i);
|
||||
|
||||
i = open("/dev/null",O_RDWR);
|
||||
dup(i);
|
||||
dup(i);
|
||||
lfp = open("/dev/null",O_RDWR);
|
||||
dup(lfp);
|
||||
dup(lfp);
|
||||
umask(022);
|
||||
|
||||
lfp = open(LOCK_FILE,O_RDWR|O_CREAT,0640);
|
||||
if(lfp < 0)
|
||||
exit(1);
|
||||
if(lockf(lfp,F_TLOCK,0) < 0)
|
||||
exit(1);
|
||||
if(lfp < 0) exit(1);
|
||||
if(lockf(lfp,F_TLOCK,0) < 0) exit(1);
|
||||
|
||||
sprintf(str,"%d\n",getpid());
|
||||
write(lfp,str,strlen(str));
|
||||
|
||||
atexit(close_lock_file);
|
||||
}
|
||||
@@ -692,9 +692,6 @@ int init_blockchain_file()
|
||||
|
||||
request_headers_or_blocks_hash_init = true;
|
||||
cb_handshake_done_bestknownheight = block_height;
|
||||
|
||||
fclose(blockchain_fd);
|
||||
blockchain_fd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
* Les outils
|
||||
*/
|
||||
static void signal_handler(int sig){
|
||||
char msg[200];
|
||||
sprintf(msg,"process %d signal %d trapped\n", getpid(), sig);
|
||||
log_signal_message("/tmp/daemonize.log", msg);
|
||||
|
||||
switch(sig){
|
||||
case SIGUSR1:
|
||||
// signal USR1
|
||||
|
||||
Reference in New Issue
Block a user