8 #include "auto_qmail.h"
11 #define FATAL "qmail-newmrh: fatal: "
15 strerr_die2sys(111,FATAL
,"unable to read control/morercpthosts: ");
19 strerr_die2sys(111,FATAL
,"unable to write to control/morercpthosts.tmp: ");
35 if (chdir(auto_qmail
) == -1)
36 strerr_die4sys(111,FATAL
,"unable to chdir to ",auto_qmail
,": ");
38 fd
= open_read("control/morercpthosts");
39 if (fd
== -1) die_read();
41 substdio_fdbuf(&ssin
,read
,fd
,inbuf
,sizeof inbuf
);
43 fdtemp
= open_trunc("control/morercpthosts.tmp");
44 if (fdtemp
== -1) die_write();
46 if (cdbmss_start(&cdbmss
,fdtemp
) == -1) die_write();
49 if (getln(&ssin
,&line
,&match
,'\n') != 0) die_read();
50 case_lowerb(line
.s
,line
.len
);
52 if (line
.s
[line
.len
- 1] == ' ') { --line
.len
; continue; }
53 if (line
.s
[line
.len
- 1] == '\n') { --line
.len
; continue; }
54 if (line
.s
[line
.len
- 1] == '\t') { --line
.len
; continue; }
56 if (cdbmss_add(&cdbmss
,line
.s
,line
.len
,"",0) == -1)
63 if (cdbmss_finish(&cdbmss
) == -1) die_write();
64 if (fsync(fdtemp
) == -1) die_write();
65 if (close(fdtemp
) == -1) die_write(); /* NFS stupidity */
66 if (rename("control/morercpthosts.tmp","control/morercpthosts.cdb") == -1)
67 strerr_die2sys(111,FATAL
,"unable to move control/morercpthosts.tmp to control/morercpthosts.cdb");