Skip to contentSkip to conversation

libtracefs: Add missing system includes

PATCH In review Tzvetomir Stoyanov (VMware) 1 participant 2 messages Jan 26, 2021 – Jan 27, 2021 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracefs: Add missing system includes

Some libtracefs APIs use defines from Linux system headers. These headers are not included in the tracefs library main header file, which causes compilation errors when these APIs are used and the required system headers are not included explicitly by the caller.

---
 include/tracefs.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/tracefs.h +3 -1
index 3059dbb..f3eec62 100644
@@ -6,8 +6,10 @@
 #ifndef _TRACE_FS_H
 #define _TRACE_FS_H
 
-#include <traceevent/event-parse.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <sched.h>
+#include <traceevent/event-parse.h>
 
 char *tracefs_get_tracing_file(const char *name);
 void tracefs_put_tracing_file(char *name);
Signature · 1 line
2.29.2

A message that is not in the archive (sent off-list or not yet received): CAK7tX=YU-R_agm-_XQFu1=Z_dvm92uMZ3CkPJGbwzPGVJ2SUTg@mail.gmail.com

#2 lore raw
Quoted 34 lines · Sameeruddin Shaik

The following is the error, which we will get if the above patch is not applied

----------------------------

sameeraaron@sameeraaron-Lenovo-Z50-70:~/hobbies/libtracefs$ sudo make install
  COMPILE FPIC       tracefs-utils.o
  COMPILE FPIC       tracefs-instance.o
  COMPILE FPIC       tracefs-events.o
  COMPILE FPIC       tracefs-tools.o
  BUILD STATIC LIB   libtracefs.a
  COMPILE SHARED LIB libtracefs.so.1.0.2
  INSTALL     /home/sameeraaron/hobbies/libtracefs/libtracefs.pc    to    /usr/local/lib/x86_64-linux-gnu/pkgconfig
  INSTALL     /home/sameeraaron/hobbies/libtracefs/lib/tracefs/libtracefs.so.1.0.2    to    /usr/local/lib64
  INSTALL     /home/sameeraaron/hobbies/libtracefs/include/tracefs.h    to    /usr/local/include/tracefs
  INSTALL      trace.conf    to     /etc/ld.so.conf.d/
/bin/sh: 1: /home/sameeraaron/hobbies/libtracefs/test: not found
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
/etc/ld.so.conf.d//trace.conf:/usr/local/lib64
In file included from /home/sameeraaron/hobbies/libtracefs/test.c:1:0:
/usr/local/include/tracefs/tracefs.h: In function ‘tracefs_trace_on_get_fd’:
/usr/local/include/tracefs/tracefs.h:58:60: error: ‘O_RDWR’ undeclared (first use in this function)
  return tracefs_instance_file_open(instance, "tracing_on", O_RDWR);
                                                            ^
/usr/local/include/tracefs/tracefs.h:58:60: note: each undeclared identifier is reported only once for each function it appears in
-------------------------------------------
Quoted 8 lines

Tzvetomir Stoyanov,

I have one small doubt,

standard headers are not included in --<tracefs.h>-- file, but they are included
in the file where the tracefs_instance_file_open() function is defined, will it won't be suffice?

With your patch, above error is vanished, i tested it.

Thank you for testing the patch :) The problem is that tracefs_trace_on_get_fd() API is implemented as inline in the header file, It is not a good practice to force
the library users to add such indirect includes. As tracefs.h requires these system
headers, it should include them implicitly.

Quoted 36 lines

Thanks,
sameer.

Quoted 31 lines · Tzvetomir Stoyanov (VMware)

Some libtracefs APIs use defines from Linux system headers. These headers are not included in the tracefs library main header file, which causes compilation errors when these APIs are used and the required system headers are not included explicitly by the caller.

---
 include/tracefs.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/tracefs.h +3 -2
index 3059dbb..f3eec62 100644
@@ -6,8 +6,10 @@
 #ifndef _TRACE_FS_H
 #define _TRACE_FS_H
 
-#include <traceevent/event-parse.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <sched.h>
+#include <traceevent/event-parse.h>
 
 char *tracefs_get_tracing_file(const char *name);
 void tracefs_put_tracing_file(char *name);
--

2.29.2

Signature · 2 lines
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center