Project

General

Profile

Bug #7145 » patch-dhcp6c.c

Added new signal handling SIGUSER1, log changes and exit script call - Martin Wasley, 01/30/2017 06:48 AM

 
1
--- dhcp6c.c.orig	2016-12-19 08:16:42 UTC
2
+++ dhcp6c.c
3
@@ -85,6 +85,8 @@ static int exit_ok = 0;
4
 static sig_atomic_t sig_flags = 0;
5
 #define SIGF_TERM 0x1
6
 #define SIGF_HUP 0x2
7
+#define SIGF_QUIT 0x4
8
+
9
 
10
 const dhcp6_mode_t dhcp6_mode = DHCP6_MODE_CLIENT;
11
 
12
@@ -109,7 +111,7 @@ static int ctldigestlen;
13
 static int infreq_mode = 0;
14
 
15
 int opt_norelease;
16
-
17
+static char path_hold[256];
18
 static inline int get_val32 __P((char **, int *, u_int32_t *));
19
 static inline int get_ifname __P((char **, int *, char *, int));
20
 
21
@@ -390,6 +392,11 @@ client6_init()
22
 		    strerror(errno));
23
 		exit(1);
24
 	}
25
+	if (signal(SIGUSR1, client6_signal) == SIG_ERR) {
26
+		d_printf(LOG_WARNING, FNAME, "failed to set signal: %s",
27
+		    strerror(errno));
28
+		exit(1);
29
+	}
30
 }
31
 
32
 int
33
@@ -483,20 +490,31 @@ check_exit()
34
 {
35
 	struct dhcp6_if *ifp;
36
 
37
+	
38
+	
39
 	if (!exit_ok)
40
 		return;
41
 
42
-	for (ifp = dhcp6_if; ifp; ifp = ifp->next) {
43
-		/*
44
-		 * Check if we have an outstanding event.  If we do, we cannot
45
-		 * exit for now.
46
-		 */
47
-		if (!TAILQ_EMPTY(&ifp->event_list))
48
+	if(exit_ok) {
49
+	  
50
+		for (ifp = dhcp6_if; ifp; ifp = ifp->next) {
51
+			/*
52
+			* Check if we have an outstanding event.  If we do, we cannot
53
+			* exit for now.
54
+			*/
55
+			if (!TAILQ_EMPTY(&ifp->event_list))
56
 			return;
57
+		}
58
 	}
59
-
60
+	
61
 	/* We have no existing event.  Do exit. */
62
 	d_printf(LOG_INFO, FNAME, "exiting");
63
+	
64
+	if (strlen(path_hold) != 0) {
65
+		    /* We are going to fire the script with and exit value */
66
+		     d_printf(LOG_DEBUG, FNAME, "shutdown executes %s", path_hold);
67
+		     client6_script(path_hold, DHCP6S_EXIT, NULL);
68
+	} 
69
 
70
 	exit(0);
71
 }
72
@@ -504,6 +522,8 @@ check_exit()
73
 static void
74
 process_signals()
75
 {
76
+     
77
+	 
78
 	if ((sig_flags & SIGF_TERM)) {
79
 		exit_ok = 1;
80
 		free_resources(NULL);
81
@@ -515,6 +535,14 @@ process_signals()
82
 		free_resources(NULL);
83
 		client6_startall(1);
84
 	}
85
+	if ((sig_flags & SIGF_QUIT)) {
86
+		d_printf(LOG_INFO, FNAME, "QUIT signal");
87
+		exit_ok = 1;
88
+		opt_norelease = 1;
89
+		free_resources(NULL);
90
+		unlink(pid_file);
91
+		check_exit();
92
+	}
93
 
94
 	sig_flags = 0;
95
 }
96
@@ -1161,6 +1189,9 @@ client6_signal(sig)
97
 	case SIGHUP:
98
 		sig_flags |= SIGF_HUP;
99
 		break;
100
+	case SIGUSR1:
101
+		sig_flags |= SIGF_QUIT;
102
+		break;
103
 	}
104
 }
105
 
106
@@ -1751,23 +1782,23 @@ client6_recvreply(ifp, dh6, len, optinfo
107
 
108
 	switch (state) {
109
 	case DHCP6S_INFOREQ:
110
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received INFOREQ");
111
-		break;  
112
-	case DHCP6S_REQUEST:
113
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received REQUEST");
114
-		break;
115
-	case DHCP6S_RENEW:
116
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received INFO");
117
-		break;
118
-	case DHCP6S_REBIND:
119
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received REBIND");
120
-		break;
121
-	case DHCP6S_RELEASE:
122
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received RELEASE");
123
-		break;
124
-	case DHCP6S_SOLICIT:
125
-		d_printf(LOG_INFO, FNAME, "dhcp6c Received SOLICIT");
126
-		break;          
127
+		d_printf(LOG_INFO, FNAME, "Received Info");
128
+ 		break;  
129
+ 	case DHCP6S_REQUEST:
130
+		d_printf(LOG_INFO, FNAME, "Received Reply");
131
+ 		break;
132
+ 	case DHCP6S_RENEW:
133
+		d_printf(LOG_INFO, FNAME, "Received Renew");
134
+ 		break;
135
+ 	case DHCP6S_REBIND:
136
+		d_printf(LOG_INFO, FNAME, "Received Rebind");
137
+ 		break;
138
+ 	case DHCP6S_RELEASE:
139
+		d_printf(LOG_INFO, FNAME, "Received Release");
140
+ 		break;
141
+ 	case DHCP6S_SOLICIT:
142
+		d_printf(LOG_INFO, FNAME, "Received Advert");
143
+ 		break;             
144
 	}
145
 
146
 	/* A Reply message must contain a Server ID option */
(6-6/11)