Skip to content

Commit a4a81e2

Browse files
author
tymon
committed
correct the code style and add pid file support for wifidog daemon
Signed-off-by: tymon <[email protected]>
1 parent 05fa390 commit a4a81e2

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed

src/commandline.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ parse_commandline(int argc, char **argv)
165165
exit(1);
166166
}
167167
break;
168-
case 'p':
169-
if (optarg) {
170-
config->save_pid = 1;
171-
strncpy(config->pidfile, optarg, sizeof(config->pidfile));
172-
} else {
173-
fprintf(stdout, "The expected PID file path to the wifidog was not supplied!\n");
174-
exit(1);
175-
}
176-
break;
168+
case 'p':
169+
if (optarg) {
170+
free(config->pidfile);
171+
config->pidfile = safe_strdup(optarg);
172+
} else {
173+
fprintf(stdout, "The expected PID file path to the wifidog was not supplied!\n");
174+
exit(1);
175+
}
176+
break;
177177
default:
178178
usage();
179179
exit(1);

src/conf.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ typedef struct {
162162
char *internal_sock; /**< @brief internal path to socket */
163163
int deltatraffic; /**< @brief reset each user's traffic (Outgoing and Incoming) value after each Auth operation. */
164164
int daemon; /**< @brief if daemon > 0, use daemon mode */
165-
int save_pid; /**< @brief if save_pid == 1, save the pid in file */
166-
char pidfile[255]; /**< @brief pid file path of wifidog */
165+
char *pidfile; /**< @brief pid file path of wifidog */
167166
char *external_interface; /**< @brief External network interface name for
168167
firewall rules */
169168
char *gw_id; /**< @brief ID of the Gateway, sent to central

src/gateway.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ main_loop(void)
367367
}
368368

369369
/* save the pid file if needed */
370-
if (config->save_pid)
371-
save_pid_file(config->pidfile);
370+
if ((!config) && (!config->pidfile))
371+
save_pid_file(config->pidfile);
372372

373373
/* If we don't have the Gateway IP address, get it. Can't fail. */
374374
if (!config->gw_address) {

src/util.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,13 @@ rand16(void)
397397
void
398398
save_pid_file(const char *pf)
399399
{
400-
if (pf) {
401-
FILE *f = fopen(pf, "w");
402-
if (f) {
403-
fprintf(f, "%lu\n", getpid());
404-
fclose(f);
405-
}
406-
}
407-
408-
return;
400+
if (pf) {
401+
FILE *f = fopen(pf, "w");
402+
if (f) {
403+
fprintf(f, "%zu\n", getpid());
404+
fclose(f);
405+
}
406+
}
407+
408+
return;
409409
}

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ void close_icmp_socket(void);
5959
void icmp_ping(const char *);
6060

6161
/** @brief Save pid of this wifidog in pid file */
62-
void save_pid_file(const char *pf);
62+
void save_pid_file(const char *);
6363

6464
#endif /* _UTIL_H_ */

0 commit comments

Comments
 (0)