LCDproc development and user support list

Text archives Help


[Lcdproc] sock_connect() bug


Chronological Thread 
  • From: fnacino AT internap.com (Frederick Nacino)
  • Subject: [Lcdproc] sock_connect() bug
  • Date: Fri May 5 19:43:02 2006

sock_connect() in shared/sockets.c is supposed to return a descriptor referencing the socket via the socket() function. 0 is a valid descriptor, however the sock_connect() code and a couple of the clients contradict that. I've included a patch that correctly assumes any descriptor above -1 is valid. People typically shouldn't run into this problem unless you finagle with environment as I have. Normally stdin will take up descriptor 0 eliminating the case where the socket() function can return a 0.

--
Frederick Nacino
Software Engineer, FCP Engineering
Internap Network Services
www.internap.com

diff -ur lcdproc-CVS-current-20060505/clients/lcdexec/lcdexec.c
lcdproc-fixes-20060505/clients/lcdexec/lcdexec.c
--- lcdproc-CVS-current-20060505/clients/lcdexec/lcdexec.c Sun Apr 30
00:00:35 2006
+++ lcdproc-fixes-20060505/clients/lcdexec/lcdexec.c Fri May 5 12:14:34
2006
@@ -226,7 +226,7 @@
report(RPT_INFO, "Connecting to %s:%d", address, port);

sock = sock_connect(address, port);
- if (sock <= 0) {
+ if (sock < 0) {
return -1;
}

diff -ur lcdproc-CVS-current-20060505/clients/lcdproc/iface.c
lcdproc-fixes-20060505/clients/lcdproc/iface.c
--- lcdproc-CVS-current-20060505/clients/lcdproc/iface.c Fri May 5
00:00:42 2006
+++ lcdproc-fixes-20060505/clients/lcdproc/iface.c Fri May 5 12:16:01
2006
@@ -138,7 +138,7 @@
/* Try to connect to server */
sock = sock_connect(server, port);

- if (sock <= 0) { /* there was some error and exit */
+ if (sock < 0) { /* there was some error and exit */
fprintf(stderr, "Error: Could not connect to %s:%d\n",
server, port);
exit(0);
}
diff -ur lcdproc-CVS-current-20060505/clients/lcdproc/main.c
lcdproc-fixes-20060505/clients/lcdproc/main.c
--- lcdproc-CVS-current-20060505/clients/lcdproc/main.c Sun Apr 30 00:00:35
2006
+++ lcdproc-fixes-20060505/clients/lcdproc/main.c Fri May 5 12:13:40
2006
@@ -278,7 +278,7 @@
// Connect to the server...
usleep(500000); // wait for the server to start up
sock = sock_connect(server, port);
- if (sock <= 0) {
+ if (sock < 0) {
fprintf(stderr, "Error connecting to LCD server %s on port
%d.\n"
"Check to see that the server is running and
operating normally.\n",
server, port);
diff -ur lcdproc-CVS-current-20060505/clients/lcdvc/lcd_link.c
lcdproc-fixes-20060505/clients/lcdvc/lcd_link.c
--- lcdproc-CVS-current-20060505/clients/lcdvc/lcd_link.c Sat Apr 29
00:00:30 2006
+++ lcdproc-fixes-20060505/clients/lcdvc/lcd_link.c Fri May 5 12:16:30
2006
@@ -41,7 +41,7 @@
report(RPT_INFO, "Connecting to %s:%d", address, port);

sock = sock_connect(address, port);
- if (sock <= 0) {
+ if (sock < 0) {
report(RPT_ERR, "Connecting to %s:%d failed", address, port);
return -1;
}
diff -ur lcdproc-CVS-current-20060505/shared/sockets.c
lcdproc-fixes-20060505/shared/sockets.c
--- lcdproc-CVS-current-20060505/shared/sockets.c Fri Apr 28 00:00:36
2006
+++ lcdproc-fixes-20060505/shared/sockets.c Fri May 5 12:20:12 2006
@@ -82,7 +82,7 @@
#endif
report (RPT_ERR, "sock_connect: connect failed");
shutdown (sock, SHUT_RDWR);
- return 0; // Normal
exit if server doesn't exist...
+ return -1;
}

#ifndef WINSOCK2



Archive powered by MHonArc 2.6.18.

Top of page