Skip to content

Commit dc08fe7

Browse files
committed
Merge branch 'master' of github.com:wifidog/wifidog-gateway into new-coverity-pass
Conflicts: src/commandline.c src/gateway.c src/gateway.h src/simple_http.c src/wdctl_thread.c
2 parents 42bd2d5 + b80bc0b commit dc08fe7

File tree

8 files changed

+967
-873
lines changed

8 files changed

+967
-873
lines changed

src/commandline.c

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

4552
/**
4653
* A flag to denote whether we were restarted via a parent wifidog, or started normally
@@ -68,7 +75,8 @@ usage(void)
6875
fprintf(stdout, " -w <path> Wdctl socket path\n");
6976
fprintf(stdout, " -h Print usage\n");
7077
fprintf(stdout, " -v Print version information\n");
71-
fprintf(stdout, " -x pid Used internally by WiFiDog when re-starting itself *DO NOT ISSUE THIS SWITCH MANUAlLY*\n");
78+
fprintf(stdout,
79+
" -x pid Used internally by WiFiDog when re-starting itself *DO NOT ISSUE THIS SWITCH MANUAlLY*\n");
7280
fprintf(stdout, " -i <path> Internal socket path used when re-starting self\n");
7381
fprintf(stdout, "\n");
7482
}
@@ -77,20 +85,29 @@ usage(void)
7785
* also populates restartargv
7886
*/
7987
void
88+
<<<<<<< HEAD
8089
parse_commandline(int argc, char **argv) {
8190
int c;
8291
int skiponrestart;
8392
int i;
93+
=======
94+
parse_commandline(int argc, char **argv)
95+
{
96+
int c;
97+
int skiponrestart;
98+
int i;
99+
>>>>>>> b80bc0b523d60a5c16040ef8a66827aab13541b3
84100

85101
s_config *config = config_get_config();
86102

87-
//MAGIC 3: Our own -x, the pid, and NULL :
88-
restartargv = safe_malloc((size_t) (argc + 3) * sizeof(char*));
89-
i=0;
90-
restartargv[i++] = safe_strdup(argv[0]);
103+
//MAGIC 3: Our own -x, the pid, and NULL :
104+
restartargv = safe_malloc((size_t) (argc + 3) * sizeof(char *));
105+
i = 0;
106+
restartargv[i++] = safe_strdup(argv[0]);
91107

92108
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vx:i:"))) {
93109

110+
<<<<<<< HEAD
94111
skiponrestart = 0;
95112

96113
switch(c) {
@@ -179,6 +196,94 @@ parse_commandline(int argc, char **argv) {
179196
restartargv[i++] = NULL;
180197
restartargv[i++] = NULL;
181198
restartargv[i++] = NULL;
199+
=======
200+
skiponrestart = 0;
182201

183-
}
202+
switch (c) {
203+
204+
case 'h':
205+
usage();
206+
exit(1);
207+
break;
208+
209+
case 'c':
210+
if (optarg) {
211+
free(config->configfile);
212+
config->configfile = safe_strdup(optarg);
213+
}
214+
break;
215+
216+
case 'w':
217+
if (optarg) {
218+
free(config->wdctl_sock);
219+
config->wdctl_sock = safe_strdup(optarg);
220+
}
221+
break;
222+
223+
case 'f':
224+
skiponrestart = 1;
225+
config->daemon = 0;
226+
break;
227+
228+
case 'd':
229+
if (optarg) {
230+
config->debuglevel = atoi(optarg);
231+
}
232+
break;
233+
234+
case 's':
235+
config->log_syslog = 1;
236+
break;
237+
238+
case 'v':
239+
fprintf(stdout, "This is WiFiDog version " VERSION "\n");
240+
exit(1);
241+
break;
184242

243+
case 'x':
244+
skiponrestart = 1;
245+
if (optarg) {
246+
restart_orig_pid = atoi(optarg);
247+
} else {
248+
fprintf(stdout, "The expected PID to the -x switch was not supplied!");
249+
exit(1);
250+
}
251+
break;
252+
253+
case 'i':
254+
if (optarg) {
255+
free(config->internal_sock);
256+
config->internal_sock = safe_strdup(optarg);
257+
}
258+
break;
259+
260+
default:
261+
usage();
262+
exit(1);
263+
break;
264+
265+
}
266+
267+
if (!skiponrestart) {
268+
/* Add it to restartargv */
269+
safe_asprintf(&(restartargv[i++]), "-%c", c);
270+
if (optarg) {
271+
restartargv[i++] = safe_strdup(optarg);
272+
}
273+
}
274+
275+
}
276+
277+
/* Finally, we should add the -x, pid and NULL to restartargv
278+
* HOWEVER we cannot do it here, since this is called before we fork to background
279+
* so we'll leave this job to gateway.c after forking is completed
280+
* so that the correct PID is assigned
281+
*
282+
* We add 3 nulls, and the first 2 will be overridden later
283+
*/
284+
restartargv[i++] = NULL;
285+
restartargv[i++] = NULL;
286+
restartargv[i++] = NULL;
287+
>>>>>>> b80bc0b523d60a5c16040ef8a66827aab13541b3
288+
289+
}

src/commandline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ extern char **restartargv;
4040
extern pid_t restart_orig_pid;
4141

4242
/** @brief Parses the command line and set the config accordingly */
43-
void parse_commandline(int, char**);
43+
void parse_commandline(int, char **);
4444

45-
#endif /* _COMMANDLINE_H_ */
45+
#endif /* _COMMANDLINE_H_ */

src/conf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,9 @@ parse_trusted_mac_list(const char *ptr)
873873
p->mac = safe_strdup(mac);
874874
p->next = NULL;
875875
} else {
876-
debug(LOG_ERR, "MAC address [%s] already on trusted list. See option TrustedMACList in wifidog.conf file ", mac);
876+
debug(LOG_ERR,
877+
"MAC address [%s] already on trusted list. See option TrustedMACList in wifidog.conf file ",
878+
mac);
877879
}
878880
}
879881
}

0 commit comments

Comments
 (0)