[PATCH] hostapd PID
Lubomir Gelo
lgelo
Wed Jul 16 08:59:54 PDT 2003
Hostapd daemon doesn't create PID file. Since we often use 2 or even
4 daemons, one for each wireless interface it's nice to know PID
without greping through ps output. Using one daemon for more interfaces
is out of question. Patch is enclosed.
LG
-------------- next part --------------
diff -urN hostapd-snapshot.orig/hostapd/config.c hostapd-snapshot/hostapd/config.c
--- hostapd-snapshot.orig/hostapd/config.c 2003-05-09 17:54:09.000000000 +0200
+++ hostapd-snapshot/hostapd/config.c 2003-05-14 11:02:34.000000000 +0200
@@ -214,6 +214,8 @@
conf->dump_log_name = strdup(pos);
} else if (strcmp(buf, "daemonize") == 0) {
conf->daemonize = atoi(pos);
+ } else if (strcmp(buf, "pid_file") == 0) {
+ conf->pid_file_name = strdup(pos);
} else if (strcmp(buf, "ssid") == 0) {
conf->ssid_len = strlen(pos);
if (conf->ssid_len >= HOSTAPD_SSID_LEN ||
@@ -396,6 +397,7 @@
return;
free(conf->dump_log_name);
+ free(conf->pid_file_name);
free(conf->eap_req_id_text);
free(conf->accept_mac);
free(conf->deny_mac);
diff -urN hostapd-snapshot.orig/hostapd/config.h hostapd-snapshot/hostapd/config.h
--- hostapd-snapshot.orig/hostapd/config.h 2003-05-07 06:38:47.000000000 +0200
+++ hostapd-snapshot/hostapd/config.h 2003-05-14 10:58:56.000000000 +0200
@@ -33,6 +33,8 @@
char *dump_log_name; /* file name for state dump (SIGUSR1) */
int daemonize; /* fork into background */
+ char *pid_file_name;
+
int ieee802_1x; /* use IEEE 802.1X */
int minimal_eap; /* test version of EAP authentication that only
* requires EAP Response-Identity and authorizes any
diff -urN hostapd-snapshot.orig/hostapd/hostapd.c hostapd-snapshot/hostapd/hostapd.c
--- hostapd-snapshot.orig/hostapd/hostapd.c 2003-05-11 08:10:08.000000000 +0200
+++ hostapd-snapshot/hostapd/hostapd.c 2003-05-14 11:25:36.000000000 +0200
@@ -348,6 +348,9 @@
hostapd_acl_deinit(hapd);
radius_client_deinit(hapd);
+ if (hapd->conf->pid_file_name)
+ unlink(hapd->conf->pid_file_name);
+
hostapd_config_free(hapd->conf);
hapd->conf = NULL;
@@ -522,6 +525,7 @@
{
struct hapd_interfaces interfaces;
int ret = 1, i;
+ FILE *fp;
int c, debug = 0, daemonize = 0;
for (;;) {
@@ -572,10 +576,23 @@
goto out;
}
- if (daemonize && daemon(0, 0)) {
- perror("daemon");
- goto out;
- }
+
+ if (daemonize){
+ if (daemon(0, 0)) {
+ perror("daemon");
+ goto out;
+ }
+
+ for (i = 0; i < interfaces.count; i++) {
+ if ((fp=fopen(interfaces.hapd[i]->conf->pid_file_name,"w"))==NULL){
+ printf("Failed to create PID file %s\n", interfaces.hapd[i]->conf->pid_file_name);
+ } else {
+ fprintf(fp, "%d\n", getpid());
+ fclose(fp);
+ }
+ }
+
+ }
openlog("hostapd", 0, LOG_DAEMON);
More information about the Hostap
mailing list