s += fmt_str(s,"tmp/");/*将"tmp/"拷到s中*/
s += fmt_ulong(s,time); *s++ = '.';/*将时间转化为字符串*/
s += fmt_ulong(s,pid); *s++ = '.';
s += fmt_strn(s,host,sizeof(host)); *s++ = 0;
if (stat(fntmptph,&st) == -1) if (errno == error_noent) break;
/* really should never get to this point */
if (loop == 2) _exit(1);
sleep(2);
}
str_copy(fnnewtph,fntmptph);
byte_copy(fnnewtph,3,"new");
//时间为24小时
alarm(86400);
fd = open_excl(fntmptph);
if (fd == -1) _exit(1);
///////////////////////////////////////////////////
substdio_fdbuf(&ss,read,0,buf,sizeof(buf));
substdio_fdbuf(&ssout,write,fd,outbuf,sizeof(outbuf));
//dtline:;邮件头Delivered-To部分
//rpline:;邮件头返回路径
//无需"From "头部
if (substdio_put(&ssout,rpline.s,rpline.len) == -1) goto fail;
if (substdio_put(&ssout,dtline.s,dtline.len) == -1) goto fail;
//将邮件写到文件fd中
switch(substdio_copy(&ssout,&ss))
{
case -2:; tryunlinktmp(); _exit(4);
case -3:; goto fail;
}
if (substdio_flush(&ssout) == -1) goto fail;
//将fd所指文件数据由系统缓冲区写回磁盘正确返回0,错误返回-1
if (fsync(fd) == -1) goto fail;
if (close(fd) == -1) goto fail; /* NFS dorks */
if (link(fntmptph,fnnewtph) == -1) goto fail;
/* if it was error_exist, almost certainly successful; i hate NFS */
tryunlinktmp(); _exit(0);
fail:; tryunlinktmp(); _exit(1);
}
/* end child process */
//maildir 格式邮箱的邮件投递,不要锁定
void maildir(fn)
char *fn;
{
int child;
int wstat;
//#define seek_begin(fd) (seek_set((fd),(seek_pos) 0))
//指向文件0的开头
if (seek_begin(0) == -1) temp_rewind();
switch(child = fork())
{
case -1:;
temp_fork();
case 0:;
maildir_child(fn);/////////////////////////////////////
_exit(111);
}
//返回子进程fd的结束状态值于wstat中
wait_pid(&wstat,child);
//#define wait_crashed(w) ((w) & 127)
if (wait_crashed(wstat))
temp_childcrashed();
//#define wait_exitcode(w) ((w) >> 8)
switch(wait_exitcode(wstat))
{
case 0:; break;
case 2:; strerr_die1x(111,"Unable to chdir to maildir. (#4.2.1)");
case 3:; strerr_die1x(111,"Timeout on maildir delivery. (#4.3.0)");
case 4:; strerr_die1x(111,"Unable to read message. (#4.3.0)");
default:; strerr_die1x(111,"Temporary error on maildir delivery. (#4.3.0)");
}
}
//mbox 格式邮箱的邮件投递,必须锁定
void mailfile(fn)
char *fn;
{
int fd;
substdio ss;
substdio ssout;
int match;
seek_pos pos;
int flaglocked;
//到文件0开头
if (seek_begin(0) == -1) temp_rewind();
//打开文件fn
fd = open_append(fn);