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
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;
}