Package: didiwiki / 0.5-13

80_sigint_sigterm.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
From: Ignace Mouzannar <mouzannar@gmail.com>
Subject: Implementation of a SIGINT handler in order to stop didiwiki cleanly

diff -urNad didiwiki-0.5~/src/http.c didiwiki-0.5/src/http.c
--- didiwiki-0.5~/src/http.c	2009-07-24 17:19:53.000000000 +0200
+++ didiwiki-0.5/src/http.c	2009-07-24 17:20:29.000000000 +0200
@@ -442,6 +442,40 @@
 }
 
 /*
+** SIGINT handler.
+*/
+
+void  
+sigint(int sig)
+{
+  printf("\nDidiwiki stopped.\n");
+  syslog(LOG_LOCAL0|LOG_INFO, "Didiwiki stopped.\n");
+
+  (void)signal(SIGINT, SIG_DFL);
+  (void)kill(getpid(), SIGINT);
+
+  /* NOTREACHED */
+  exit(1);
+}
+
+/*
+** SIGTERM handler
+*/
+void
+sigterm(int sig)
+{
+  printf("\nDidiwiki stopped.\n");
+  syslog(LOG_LOCAL0|LOG_INFO, "Didiwiki stopped.\n");
+
+  (void)signal(SIGTERM, SIG_DFL);
+  (void)kill(getpid(), SIGTERM);
+
+  /* NOTREACHED */
+  exit(1);
+
+}
+
+/*
 ** Maximum number of child processes that we can have running
 ** at one time before we start slowing things down.
 */
@@ -463,6 +497,12 @@
   struct sockaddr_in inaddr;        /* The socket address */
   int                reuse = 1;
 
+  /* catch SIGINT */
+  (void) signal(SIGINT, sigint);
+
+  /* catch SIGTERM */
+  (void) signal(SIGTERM, sigterm);
+
   memset(&inaddr, 0, sizeof(inaddr));
   inaddr.sin_family = AF_INET;
   inaddr.sin_addr.s_addr = address.s_addr;
diff -urNad didiwiki-0.5~/src/http.h didiwiki-0.5/src/http.h
--- didiwiki-0.5~/src/http.h	2009-07-24 17:19:53.000000000 +0200
+++ didiwiki-0.5/src/http.h	2009-07-24 17:20:53.000000000 +0200
@@ -55,5 +55,10 @@
 void
 http_response_send(HttpResponse *res);
 
+void
+sigint(int sig);
+
+void
+sigterm(int sig);
 
 #endif