]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_debug: Prefer tracefs over debugfs
authorJohannes Berg <johannes.berg@intel.com>
Thu, 28 Aug 2025 12:15:00 +0000 (14:15 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 29 Sep 2025 10:55:01 +0000 (13:55 +0300)
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 <johannes.berg@intel.com>
src/utils/wpa_debug.c
tests/hwsim/vm/inside.sh

index 7f3dd185f100c58f21084a9174b8776fbe57e793..826a9a3738d7f43e0e26ca7d6970fa5aada372b4 100644 (file)
@@ -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");
index 31dfb9d5708cc58cd6e20133213f81bc9c3236a9..53d67472cd50135419221abb0d35bc89e5435e26 100755 (executable)
@@ -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