[PATCH 2/2] trace-cmd: record: fix glob() return value checks

Johannes Berg <[email protected]> Thu, 3 Jul 2025 13:53:35 +0200
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
glob() is defined to return zero on success or various GLOB_*
error constants, but those are not defined to be negative. In
fact, glibc makes them positive, and as a result the checks
don't do anything at all on glibc, but erroneously abort on
other libc implementations (such as bionic) that use negative
values for GLOB_* errors.

Fix this to compare against 0 only, adding documentation as
to which error result codes are possible.

Fixes: 6f1c80b937ee ("trace-cmd: Use glob() library call to enable events")
Fixes: 65b7fed7c15c ("trace-cmd: Add filtering of events")
Signed-off-by: Johannes Berg <[email protected]>
---
 tracecmd/trace-record.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index b122579bc178..47486e9863df 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -2248,7 +2248,8 @@ reset_events_instance(struct buffer_instance *instance)
 	globbuf.gl_offs = 0;
 	ret = glob(path, 0, NULL, &globbuf);
 	tracefs_put_tracing_file(path);
-	if (ret < 0)
+	/* no request flags, so only GLOB_NOSPACE and GLOB_NOMATCH */
+	if (ret != 0)
 		return;
 
 	for (i = 0; i < globbuf.gl_pathc; i++) {
@@ -3210,8 +3211,9 @@ static int expand_event_files(struct buffer_instance *instance,
 	tracefs_put_tracing_file(path);
 	free(p);
 
-	if (ret < 0)
-		die("No filters found");
+	/* no request flags, so only GLOB_NOSPACE and GLOB_NOMATCH */
+	if (ret != 0)
+		return 1;
 
 	for (i = 0; i < globbuf.gl_pathc; i++) {
 		int len;
-- 
2.50.0