Skip to contentSkip to conversation

Fix: unchecked return value

PATCH Jérémie Galarneau 2 participants 5 messages May 18, 2016 5 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 18 lines · Mathieu Desnoyers

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

---
 src/common/consumer/consumer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/common/consumer/consumer.c +0 -0
index cb05a1e..e22de4d 100644

src/common/consumer/consumer.c void lttng_consumer_sync_trace_file(struct lttng_consumer_stream *stream, · line 1267

Quoted 8 lines
src/common/consumer/consumer.c +3 -2
@@ -1262,8 +1262,10 @@ void lttng_consumer_sync_trace_file(struct lttng_consumer_stream *stream,
         * defined. So it can be expected to lead to lower throughput in
         * streaming.
         */
-       posix_fadvise(outfd, orig_offset - stream->max_sb_size,
-                       stream->max_sb_size, POSIX_FADV_DONTNEED);
+       if (posix_fadvise(outfd, orig_offset - stream->max_sb_size,
+                       stream->max_sb_size, POSIX_FADV_DONTNEED)) {
+               DBG("Ignoring posix_fadvise() error: %s.", strerror(errno));

posix_fadvise() does not set errno on error, it returns the error code directly. I have merged an alternative fix as:

commit c7a78aabfa0491974d4ffc188d72eb1e67c7344e

Author: Jérémie Galarneau <[email protected]>
Date:   Tue May 17 12:17:05 2016 -0400

Fix: unchecked posix_fadvise() return value

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

I also set this to WARN() since we'd probably want to know if we're misusing posix_fadvise or passing a bad FD, etc.

Thanks!
Jérémie

Quoted 7 lines
src/common/consumer/consumer.c +1 -1
+       }
 }
 
 /*
--

2.1.4

Signature · 7 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): CA+jJMxunQvhCgbbtPk1ZnZ9Y2w_upabio7kGOT4g9FirgCCNbA@mail.gmail.com

#3 lore raw
Quoted 47 lines · ----- On May 18, 2016, at 3:26 PM, Jeremie Galarneau…
Quoted 18 lines · Mathieu Desnoyers

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

---
 src/common/consumer/consumer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/common/consumer/consumer.c +0 -0
index cb05a1e..e22de4d 100644

src/common/consumer/consumer.c void lttng_consumer_sync_trace_file(struct · line 1268

Quoted 9 lines
src/common/consumer/consumer.c +3 -2
@@ -1262,8 +1262,10 @@ void lttng_consumer_sync_trace_file(struct
 lttng_consumer_stream *stream,
         * defined. So it can be expected to lead to lower throughput in
         * streaming.
         */
-       posix_fadvise(outfd, orig_offset - stream->max_sb_size,
-                       stream->max_sb_size, POSIX_FADV_DONTNEED);
+       if (posix_fadvise(outfd, orig_offset - stream->max_sb_size,
+                       stream->max_sb_size, POSIX_FADV_DONTNEED)) {
+               DBG("Ignoring posix_fadvise() error: %s.", strerror(errno));

posix_fadvise() does not set errno on error, it returns the error code directly. I have merged an alternative fix as:

commit c7a78aabfa0491974d4ffc188d72eb1e67c7344e

Author: Jérémie Galarneau <[email protected]>
Date:   Tue May 17 12:17:05 2016 -0400

Fix: unchecked posix_fadvise() return value

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

Quoted 5 lines

I also set this to WARN() since we'd probably want to know if we're misusing posix_fadvise or passing a bad FD, etc.

On our FreeBSD port, our posix_fadvise wrapper returns an error. Since we don't care about reporting this as a warning, I chose DBG() here.

Thoughts ?

Thanks,

Mathieu

Quoted 20 lines

Thanks!
Jérémie

Quoted 7 lines
src/common/consumer/consumer.c +1 -0
+       }
 }
 

/*
--
2.1.4

--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 52 lines · Mathieu Desnoyers
Quoted 50 lines · ----- On May 18, 2016, at 3:26 PM, Jeremie Galarneau…
Quoted 18 lines · Mathieu Desnoyers

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

---
 src/common/consumer/consumer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/common/consumer/consumer.c +0 -0
index cb05a1e..e22de4d 100644

src/common/consumer/consumer.c void lttng_consumer_sync_trace_file(struct · line 1268

Quoted 9 lines
src/common/consumer/consumer.c +3 -2
@@ -1262,8 +1262,10 @@ void lttng_consumer_sync_trace_file(struct
 lttng_consumer_stream *stream,
         * defined. So it can be expected to lead to lower throughput in
         * streaming.
         */
-       posix_fadvise(outfd, orig_offset - stream->max_sb_size,
-                       stream->max_sb_size, POSIX_FADV_DONTNEED);
+       if (posix_fadvise(outfd, orig_offset - stream->max_sb_size,
+                       stream->max_sb_size, POSIX_FADV_DONTNEED)) {
+               DBG("Ignoring posix_fadvise() error: %s.", strerror(errno));

posix_fadvise() does not set errno on error, it returns the error code directly. I have merged an alternative fix as:

commit c7a78aabfa0491974d4ffc188d72eb1e67c7344e

Author: Jérémie Galarneau <[email protected]>
Date:   Tue May 17 12:17:05 2016 -0400

Fix: unchecked posix_fadvise() return value

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

Quoted 8 lines
Quoted 2 lines

I also set this to WARN() since we'd probably want to know if we're misusing posix_fadvise or passing a bad FD, etc.

On our FreeBSD port, our posix_fadvise wrapper returns an error. Since we don't care about reporting this as a warning, I chose DBG() here.

Thoughts ?

Good point. I agree with the use of "return -ENOSYS" in the other wrappers, but given the nature of posix_fadvise(), I would change the behavior of this wrapper to a no-op (return 0).

What do you think?

Jérémie

Quoted 30 lines

Thanks,

Mathieu

Quoted 16 lines

Thanks!
Jérémie

Quoted 7 lines
src/common/consumer/consumer.c +1 -0
+       }
 }
 

/*
--
2.1.4

Quoted 4 lines

--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Signature · 7 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): CA+jJMxsjBwQ5FZHJqhN1d=LH-tGFUy6UOLpamkK8ZisE82e8bg@mail.gmail.com

#7 lore raw
Quoted 62 lines · ----- On May 18, 2016, at 3:40 PM, Jeremie Galarneau…
Quoted 60 lines · Mathieu Desnoyers

----- On May 18, 2016, at 3:26 PM, Jeremie Galarneau

Quoted 47 lines · [email protected] wrote:
Quoted 18 lines · Mathieu Desnoyers

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

---
 src/common/consumer/consumer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/common/consumer/consumer.c +0 -0
index cb05a1e..e22de4d 100644

src/common/consumer/consumer.c void lttng_consumer_sync_trace_file(struct · line 1268

Quoted 9 lines
src/common/consumer/consumer.c +3 -2
@@ -1262,8 +1262,10 @@ void lttng_consumer_sync_trace_file(struct
 lttng_consumer_stream *stream,
         * defined. So it can be expected to lead to lower throughput in
         * streaming.
         */
-       posix_fadvise(outfd, orig_offset - stream->max_sb_size,
-                       stream->max_sb_size, POSIX_FADV_DONTNEED);
+       if (posix_fadvise(outfd, orig_offset - stream->max_sb_size,
+                       stream->max_sb_size, POSIX_FADV_DONTNEED)) {
+               DBG("Ignoring posix_fadvise() error: %s.", strerror(errno));

posix_fadvise() does not set errno on error, it returns the error code directly. I have merged an alternative fix as:

commit c7a78aabfa0491974d4ffc188d72eb1e67c7344e

Author: Jérémie Galarneau <[email protected]>
Date:   Tue May 17 12:17:05 2016 -0400

Fix: unchecked posix_fadvise() return value

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

Quoted 5 lines

I also set this to WARN() since we'd probably want to know if we're misusing posix_fadvise or passing a bad FD, etc.

On our FreeBSD port, our posix_fadvise wrapper returns an error. Since we don't care about reporting this as a warning, I chose DBG() here.

Quoted 7 lines
Quoted 1 line

Thoughts ?

Good point. I agree with the use of "return -ENOSYS" in the other wrappers, but given the nature of posix_fadvise(), I would change the behavior of this wrapper to a no-op (return 0).

What do you think?

Well it's just "not implemented" ;)

I would keep the return -ENOSYS, and in the caller:

if (ret == -ENOSYS) {
DBG();....
} else {
errno = -ret;
PERROR();....
}

Thoughts ?

Thanks,

Mathieu

Quoted 40 lines

Jérémie

Quoted 26 lines

Thanks,

Mathieu

Quoted 16 lines

Thanks!
Jérémie

Quoted 7 lines
src/common/consumer/consumer.c +1 -0
+       }
 }
 

/*
--
2.1.4

Quoted 4 lines

--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

Quoted 4 lines

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 74 lines · Mathieu Desnoyers
Quoted 62 lines · ----- On May 18, 2016, at 3:40 PM, Jeremie Galarneau…
Quoted 60 lines · Mathieu Desnoyers

----- On May 18, 2016, at 3:26 PM, Jeremie Galarneau

Quoted 47 lines · [email protected] wrote:
Quoted 18 lines · Mathieu Desnoyers

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

---
 src/common/consumer/consumer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/common/consumer/consumer.c +0 -0
index cb05a1e..e22de4d 100644

src/common/consumer/consumer.c void lttng_consumer_sync_trace_file(struct · line 1268

Quoted 9 lines
src/common/consumer/consumer.c +3 -2
@@ -1262,8 +1262,10 @@ void lttng_consumer_sync_trace_file(struct
 lttng_consumer_stream *stream,
         * defined. So it can be expected to lead to lower throughput in
         * streaming.
         */
-       posix_fadvise(outfd, orig_offset - stream->max_sb_size,
-                       stream->max_sb_size, POSIX_FADV_DONTNEED);
+       if (posix_fadvise(outfd, orig_offset - stream->max_sb_size,
+                       stream->max_sb_size, POSIX_FADV_DONTNEED)) {
+               DBG("Ignoring posix_fadvise() error: %s.", strerror(errno));

posix_fadvise() does not set errno on error, it returns the error code directly. I have merged an alternative fix as:

commit c7a78aabfa0491974d4ffc188d72eb1e67c7344e

Author: Jérémie Galarneau <[email protected]>
Date:   Tue May 17 12:17:05 2016 -0400

Fix: unchecked posix_fadvise() return value

Found by Coverity:

CID 1019971 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)2. check_return: Calling posix_fadvise(outfd, orig_offset - stream->max_sb_size, stream->max_sb_size, 4) without checking return value. This library function may fail and return an error code.

Quoted 5 lines

I also set this to WARN() since we'd probably want to know if we're misusing posix_fadvise or passing a bad FD, etc.

On our FreeBSD port, our posix_fadvise wrapper returns an error. Since we don't care about reporting this as a warning, I chose DBG() here.

Quoted 7 lines
Quoted 1 line

Thoughts ?

Good point. I agree with the use of "return -ENOSYS" in the other wrappers, but given the nature of posix_fadvise(), I would change the behavior of this wrapper to a no-op (return 0).

What do you think?

Well it's just "not implemented" ;)

Quoted 8 lines

I would keep the return -ENOSYS, and in the caller:

if (ret == -ENOSYS) {
DBG();....
} else {
errno = -ret;
PERROR();....
}

Looks good to me. I'll add this in.

Thanks,
Jérémie

Quoted 52 lines

Thoughts ?

Thanks,

Mathieu

Quoted 36 lines

Jérémie

Quoted 26 lines

Thanks,

Mathieu

Quoted 16 lines

Thanks!
Jérémie

Quoted 7 lines
src/common/consumer/consumer.c +1 -0
+       }
 }
 

/*
--
2.1.4

Quoted 4 lines

--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

Quoted 4 lines

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Quoted 4 lines

--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Signature · 7 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev