linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libtracefs: Add missing system includes
@ 2021-01-26 16:12 Tzvetomir Stoyanov (VMware)
       [not found] ` <CAK7tX=YU-R_agm-_XQFu1=Z_dvm92uMZ3CkPJGbwzPGVJ2SUTg@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-01-26 16:12 UTC (permalink / raw)
  To: rostedt, y.karadz; +Cc: linux-trace-devel

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.

Reported-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/tracefs.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/tracefs.h b/include/tracefs.h
index 3059dbb..f3eec62 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libtracefs: Add missing system includes
       [not found] ` <CAK7tX=YU-R_agm-_XQFu1=Z_dvm92uMZ3CkPJGbwzPGVJ2SUTg@mail.gmail.com>
@ 2021-01-26 16:58   ` Tzvetomir Stoyanov
  0 siblings, 0 replies; 2+ messages in thread
From: Tzvetomir Stoyanov @ 2021-01-26 16:58 UTC (permalink / raw)
  To: Sameeruddin Shaik; +Cc: Steven Rostedt, Yordan Karadzhov, Linux Trace Devel

On Tue, Jan 26, 2021 at 6:43 PM Sameeruddin Shaik
<sameeruddin.shaik8@gmail.com> wrote:
>
>
> 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
> -------------------------------------------
>
> 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.

>
> Thanks,
> sameer.
>
> On Tue, Jan 26, 2021 at 9:44 PM Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> wrote:
>>
>> 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.
>>
>> Reported-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
>> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
>> ---
>>  include/tracefs.h | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/tracefs.h b/include/tracefs.h
>> index 3059dbb..f3eec62 100644
>> --- a/include/tracefs.h
>> +++ b/include/tracefs.h
>> @@ -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
>>


-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-27  4:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-26 16:12 [PATCH] libtracefs: Add missing system includes Tzvetomir Stoyanov (VMware)
     [not found] ` <CAK7tX=YU-R_agm-_XQFu1=Z_dvm92uMZ3CkPJGbwzPGVJ2SUTg@mail.gmail.com>
2021-01-26 16:58   ` Tzvetomir Stoyanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).