[Nut-upsdev] [PATCH] disable nonblocking mode on serial port

Jim Paris jim at jtan.com
Wed Sep 24 21:21:50 UTC 2008


Hi,

I got a new Cyberpower 1500AVR UPS and nut wouldn't work.  It failed
to detect the UPS and a strace showed that all writes to the serial
port were failing with -EAGAIN.  The attached patch disabled
nonblocking mode on the serial port and now it works fine.

Is there a reason the port was put in non-blocking mode?  There's no
code I could find to deal with the inevitable -EAGAIN that you'd
receive on writes.  Maybe the delays introduced by ser_send_pace are
why it might work for some people?

-jim

--- nut-2.2.2/drivers/serial.c	2007-09-09 15:33:15.000000000 -0400
+++ nut-2.2.2-jim/drivers/serial.c	2008-09-24 16:55:32.000000000 -0400
@@ -133,12 +133,19 @@
 int ser_open(const char *port)
 {
 	int	fd;
+	int	flags;
 
 	fd = open(port, O_RDWR | O_NOCTTY | O_EXCL | O_NONBLOCK);
 
 	if (fd < 0)
 		ser_open_error(port);
 
+	if ((flags = fcntl(fd, F_GETFL, 0)) < 0)
+		ser_open_error(port);
+
+	if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) < 0)
+		ser_open_error(port);
+
 	lock_set(fd, port);
 
 	return fd;





More information about the Nut-upsdev mailing list