blob: 45886896ee9b3021c68d98b0cadc6072719b58a8 [file] [log] [blame]
developer29c4d2d2022-12-26 19:41:22 +08001--- a/hostapd/main.c
2+++ b/hostapd/main.c
3@@ -39,6 +39,8 @@ struct hapd_global {
4 };
5
6 static struct hapd_global global;
7+static int daemonize = 0;
8+static char *pid_file = NULL;
9
10
11 #ifndef CONFIG_NO_HOSTAPD_LOGGER
12@@ -146,6 +148,14 @@ static void hostapd_logger_cb(void *ctx,
13 }
14 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
15
16+static void hostapd_setup_complete_cb(void *ctx)
17+{
18+ if (daemonize && os_daemonize(pid_file)) {
19+ perror("daemon");
20+ return;
21+ }
22+ daemonize = 0;
23+}
24
25 /**
26 * hostapd_driver_init - Preparate driver interface
developer8bff6472023-07-17 11:11:44 +080027@@ -217,6 +227,8 @@ static int hostapd_driver_init(struct ho
developer29c4d2d2022-12-26 19:41:22 +080028 }
developer8bff6472023-07-17 11:11:44 +080029 #endif /* CONFIG_IEEE80211BE */
developer29c4d2d2022-12-26 19:41:22 +080030
31+ hapd->setup_complete_cb = hostapd_setup_complete_cb;
32+
33 /* Initialize the driver interface */
34 if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5]))
35 b = NULL;
developer8bff6472023-07-17 11:11:44 +080036@@ -497,8 +509,6 @@ static void hostapd_global_deinit(const
developer29c4d2d2022-12-26 19:41:22 +080037 #endif /* CONFIG_NATIVE_WINDOWS */
38
39 eap_server_unregister_methods();
40-
41- os_daemonize_terminate(pid_file);
42 }
43
44
developer8bff6472023-07-17 11:11:44 +080045@@ -524,18 +534,6 @@ static int hostapd_global_run(struct hap
developer29c4d2d2022-12-26 19:41:22 +080046 }
47 #endif /* EAP_SERVER_TNC */
48
49- if (daemonize) {
50- if (os_daemonize(pid_file)) {
51- wpa_printf(MSG_ERROR, "daemon: %s", strerror(errno));
52- return -1;
53- }
54- if (eloop_sock_requeue()) {
55- wpa_printf(MSG_ERROR, "eloop_sock_requeue: %s",
56- strerror(errno));
57- return -1;
58- }
59- }
60-
61 eloop_run();
62
63 return 0;
developer8bff6472023-07-17 11:11:44 +080064@@ -739,8 +737,7 @@ int main(int argc, char *argv[])
developer29c4d2d2022-12-26 19:41:22 +080065 struct hapd_interfaces interfaces;
66 int ret = 1;
67 size_t i, j;
68- int c, debug = 0, daemonize = 0;
69- char *pid_file = NULL;
70+ int c, debug = 0;
71 const char *log_file = NULL;
72 const char *entropy_file = NULL;
73 char **bss_config = NULL, **tmp_bss;