@@ -1096,8 +1096,9 @@ int main(int argc, char *argv[])
}
}
- if (daemonize && os_daemonize(pid_file))
+ if (daemonize && os_daemonize())
return -1;
+ os_write_pid_file(pid_file);
if (interactive)
hostapd_cli_interactive();
@@ -451,10 +451,11 @@ static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize,
}
#endif /* EAP_SERVER_TNC */
- if (daemonize && os_daemonize(pid_file)) {
+ if (daemonize && os_daemonize()) {
perror("daemon");
return -1;
}
+ os_write_pid_file(pid_file);
eloop_run();
@@ -77,10 +77,9 @@ int os_gmtime(os_time_t t, struct os_tm *tm);
/**
* os_daemonize - Run in the background (detach from the controlling terminal)
- * @pid_file: File name to write the process ID to or %NULL to skip this
* Returns: 0 on success, -1 on failure
*/
-int os_daemonize(const char *pid_file);
+int os_daemonize();
/**
* os_daemonize_terminate - Stop running in the background (remove pid file)
@@ -89,6 +88,13 @@ int os_daemonize(const char *pid_file);
void os_daemonize_terminate(const char *pid_file);
/**
+ * os_write_pid_file - Write current process ID to pid_file
+ * @pid_file: File name to write the process ID to or %NULL to skip this
+ * Returns: 0 on success, -1 on failure
+ */
+int os_write_pid_file(const char *pid_file);
+
+/**
* os_get_random - Get cryptographically strong pseudo random data
* @buf: Buffer for pseudo random data
* @len: Length of the buffer
@@ -82,22 +82,28 @@ int os_gmtime(os_time_t t, struct os_tm *tm)
}
-int os_daemonize(const char *pid_file)
+int os_daemonize()
{
if (daemon(0, 0)) {
perror("daemon");
return -1;
}
+ return 0;
+}
+
+
+int os_write_pid_file(const char *pid_file)
+{
if (pid_file) {
FILE *f = fopen(pid_file, "w");
if (f) {
fprintf(f, "%u\n", getpid());
fclose(f);
+ return 0;
}
}
-
- return -0;
+ return -1;
}
@@ -38,7 +38,13 @@ int os_gmtime(os_time_t t, struct os_tm *tm)
}
-int os_daemonize(const char *pid_file)
+int os_daemonize()
+{
+ return -1;
+}
+
+
+int os_write_pid_file(const char *pid_file)
{
return -1;
}
@@ -153,7 +153,7 @@ static int os_daemon(int nochdir, int noclose)
#endif /* __APPLE__ */
-int os_daemonize(const char *pid_file)
+int os_daemonize()
{
#if defined(__uClinux__) || defined(__sun__)
return -1;
@@ -162,17 +162,21 @@ int os_daemonize(const char *pid_file)
perror("daemon");
return -1;
}
+ return 0;
+#endif /* defined(__uClinux__) || defined(__sun__) */
+}
+int os_write_pid_file(const char *pid_file)
+{
if (pid_file) {
FILE *f = fopen(pid_file, "w");
if (f) {
fprintf(f, "%u\n", getpid());
fclose(f);
+ return 0;
}
}
-
- return -0;
-#endif /* defined(__uClinux__) || defined(__sun__) */
+ return -1;
}
@@ -105,13 +105,19 @@ int os_gmtime(os_time_t t, struct os_tm *tm)
}
-int os_daemonize(const char *pid_file)
+int os_daemonize()
{
/* TODO */
return -1;
}
+int os_write_pid_file(const char *pid_file)
+{
+ return -1;
+}
+
+
void os_daemonize_terminate(const char *pid_file)
{
}
@@ -3482,8 +3482,11 @@ int main(int argc, char *argv[])
}
}
+ if (daemonize && os_daemonize())
+ return -1;
if (daemonize && os_daemonize(pid_file))
return -1;
+ os_write_pid_file(pid_file);
if (action_file)
wpa_cli_action(ctrl_conn);
@@ -1008,8 +1008,9 @@ int main(int argc, char *argv[])
interfaces = iface;
}
- if (daemonize && os_daemonize(pid_file))
+ if (daemonize && os_daemonize())
goto out;
+ os_write_pid_file(pid_file);
eloop_register_signal_terminate(wpa_priv_terminate, NULL);
eloop_run();
@@ -2400,10 +2400,10 @@ int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
}
-static int wpa_supplicant_daemon(const char *pid_file)
+static int wpa_supplicant_daemon()
{
wpa_printf(MSG_DEBUG, "Daemonize..");
- return os_daemonize(pid_file);
+ return os_daemonize();
}
@@ -3246,9 +3246,9 @@ int wpa_supplicant_run(struct wpa_global *global)
{
struct wpa_supplicant *wpa_s;
- if (global->params.daemonize &&
- wpa_supplicant_daemon(global->params.pid_file))
+ if (global->params.daemonize && wpa_supplicant_daemon())
return -1;
+ os_write_pid_file(global->params.pid_file);
if (global->params.wait_for_monitor) {
for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)