Modify

Opened 2 years ago

Last modified 2 years ago

#20623 reopened defect

hostapd: no logging of wpa_printf messages

Reported by: rmilecki Owned by: developers
Priority: normal Milestone:
Component: packages Version: Trunk
Keywords: Cc:

Description

hostapd internally uses few functions for logging, e.g.:

  1. hostapd_logger
  2. wpa_printf

The first one works perfectly fine in OpenWrt. Whenever there is:

hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_INFO, "Foo\n");

it works OK, a following line appears in syslog:

daemon.info hostapd: wlan0: IEEE 802.11 Foo

Above works because hostapd_logger (wpa_debug.c) calls hostapd_logger_cb (wpa_debug.c) which points to the hostapd_logger_cb (main.c). That last function calls syslog(priority, "%s", format);.


Unfortunately logging messages printed by hostapd with wpa_printf doesn't work at all. Whenever something like:

wpa_printf(MSG_ERROR, "Foo\n");

is executed, nothing appears in a syslog. In current implementation & config _wpa_printf calls vprintf(fmt, ap); which doesn't result in message appearing in a syslog.

Attachments (0)

Change History (6)

comment:1 Changed 2 years ago by nbd

  • Resolution set to worksforme
  • Status changed from new to closed

Just set CONFIG_WPA_MSG_MIN_PRIORITY=0 in your .config and rebuild.

comment:2 Changed 2 years ago by rmilecki

@nbd: it's not really about CONFIG_WPA_MSG_MIN_PRIORITY or -d switch for hostapd, because I'm dealing with

wpa_printf(MSG_ERROR, "Foo\n");

(it's message important enough to be logged with default settings).

The issue is that hostapd prints wpa_printf messages to the stdout and so they are not visible in syslog. It's a bit confusing since hostapd_logger uses syslog. I think it would be nice to be consistent about this and let users see all errors in syslog. It's a bit pitty to have to run hostapd manually (from command line) to see WPA errors.

comment:3 Changed 2 years ago by rmilecki

  • Resolution worksforme deleted
  • Status changed from closed to reopened

comment:4 Changed 2 years ago by rmilecki

There is some analysis of how hostapd is started:

├ __wireless_device_set_up
├ wireless_device_run_handler
├ netifd_start_process
└┬ execvp
 └ ustream_fd_init

Please note that netifd_start_process forks and:

  1. Starts bash script
  2. Dups stdout and uses ustream to read output and log it using netifd_log_message

comment:5 Changed 2 years ago by rmilecki

I did a bit more of hostapd messages testing and there is something interesting I found. Every wpa_printf(MSG_ERROR, "..."); executed before calling eloop_run(); appears in the syslog.

Calls to wpa_printf executed after that are harder to predict.

  • Adding wpa_printf to hostapd_periodic never results in message appearing in a syslog
  • Message from wpa_printf placed right after eloop_run(); call is silent as well.
  • On the other hand I can see output of wpa_printf called in hostapd_flush_old_stations.

Maybe it's only about eloop callbacks? Maybe they are executed from different process (eloop process?) and netifd doesn't dups this process's stdout/stderr?

Last edited 2 years ago by rmilecki (previous) (diff)

comment:6 Changed 2 years ago by rmilecki

One of first eloop queued callbacks is some function calling hostapd_setup_interface_complete. When eloop runs, after an iteration or two, it calls:

├ (some function)
├ hostapd_setup_interface_complete
├ hostapd_setup_interface_complete_sync
├ hostapd_setup_complete_cb (from hapd->setup_complete_cb pointer)
└ os_daemonize

This os_daemonize is what breaks logging. It forks hostapd process and quits. The new process uses /dev/null for STDIN_FILENO, STDOUT_FILENO and STDERR_FILENO which means we don't get any more messages.

Last edited 2 years ago by rmilecki (previous) (diff)

Add Comment

Modify Ticket

Action
as reopened .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.