File tree Expand file tree Collapse file tree 5 files changed +37
-0
lines changed Expand file tree Collapse file tree 5 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ usage(void)
72
72
" -x pid Used internally by WiFiDog when re-starting itself *DO NOT ISSUE THIS SWITCH MANUAlLY*\n" );
73
73
fprintf (stdout , " -i <path> Internal socket path used when re-starting self\n" );
74
74
fprintf (stdout , " -a <path> Path to /proc/net/arp replacement - mainly useful for debugging.\n" );
75
+ fprintf (stdout , " -p <path> Save pid to file\n" );
75
76
fprintf (stdout , "\n" );
76
77
}
77
78
@@ -164,6 +165,15 @@ parse_commandline(int argc, char **argv)
164
165
exit (1 );
165
166
}
166
167
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 ;
167
177
default :
168
178
usage ();
169
179
exit (1 );
Original file line number Diff line number Diff line change @@ -162,6 +162,8 @@ typedef struct {
162
162
char * internal_sock ; /**< @brief internal path to socket */
163
163
int deltatraffic ; /**< @brief reset each user's traffic (Outgoing and Incoming) value after each Auth operation. */
164
164
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
167
char * external_interface ; /**< @brief External network interface name for
166
168
firewall rules */
167
169
char * gw_id ; /**< @brief ID of the Gateway, sent to central
Original file line number Diff line number Diff line change @@ -366,6 +366,10 @@ main_loop(void)
366
366
started_time = time (NULL );
367
367
}
368
368
369
+ /* save the pid file if needed */
370
+ if (config -> save_pid )
371
+ save_pid_file (config -> pidfile );
372
+
369
373
/* If we don't have the Gateway IP address, get it. Can't fail. */
370
374
if (!config -> gw_address ) {
371
375
debug (LOG_DEBUG , "Finding IP address of %s" , config -> gw_interface );
Original file line number Diff line number Diff line change @@ -389,3 +389,21 @@ rand16(void)
389
389
* ignore that one. */
390
390
return ((unsigned short )(rand () >> 15 ));
391
391
}
392
+
393
+ /*
394
+ * Save pid of this wifidog in pid file
395
+ * @param 'pf' as string, it is the pid file absolutely path
396
+ */
397
+ void
398
+ save_pid_file (const char * pf )
399
+ {
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 ;
409
+ }
Original file line number Diff line number Diff line change @@ -58,4 +58,7 @@ void close_icmp_socket(void);
58
58
/** @brief ICMP Ping an IP */
59
59
void icmp_ping (const char * );
60
60
61
+ /** @brief Save pid of this wifidog in pid file */
62
+ void save_pid_file (const char * pf );
63
+
61
64
#endif /* _UTIL_H_ */
You can’t perform that action at this time.
0 commit comments