[vhffs-dev] [1347] fixed bug when fd is 0 (which can happen when stdin,stdout, stderr are closed) |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1347
Author: gradator
Date: 2009-02-20 03:49:12 +0100 (Fri, 20 Feb 2009)
Log Message:
-----------
fixed bug when fd is 0 (which can happen when stdin,stdout,stderr are closed)
Modified Paths:
--------------
trunk/vhffs-stsmon/stsmon.c
Modified: trunk/vhffs-stsmon/stsmon.c
===================================================================
--- trunk/vhffs-stsmon/stsmon.c 2009-02-20 02:32:06 UTC (rev 1346)
+++ trunk/vhffs-stsmon/stsmon.c 2009-02-20 02:49:12 UTC (rev 1347)
@@ -153,10 +153,10 @@
int serialfd;
int status;
- int listencts = 0;
- int listencd = 0;
- int listenri = 0;
- int listendsr = 0;
+ int listencts = -1;
+ int listencd = -1;
+ int listenri = -1;
+ int listendsr = -1;
char *logfile = NULL;
char *device = "/dev/ttyS0";
@@ -291,24 +291,23 @@
// inputs
if( status & TIOCM_CTS ) {
// puts("CTS (clear to send)");
- if(!listencts) {
+ if(listencts < 0) {
listencts = stsmon_listentoport(bindaddr, baseport+0);
- if(listencts < 0) listencts = 0;
snprintf(line, 128, "%s on", namects);
addlogline(line, logfile);
}
}
else {
- if(listencts) {
+ if(listencts >= 0) {
close(listencts);
- listencts = 0;
+ listencts = -1;
snprintf(line, 128, "%s off", namects);
addlogline(line, logfile);
}
}
- while(listencts) {
+ while(listencts >= 0) {
int fd = accept(listencts, NULL, NULL);
if(fd < 0) break;
shutdown(fd, SHUT_RDWR);
@@ -317,24 +316,23 @@
if( status & TIOCM_CD ) {
// puts("DCD (data carrier detect)");
- if(!listencd) {
+ if(listencd < 0) {
listencd = stsmon_listentoport(bindaddr, baseport+1);
- if(listencd < 0) listencd = 0;
snprintf(line, 128, "%s on", namecd);
addlogline(line, logfile);
}
}
else {
- if(listencd) {
+ if(listencd >= 0) {
close(listencd);
- listencd = 0;
+ listencd = -1;
snprintf(line, 128, "%s off", namecd);
addlogline(line, logfile);
}
}
- while(listencd) {
+ while(listencd >= 0) {
int fd = accept(listencd, NULL, NULL);
if(fd < 0) break;
shutdown(fd, SHUT_RDWR);
@@ -343,24 +341,23 @@
if( status & TIOCM_RI ) {
// puts("RI (ring)");
- if(!listenri) {
+ if(listenri < 0) {
listenri = stsmon_listentoport(bindaddr, baseport+2);
- if(listenri < 0) listenri = 0;
snprintf(line, 128, "%s on", nameri);
addlogline(line, logfile);
}
}
else {
- if(listenri) {
+ if(listenri >= 0) {
close(listenri);
- listenri = 0;
+ listenri = -1;
snprintf(line, 128, "%s off", nameri);
addlogline(line, logfile);
}
}
- while(listenri) {
+ while(listenri >= 0) {
int fd = accept(listenri, NULL, NULL);
if(fd < 0) break;
shutdown(fd, SHUT_RDWR);
@@ -369,24 +366,23 @@
if( status & TIOCM_DSR ) {
// puts("DSR (data set ready)");
- if(!listendsr) {
+ if(listendsr < 0) {
listendsr = stsmon_listentoport(bindaddr, baseport+3);
- if(listendsr < 0) listendsr = 0;
snprintf(line, 128, "%s on", namedsr);
addlogline(line, logfile);
}
}
else {
- if(listendsr) {
+ if(listendsr >= 0) {
close(listendsr);
- listendsr = 0;
+ listendsr = -1;
snprintf(line, 128, "%s off", namedsr);
addlogline(line, logfile);
}
}
- while(listendsr) {
+ while(listendsr >= 0) {
int fd = accept(listendsr, NULL, NULL);
if(fd < 0) break;
shutdown(fd, SHUT_RDWR);