Переглянути джерело

ADD test_daemonize

master
tibo 5 роки тому
джерело
коміт
9e67f611ff
3 змінених файлів з 81 додано та 1 видалено
  1. +5
    -0
      Makefile
  2. +1
    -1
      Makefile.inc
  3. +75
    -0
      src/test_daemonize.c

+ 5
- 0
Makefile Переглянути файл

@ -37,3 +37,8 @@ $(BINDIR)/block2json : $(OBJDIR)/block2json.o
block2json : $(BINDIR)/block2json
$(BINDIR)/test_daemonize : $(OBJDIR)/test_daemonize.o $(OBJDIR)/daemonize.o
$(CC) -o $@ $^ $(LDFLAGS)
test_daemonize : $(BINDIR)/test_daemonize

+ 1
- 1
Makefile.inc Переглянути файл

@ -1,5 +1,5 @@
CC=gcc
IFLAGS=-I /usr/local/include -I include
IFLAGS=-I ../libbtc/include -I include
CFLAGS=-g
LDFLAGS=-lbtc -lsecp256k1
OBJDIR=obj

+ 75
- 0
src/test_daemonize.c Переглянути файл

@ -0,0 +1,75 @@
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
#include <daemonize.h>
/*
* Les outils
*/
static void signal_handler(int sig){
switch(sig){
case SIGUSR1:
// signal USR1
break;
case SIGUSR2:
// Signal USR2
break;
case SIGHUP:
// Reload conf and reinitialize processus
break;
case SIGINT:
// CTRL+C
case SIGTERM:
// Terminate : kill -15
exit(0);
break;
}
}
#define array_len(a) ( sizeof(a) / sizeof(a[0]) )
int main(int ac, char** av)
{
/*
* Daemonize
*/
daemonize();
/*
* Trapper les signaux pour fermer correctement le programme
*/
int les_signaux_ign[] = { SIGCHLD, SIGTSTP, SIGTTOU, SIGTTIN };
int les_signaux[] = { SIGHUP, SIGTERM, SIGINT };
size_t n;
n = array_len(les_signaux_ign);
for(int i = 0; i < n; i++)
{
if (signal(les_signaux_ign[i],SIG_IGN) == SIG_ERR)
{
printf("\ncan't catch signal %d\n", les_signaux_ign[i]);
return 1;
}
}
n = array_len(les_signaux);
for(int i = 0; i < n; i++)
{
if (signal(les_signaux[i],signal_handler) == SIG_ERR)
{
printf("\ncan't catch signal %d\n", les_signaux[i]);
return 1;
}
}
for(;;) { sleep(10); }
return 0;
}

Завантаження…
Відмінити
Зберегти