log: avoid call close with negative value

Message ID 20250205161518.143865-1-stephen@networkplumber.org (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers
Series log: avoid call close with negative value |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-abi-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS

Commit Message

Stephen Hemminger Feb. 5, 2025, 4:15 p.m. UTC
On error path, the journal socket code would call close
with -1 which caused Coverity warning.

Coverity issue: 448872
Fixes: 9da0dc6c0331 ("log: support systemd journal")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/log/log_journal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

David Marchand Feb. 7, 2025, 2:40 p.m. UTC | #1
On Wed, Feb 5, 2025 at 5:15 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On error path, the journal socket code would call close
> with -1 which caused Coverity warning.
>
> Coverity issue: 448872
> Fixes: 9da0dc6c0331 ("log: support systemd journal")
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Applied, thanks.
  

Patch

diff --git a/lib/log/log_journal.c b/lib/log/log_journal.c
index e9b3aa5640..43099649ed 100644
--- a/lib/log/log_journal.c
+++ b/lib/log/log_journal.c
@@ -116,7 +116,7 @@  log_journal_open(const char *id)
 		.sun_family = AF_UNIX,
 		.sun_path = "/run/systemd/journal/socket",
 	};
-	int jfd = -1;
+	int jfd;
 
 	len = snprintf(syslog_id, sizeof(syslog_id),
 		       "SYSLOG_IDENTIFIER=%s\nSYSLOG_PID=%u", id, getpid());
@@ -128,7 +128,7 @@  log_journal_open(const char *id)
 	jfd = socket(AF_UNIX, SOCK_DGRAM, 0);
 	if (jfd < 0) {
 		perror("socket");
-		goto error;
+		return NULL;
 	}
 
 	if (connect(jfd, (struct sockaddr *)&sun, sizeof(sun)) < 0) {