fix more fd <= 0 bugs
This commit is contained in:
parent
7e4d9a4bfa
commit
8562240e8c
4 changed files with 15 additions and 44 deletions
|
@ -126,6 +126,7 @@ void setline(void);
|
||||||
int getonechar(vlong*);
|
int getonechar(vlong*);
|
||||||
void getline(char*, int, vlong*);
|
void getline(char*, int, vlong*);
|
||||||
void putline(char*);
|
void putline(char*);
|
||||||
|
void rtcset(long t);
|
||||||
int gettime(Fix*);
|
int gettime(Fix*);
|
||||||
int getzulu(char *, Fix*);
|
int getzulu(char *, Fix*);
|
||||||
int getalt(char*, char*, Fix*);
|
int getalt(char*, char*, Fix*);
|
||||||
|
@ -570,37 +571,6 @@ readraw(Req *r)
|
||||||
return nil;
|
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
|
int
|
||||||
gettime(Fix *f){
|
gettime(Fix *f){
|
||||||
/* Convert zulu time and date to Plan9 time(2) */
|
/* Convert zulu time and date to Plan9 time(2) */
|
||||||
|
|
|
@ -142,15 +142,15 @@ strtopos(char *p, char **ep)
|
||||||
return pl;
|
return pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
rtcset(long t) /* We may use this some day */
|
rtcset(long t)
|
||||||
{
|
{
|
||||||
static int fd;
|
static int fd = -1;
|
||||||
long r;
|
long r;
|
||||||
int n;
|
int n;
|
||||||
char buf[32];
|
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");
|
fprint(2, "Can't open #r/rtc: %r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,9 +265,9 @@ querydestroy(Query *qp)
|
||||||
{
|
{
|
||||||
queryck(qp);
|
queryck(qp);
|
||||||
/* leave udpfd open */
|
/* leave udpfd open */
|
||||||
if (qp->tcpfd > 0)
|
if (qp->tcpfd >= 0)
|
||||||
close(qp->tcpfd);
|
close(qp->tcpfd);
|
||||||
if (qp->tcpctlfd > 0) {
|
if (qp->tcpctlfd >= 0) {
|
||||||
hangup(qp->tcpctlfd);
|
hangup(qp->tcpctlfd);
|
||||||
close(qp->tcpctlfd);
|
close(qp->tcpctlfd);
|
||||||
}
|
}
|
||||||
|
@ -666,7 +666,7 @@ readnet(Query *qp, int medium, uchar *ibuf, uvlong endms, uchar **replyp,
|
||||||
memset(srcip, 0, IPaddrlen);
|
memset(srcip, 0, IPaddrlen);
|
||||||
alarm(ms);
|
alarm(ms);
|
||||||
if (medium == Udp)
|
if (medium == Udp)
|
||||||
if (qp->udpfd <= 0)
|
if (qp->udpfd < 0)
|
||||||
dnslog("readnet: qp->udpfd closed");
|
dnslog("readnet: qp->udpfd closed");
|
||||||
else {
|
else {
|
||||||
len = read(qp->udpfd, ibuf, Udphdrsize+Maxudpin);
|
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)
|
if (!qp->tcpset)
|
||||||
dnslog("readnet: tcp params not set");
|
dnslog("readnet: tcp params not set");
|
||||||
fd = qp->tcpfd;
|
fd = qp->tcpfd;
|
||||||
if (fd <= 0)
|
if (fd < 0)
|
||||||
dnslog("readnet: %s: tcp fd unset for dest %I",
|
dnslog("readnet: %s: tcp fd unset for dest %I",
|
||||||
qp->dp->name, qp->tcpip);
|
qp->dp->name, qp->tcpip);
|
||||||
else if (readn(fd, lenbuf, 2) != 2) {
|
else if (readn(fd, lenbuf, 2) != 2) {
|
||||||
|
@ -1003,7 +1003,7 @@ mydnsquery(Query *qp, int medium, uchar *udppkt, int len)
|
||||||
}
|
}
|
||||||
close(nfd);
|
close(nfd);
|
||||||
|
|
||||||
if (qp->udpfd <= 0)
|
if (qp->udpfd < 0)
|
||||||
dnslog("mydnsquery: qp->udpfd %d closed", qp->udpfd);
|
dnslog("mydnsquery: qp->udpfd %d closed", qp->udpfd);
|
||||||
else {
|
else {
|
||||||
if (write(qp->udpfd, udppkt, len+Udphdrsize) !=
|
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 ||
|
if (xmitquery(qp, Tcp, depth, obuf, inns, len) < 0 ||
|
||||||
readreply(qp, Tcp, req, ibuf, mp, endms) < 0)
|
readreply(qp, Tcp, req, ibuf, mp, endms) < 0)
|
||||||
rv = -1;
|
rv = -1;
|
||||||
if (qp->tcpfd > 0) {
|
if (qp->tcpfd >= 0) {
|
||||||
hangup(qp->tcpctlfd);
|
hangup(qp->tcpctlfd);
|
||||||
close(qp->tcpctlfd);
|
close(qp->tcpctlfd);
|
||||||
close(qp->tcpfd);
|
close(qp->tcpfd);
|
||||||
|
|
|
@ -86,11 +86,12 @@ char *tname[] = {
|
||||||
void
|
void
|
||||||
journal(int out, char *s)
|
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);
|
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
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue