/sys/src/cmd/upas/smtp/mxdial.c
% cat >/sys/lib/dist/changes/1176838212.2.txt << EOF
• Style cleanup
• Alarm if we can't resolve within 60s.
EOF
[geoff] --rw-rw-r-- M 64 glenda sys 6567 Apr 17 15:19 sys/src/cmd/upas/smtp/mxdial.c
/n/sourcesdump/2007/0417/plan9/sys/src/cmd/upas/smtp/mxdial.c:79,85 -
/n/sourcesdump/2007/0418/plan9/sys/src/cmd/upas/smtp/mxdial.c:79,85
}
/* refuse to honor loopback addresses given by dns */
- for(i = 0; i < nmx; i++){
+ for(i = 0; i < nmx; i++)
if(strcmp(mx[i].ip, "127.0.0.1") == 0){
if(debug)
fprint(2, "mxlookup returns loopback\n");
/n/sourcesdump/2007/0417/plan9/sys/src/cmd/upas/smtp/mxdial.c:86,92 -
/n/sourcesdump/2007/0418/plan9/sys/src/cmd/upas/smtp/mxdial.c:86,91
werrstr("illegal: domain lists 127.0.0.1 as mail server");
return -1;
}
- }
/* sort by preference */
if(nmx > 1)
/n/sourcesdump/2007/0417/plan9/sys/src/cmd/upas/smtp/mxdial.c:123,131 -
/n/sourcesdump/2007/0418/plan9/sys/src/cmd/upas/smtp/mxdial.c:122,130
/* just in case we find no domain name */
strcpy(domain, ds->host);
- if(ds->netdir){
+ if(ds->netdir)
n = mxlookup1(ds, domain);
- } else {
+ else {
ds->netdir = "/net";
n = mxlookup1(ds, domain);
if(n == 0) {
/n/sourcesdump/2007/0417/plan9/sys/src/cmd/upas/smtp/mxdial.c:140,149 -
/n/sourcesdump/2007/0418/plan9/sys/src/cmd/upas/smtp/mxdial.c:139,148
static int
mxlookup1(DS *ds, char *domain)
{
- char buf[1024];
- char dnsname[Maxstring];
- char *fields[4];
int i, n, fd, nmx;
+ long oalarm;
+ char buf[1024], dnsname[Maxstring];
+ char *fields[4];
snprint(dnsname, sizeof dnsname, "%s/dns", ds->netdir);
/n/sourcesdump/2007/0417/plan9/sys/src/cmd/upas/smtp/mxdial.c:152,161 -
/n/sourcesdump/2007/0418/plan9/sys/src/cmd/upas/smtp/mxdial.c:151,167
return 0;
nmx = 0;
- snprint(buf, sizeof(buf), "%s mx", ds->host);
+ snprint(buf, sizeof buf, "%s mx", ds->host);
if(debug)
fprint(2, "sending %s '%s'\n", dnsname, buf);
+ /*
+ * don't hang indefinitely in the write to /net/dns.
+ */
+ atnotify(timeout, 1);
+ oalarm = alarm(60*1000);
n = write(fd, buf, strlen(buf));
+ alarm(oalarm);
+ atnotify(timeout, 0);
if(n < 0){
rerrstr(buf, sizeof buf);
if(debug)
/n/sourcesdump/2007/0417/plan9/sys/src/cmd/upas/smtp/mxdial.c:170,176 -
/n/sourcesdump/2007/0418/plan9/sys/src/cmd/upas/smtp/mxdial.c:176,182
* get any mx entries
*/
seek(fd, 0, 0);
- while(nmx < Nmx && (n = read(fd, buf, sizeof(buf)-1)) > 0){
+ while(nmx < Nmx && (n = read(fd, buf, sizeof buf-1)) > 0){
buf[n] = 0;
if(debug)
fprint(2, "dns mx: %s\n", buf);
/n/sourcesdump/2007/0417/plan9/sys/src/cmd/upas/smtp/mxdial.c:227,233 -
/n/sourcesdump/2007/0418/plan9/sys/src/cmd/upas/smtp/mxdial.c:233,239
mx[i] = mx[nmx];
i--;
}
- return nmx;
+ return nmx;
}
static int
/n/sourcesdump/2007/0417/plan9/sys/src/cmd/upas/smtp/mxdial.c:291,297 -
/n/sourcesdump/2007/0418/plan9/sys/src/cmd/upas/smtp/mxdial.c:297,303
return;
}
- snprint(buf, sizeof(buf), "!ipinfo %s", ds->host+1); // +1 to skip $
+ snprint(buf, sizeof buf, "!ipinfo %s", ds->host+1); // +1 to skip $
if(write(fd, buf, strlen(buf)) <= 0){
if(debug)
fprint(2, "write %s: %r\n", cs);
|