From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> There may be cases when reading a file that warnings should not be displayed. Add a parameter to str_read_file() that lets the caller tell it not to warn on any errors. Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> --- include/tracefs-local.h | 2 +- src/tracefs-events.c | 6 +++--- src/tracefs-instance.c | 2 +- src/tracefs-utils.c | 8 +++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/tracefs-local.h b/include/tracefs-local.h index 84e4b10..9e3aa18 100644 --- a/include/tracefs-local.h +++ b/include/tracefs-local.h @@ -42,7 +42,7 @@ static inline pthread_mutex_t *trace_get_lock(struct tracefs_instance *instance) /* Can be overridden */ void tracefs_warning(const char *fmt, ...); -int str_read_file(const char *file, char **buffer); +int str_read_file(const char *file, char **buffer, bool warn); char *trace_append_file(const char *dir, const char *name); char *trace_find_tracing_dir(void); diff --git a/src/tracefs-events.c b/src/tracefs-events.c index 9a706ab..ab474e0 100644 --- a/src/tracefs-events.c +++ b/src/tracefs-events.c @@ -485,7 +485,7 @@ char **tracefs_tracers(const char *tracing_dir) if (ret < 0) goto out_free; - len = str_read_file(available_tracers, &buf); + len = str_read_file(available_tracers, &buf, true); if (len <= 0) goto out_free; @@ -545,7 +545,7 @@ static int load_events(struct tep_handle *tep, if (ret < 0) goto next_event; - len = str_read_file(format, &buf); + len = str_read_file(format, &buf, true); if (len <= 0) goto next_event; @@ -575,7 +575,7 @@ static int read_header(struct tep_handle *tep, const char *tracing_dir) if (ret < 0) goto out; - len = str_read_file(header, &buf); + len = str_read_file(header, &buf, true); if (len <= 0) goto out; diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c index c6cfbda..b8ce36f 100644 --- a/src/tracefs-instance.c +++ b/src/tracefs-instance.c @@ -400,7 +400,7 @@ char *tracefs_instance_file_read(struct tracefs_instance *instance, if (!path) return NULL; - size = str_read_file(path, &buf); + size = str_read_file(path, &buf, true); tracefs_put_tracing_file(path); if (buf && psize) diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c index 812a41a..e10b333 100644 --- a/src/tracefs-utils.c +++ b/src/tracefs-utils.c @@ -196,7 +196,7 @@ void tracefs_put_tracing_file(char *name) free(name); } -__hidden int str_read_file(const char *file, char **buffer) +__hidden int str_read_file(const char *file, char **buffer, bool warn) { char stbuf[BUFSIZ]; char *buf = NULL; @@ -207,7 +207,8 @@ __hidden int str_read_file(const char *file, char **buffer) fd = open(file, O_RDONLY); if (fd < 0) { - tracefs_warning("File %s not found", file); + if (warn) + tracefs_warning("File %s not found", file); return -1; } @@ -217,7 +218,8 @@ __hidden int str_read_file(const char *file, char **buffer) continue; nbuf = realloc(buf, size+r+1); if (!nbuf) { - tracefs_warning("Failed to allocate file buffer"); + if (warn) + tracefs_warning("Failed to allocate file buffer"); size = -1; break; } -- 2.29.2