Skip to content

Commit 4c35125

Browse files
committed
Add termination handler to wdctl thread instead of exit()
1 parent dc08fe7 commit 4c35125

File tree

3 files changed

+6
-112
lines changed

3 files changed

+6
-112
lines changed

src/commandline.c

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,7 @@
4040
/*
4141
* Holds an argv that could be passed to exec*() if we restart ourselves
4242
*/
43-
<<<<<<< HEAD
4443
char ** restartargv = NULL;
45-
=======
46-
/* Declare variable */
47-
extern char **restartargv;
48-
/* Define variable */
49-
char **restartargv = NULL;
50-
>>>>>>> b80bc0b523d60a5c16040ef8a66827aab13541b3
5144

5245
/**
5346
* A flag to denote whether we were restarted via a parent wifidog, or started normally
@@ -85,18 +78,11 @@ usage(void)
8578
* also populates restartargv
8679
*/
8780
void
88-
<<<<<<< HEAD
89-
parse_commandline(int argc, char **argv) {
90-
int c;
91-
int skiponrestart;
92-
int i;
93-
=======
9481
parse_commandline(int argc, char **argv)
9582
{
9683
int c;
9784
int skiponrestart;
9885
int i;
99-
>>>>>>> b80bc0b523d60a5c16040ef8a66827aab13541b3
10086

10187
s_config *config = config_get_config();
10288

@@ -106,97 +92,6 @@ parse_commandline(int argc, char **argv)
10692
restartargv[i++] = safe_strdup(argv[0]);
10793

10894
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vx:i:"))) {
109-
110-
<<<<<<< HEAD
111-
skiponrestart = 0;
112-
113-
switch(c) {
114-
115-
case 'h':
116-
usage();
117-
exit(1);
118-
break;
119-
120-
case 'c':
121-
if (optarg) {
122-
free(config->configfile);
123-
config->configfile = safe_strdup(optarg);
124-
}
125-
break;
126-
127-
case 'w':
128-
if (optarg) {
129-
free(config->wdctl_sock);
130-
config->wdctl_sock = safe_strdup(optarg);
131-
}
132-
break;
133-
134-
case 'f':
135-
skiponrestart = 1;
136-
config->daemon = 0;
137-
break;
138-
139-
case 'd':
140-
if (optarg) {
141-
config->debuglevel = atoi(optarg);
142-
}
143-
break;
144-
145-
case 's':
146-
config->log_syslog = 1;
147-
break;
148-
149-
case 'v':
150-
fprintf(stdout, "This is WiFiDog version " VERSION "\n");
151-
exit(1);
152-
break;
153-
154-
case 'x':
155-
skiponrestart = 1;
156-
if (optarg) {
157-
restart_orig_pid = atoi(optarg);
158-
}
159-
else {
160-
fprintf(stdout, "The expected PID to the -x switch was not supplied!");
161-
exit(1);
162-
}
163-
break;
164-
165-
case 'i':
166-
if (optarg) {
167-
free(config->internal_sock);
168-
config->internal_sock = safe_strdup(optarg);
169-
}
170-
break;
171-
172-
default:
173-
usage();
174-
exit(1);
175-
break;
176-
177-
}
178-
179-
if (!skiponrestart) {
180-
/* Add it to restartargv */
181-
safe_asprintf(&(restartargv[i++]), "-%c", c);
182-
if (optarg) {
183-
restartargv[i++] = safe_strdup(optarg);
184-
}
185-
}
186-
187-
}
188-
189-
/* Finally, we should add the -x, pid and NULL to restartargv
190-
* HOWEVER we cannot do it here, since this is called before we fork to background
191-
* so we'll leave this job to gateway.c after forking is completed
192-
* so that the correct PID is assigned
193-
*
194-
* We add 3 nulls, and the first 2 will be overridden later
195-
*/
196-
restartargv[i++] = NULL;
197-
restartargv[i++] = NULL;
198-
restartargv[i++] = NULL;
199-
=======
20095
skiponrestart = 0;
20196

20297
switch (c) {
@@ -284,6 +179,4 @@ parse_commandline(int argc, char **argv)
284179
restartargv[i++] = NULL;
285180
restartargv[i++] = NULL;
286181
restartargv[i++] = NULL;
287-
>>>>>>> b80bc0b523d60a5c16040ef8a66827aab13541b3
288-
289182
}

src/gateway.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ void
258258
termination_handler(int s)
259259
{
260260
static pthread_mutex_t sigterm_mutex = PTHREAD_MUTEX_INITIALIZER;
261+
pthread_t self = pthread_self();
261262

262263
debug(LOG_INFO, "Handler for termination caught signal %d", s);
263264

@@ -277,11 +278,11 @@ termination_handler(int s)
277278
* termination handler) from happening so we need to explicitly kill the threads
278279
* that use that
279280
*/
280-
if (tid_fw_counter) {
281+
if (tid_fw_counter && self != tid_fw_counter) {
281282
debug(LOG_INFO, "Explicitly killing the fw_counter thread");
282283
pthread_kill(tid_fw_counter, SIGKILL);
283284
}
284-
if (tid_ping) {
285+
if (tid_ping && self != tid_ping) {
285286
debug(LOG_INFO, "Explicitly killing the ping thread");
286287
pthread_kill(tid_ping, SIGKILL);
287288
}

src/wdctl_thread.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ thread_wdctl(void *arg)
9595

9696
if (wdctl_socket_server < 0) {
9797
debug(LOG_DEBUG, "Could not get server socket: %s", strerror(errno));
98-
terminate_handler();
98+
termination_handler(0);
9999
}
100100
debug(LOG_DEBUG, "Got server socket %d", wdctl_socket_server);
101101

@@ -112,12 +112,12 @@ thread_wdctl(void *arg)
112112
/* Which to use, AF_UNIX, PF_UNIX, AF_LOCAL, PF_LOCAL? */
113113
if (bind(wdctl_socket_server, (struct sockaddr *)&sa_un, sizeof(struct sockaddr_un))) {
114114
debug(LOG_ERR, "Could not bind control socket: %s", strerror(errno));
115-
terminate_handler();
115+
termination_handler(0);
116116
}
117117

118118
if (listen(wdctl_socket_server, 5)) {
119119
debug(LOG_ERR, "Could not listen on control socket: %s", strerror(errno));
120-
terminate_handler();
120+
termination_handler(0);
121121
}
122122

123123
while (1) {

0 commit comments

Comments
 (0)