[PATCH] libosmocore[master]: serial.c: file descriptor '0' is a valid value

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Dec 24 17:00:34 UTC 2016


Review at  https://gerrit.osmocom.org/1503

serial.c: file descriptor '0' is a valid value

if stdin/stdout/stderr are all closed by our environment, it may very
well be that opening a serial port returns fd == 0.

Change-Id: Ifd9670260883a35da0629369e0d49e467d5b4d72
---
M src/serial.c
1 file changed, 2 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/03/1503/1

diff --git a/src/serial.c b/src/serial.c
index 6316e45..05bdc86 100644
--- a/src/serial.c
+++ b/src/serial.c
@@ -59,7 +59,7 @@
 int
 osmo_serial_init(const char *dev, speed_t baudrate)
 {
-	int rc, fd=0, v24, flags;
+	int rc, fd=-1, v24, flags;
 	struct termios tio;
 
 	/* Use nonblock as the device might block otherwise */
@@ -122,7 +122,7 @@
 	return fd;
 
 error:
-	if (fd)
+	if (fd >= 0)
 		close(fd);
 	return rc;
 }

-- 
To view, visit https://gerrit.osmocom.org/1503
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifd9670260883a35da0629369e0d49e467d5b4d72
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list