From: Johannes Berg Date: Thu, 28 Aug 2025 12:15:00 +0000 (+0200) Subject: wpa_debug: Prefer tracefs over debugfs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a76c7ed64de46eb9019cf18906ce821941020eb;p=thirdparty%2Fhostap.git wpa_debug: Prefer tracefs over debugfs With Linux 6.17, having /sys/kernel/debug/tracing/ is now optional (CONFIG_TRACEFS_AUTOMOUNT_DEPRECATED), since tracefs has been around for a long time. Prefer tracefs when finding the trace_marker file. Note the "!buf[0]" condition which serves to keep the logic identical to before when tracefs isn't present, using the first debugfs rather than the last. That is not likely to matter, but still. Also mount tracefs in the scripts for running in VMs. Signed-off-by: Johannes Berg --- diff --git a/src/utils/wpa_debug.c b/src/utils/wpa_debug.c index 7f3dd185f..826a9a373 100644 --- a/src/utils/wpa_debug.c +++ b/src/utils/wpa_debug.c @@ -130,7 +130,7 @@ int wpa_debug_open_linux_tracing(void) int mounts, trace_fd; char buf[4096] = {}; ssize_t buflen; - char *line, *tmp1, *path = NULL; + char *line, *tmp1; mounts = open("/proc/mounts", O_RDONLY); if (mounts < 0) { @@ -153,21 +153,32 @@ int wpa_debug_open_linux_tracing(void) strtok_r(line, " ", &tmp2); tmp_path = strtok_r(NULL, " ", &tmp2); fstype = strtok_r(NULL, " ", &tmp2); - if (fstype && strcmp(fstype, "debugfs") == 0) { - path = tmp_path; + + if (!buf[0] && fstype && os_strcmp(fstype, "debugfs") == 0) { + os_snprintf(buf, sizeof(buf) - 1, + "%s/tracing/trace_marker", + tmp_path); + /* + * Don't break to prefer tracefs, which if present may + * mean debugfs doesn't have tracing/ (depending on the + * kernel version). + */ + } + + if (fstype && os_strcmp(fstype, "tracefs") == 0) { + os_snprintf(buf, sizeof(buf) - 1, "%s/trace_marker", + tmp_path); break; } line = strtok_r(NULL, "\n", &tmp1); } - if (path == NULL) { - printf("debugfs mountpoint not found\n"); + if (!buf[0]) { + printf("tracefs/debugfs not found\n"); return -1; } - snprintf(buf, sizeof(buf) - 1, "%s/tracing/trace_marker", path); - trace_fd = open(buf, O_WRONLY); if (trace_fd < 0) { printf("failed to open trace_marker file\n"); diff --git a/tests/hwsim/vm/inside.sh b/tests/hwsim/vm/inside.sh index 31dfb9d57..53d67472c 100755 --- a/tests/hwsim/vm/inside.sh +++ b/tests/hwsim/vm/inside.sh @@ -14,6 +14,7 @@ mount proc -t proc /proc mount sysfs -t sysfs /sys # needed for tracing mount debugfs -t debugfs /sys/kernel/debug +mount tracefs -t tracefs /sys/kernel/tracing mkdir /tmp/wireshark-share mount --bind /usr/share/wireshark /tmp/wireshark-share