fix more fd <= 0 bugs
This commit is contained in:
parent
7e4d9a4bfa
commit
8562240e8c
|
@ -126,6 +126,7 @@ void setline(void);
|
|||
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*);
|
||||
|
@ -570,37 +571,6 @@ readraw(Req *r)
|
|||
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
|
||||
gettime(Fix *f){
|
||||
/* Convert zulu time and date to Plan9 time(2) */
|
||||
|
|
|
@ -142,15 +142,15 @@ strtopos(char *p, char **ep)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -265,9 +265,9 @@ querydestroy(Query *qp)
|
|||
{
|
||||
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 @@ readnet(Query *qp, int medium, uchar *ibuf, uvlong endms, uchar **replyp,
|
|||
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 @@ readnet(Query *qp, int medium, uchar *ibuf, uvlong endms, uchar **replyp,
|
|||
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 @@ mydnsquery(Query *qp, int medium, uchar *udppkt, int len)
|
|||
}
|
||||
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 @@ tcpquery(Query *qp, DNSmsg *mp, int depth, uchar *ibuf, uchar *obuf, int len,
|
|||
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);
|
||||
|
|
|
@ -86,11 +86,12 @@ char *tname[] = {
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue