Skip to content

Commit 110d81d

Browse files
committed
Indent commandline.{ch}, conf.c
1 parent a202a87 commit 110d81d

File tree

3 files changed

+105
-102
lines changed

3 files changed

+105
-102
lines changed

src/commandline.c

Lines changed: 100 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
* Holds an argv that could be passed to exec*() if we restart ourselves
4141
*/
4242
/* Declare variable */
43-
extern char ** restartargv;
43+
extern char **restartargv;
4444
/* Define variable */
45-
char ** restartargv = NULL;
45+
char **restartargv = NULL;
4646

4747
static void usage(void);
4848

@@ -73,115 +73,116 @@ usage(void)
7373
fprintf(stdout, " -w <path> Wdctl socket path\n");
7474
fprintf(stdout, " -h Print usage\n");
7575
fprintf(stdout, " -v Print version information\n");
76-
fprintf(stdout, " -x pid Used internally by WiFiDog when re-starting itself *DO NOT ISSUE THIS SWITCH MANUAlLY*\n");
76+
fprintf(stdout,
77+
" -x pid Used internally by WiFiDog when re-starting itself *DO NOT ISSUE THIS SWITCH MANUAlLY*\n");
7778
fprintf(stdout, " -i <path> Internal socket path used when re-starting self\n");
7879
fprintf(stdout, "\n");
7980
}
8081

8182
/** Uses getopt() to parse the command line and set configuration values
8283
* also populates restartargv
8384
*/
84-
void parse_commandline(int argc, char **argv) {
85-
int c;
86-
int skiponrestart;
87-
int i;
85+
void
86+
parse_commandline(int argc, char **argv)
87+
{
88+
int c;
89+
int skiponrestart;
90+
int i;
8891

8992
s_config *config = config_get_config();
9093

91-
//MAGIC 3: Our own -x, the pid, and NULL :
92-
restartargv = safe_malloc((size_t) (argc + 3) * sizeof(char*));
93-
i=0;
94-
restartargv[i++] = safe_strdup(argv[0]);
94+
//MAGIC 3: Our own -x, the pid, and NULL :
95+
restartargv = safe_malloc((size_t) (argc + 3) * sizeof(char *));
96+
i = 0;
97+
restartargv[i++] = safe_strdup(argv[0]);
9598

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

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

186188
}
187-

src/commandline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
#define _COMMANDLINE_H_
2929

3030
/** @brief Parses the command line and set the config accordingly */
31-
void parse_commandline(int, char**);
31+
void parse_commandline(int, char **);
3232

33-
#endif /* _COMMANDLINE_H_ */
33+
#endif /* _COMMANDLINE_H_ */

src/conf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,9 @@ parse_trusted_mac_list(const char *ptr)
868868
p->mac = safe_strdup(mac);
869869
p->next = NULL;
870870
} else {
871-
debug(LOG_ERR, "MAC address [%s] already on trusted list. See option TrustedMACList in wifidog.conf file ", mac);
871+
debug(LOG_ERR,
872+
"MAC address [%s] already on trusted list. See option TrustedMACList in wifidog.conf file ",
873+
mac);
872874
}
873875
}
874876
}

0 commit comments

Comments
 (0)