ref: 8562240e8c0222a2bf5f666218cbce01bfae0f62
parent: 7e4d9a4bfa2148c07930dd45b4e7d3071ff6180e
author: cinap_lenrek <[email protected]>
date: Tue Apr 24 02:57:02 EDT 2012
fix more fd <= 0 bugs
--- a/sys/src/cmd/aux/gps/gpsfs.c
+++ b/sys/src/cmd/aux/gps/gpsfs.c
@@ -126,6 +126,7 @@
int getonechar(vlong*);
void getline(char*, int, vlong*);
void putline(char*);
+void rtcset(long t);
int gettime(Fix*);
int getzulu(char *, Fix*);
int getalt(char*, char*, Fix*);
@@ -568,37 +569,6 @@
rawout += n;
}
return nil;
-}
-
-void
-rtcset(long t)
-{
- static int fd;
- long r;
- int n;
- char buf[32];
-
- if(fd <= 0 && (fd = open("#r/rtc", ORDWR)) < 0){
- fprint(2, "Can't open #r/rtc: %r\n");
- return;
- }
- n = read(fd, buf, sizeof buf - 1);
- if(n <= 0){
- fprint(2, "Can't read #r/rtc: %r\n");
- return;
- }
- buf[n] = '\0';
- r = strtol(buf, nil, 0);
- if(r <= 0){
- fprint(2, "ridiculous #r/rtc: %ld\n", r);
- return;
- }
- if(r - t > 1 || t - r > 0){
- seek(fd, 0, 0);
- fprint(fd, "%ld", t);
- fprint(2, "correcting #r/rtc: %ld → %ld\n", r, t);
- }
- seek(fd, 0, 0);
}
int
--- a/sys/src/cmd/aux/gps/util.c
+++ b/sys/src/cmd/aux/gps/util.c
@@ -142,15 +142,15 @@
return pl;
}
-static void
-rtcset(long t) /* We may use this some day */
+void
+rtcset(long t)
{
- static int fd;
+ static int fd = -1;
long r;
int n;
char buf[32];
- if(fd <= 0 && (fd = open("#r/rtc", ORDWR)) < 0){
+ if(fd < 0 && (fd = open("#r/rtc", ORDWR)) < 0){
fprint(2, "Can't open #r/rtc: %r\n");
return;
}
--- a/sys/src/cmd/ndb/dnresolve.c
+++ b/sys/src/cmd/ndb/dnresolve.c
@@ -265,9 +265,9 @@
{
queryck(qp);
/* leave udpfd open */
- if (qp->tcpfd > 0)
+ if (qp->tcpfd >= 0)
close(qp->tcpfd);
- if (qp->tcpctlfd > 0) {
+ if (qp->tcpctlfd >= 0) {
hangup(qp->tcpctlfd);
close(qp->tcpctlfd);
}
@@ -666,7 +666,7 @@
memset(srcip, 0, IPaddrlen);
alarm(ms);
if (medium == Udp)
- if (qp->udpfd <= 0)
+ if (qp->udpfd < 0)
dnslog("readnet: qp->udpfd closed");
else {
len = read(qp->udpfd, ibuf, Udphdrsize+Maxudpin);
@@ -683,7 +683,7 @@
if (!qp->tcpset)
dnslog("readnet: tcp params not set");
fd = qp->tcpfd;
- if (fd <= 0)
+ if (fd < 0)
dnslog("readnet: %s: tcp fd unset for dest %I",
qp->dp->name, qp->tcpip);
else if (readn(fd, lenbuf, 2) != 2) {
@@ -1003,7 +1003,7 @@
}
close(nfd);
- if (qp->udpfd <= 0)
+ if (qp->udpfd < 0)
dnslog("mydnsquery: qp->udpfd %d closed", qp->udpfd);
else {
if (write(qp->udpfd, udppkt, len+Udphdrsize) !=
@@ -1353,7 +1353,7 @@
if (xmitquery(qp, Tcp, depth, obuf, inns, len) < 0 ||
readreply(qp, Tcp, req, ibuf, mp, endms) < 0)
rv = -1;
- if (qp->tcpfd > 0) {
+ if (qp->tcpfd >= 0) {
hangup(qp->tcpctlfd);
close(qp->tcpctlfd);
close(qp->tcpfd);
--- a/sys/src/cmd/sam/mesg.c
+++ b/sys/src/cmd/sam/mesg.c
@@ -86,11 +86,12 @@
void
journal(int out, char *s)
{
- static int fd = 0;
+ static int fd = -1;
- if(fd <= 0)
+ if(fd < 0)
fd = create("/tmp/sam.out", 1, 0666L);
- fprint(fd, "%s%s\n", out? "out: " : "in: ", s);
+ if(fd >= 0)
+ fprint(fd, "%s%s\n", out? "out: " : "in: ", s);
}
void