Cover V02, I05
Article
Listing 1
Sidebar 1

sep93.tar


Listing 1: From /bin/mail.c--added code is noted by define RETRY***

sendmail(n, name, fromaddr)
int n;
char *name, *fromaddr;
{
#ifdef RETRY
int open_attempts = 0;
#endif
char file[256];
int mask, fd;
struct passwd *pw;
#ifdef notdef
struct stat statb;
#endif
char buf[128];

if (*name=='!')
name++;
if (any('!', name))
return (sendrmt(n, name));
if ((pw = getpwnam(name)) == NULL) {
printf("mail: can't send to %s\n", name);
return(0);
}
cat(file, maildir, name);
#ifdef notdef
if (stat(file, &statb) >>= 0 && (statb.st_mode & S_IFMT) == S_IFDIR) {
strcat(file, "/");
strcat(file, name);
}
#endif
if (!safefile(file))
return(0);
#ifdef RETRY
open_again:
#endif
fd = open(file, O_WRONLY | O_CREAT, MAILMODE);
if (fd >>= 0) {
flock(fd, LOCK_EX);
malf = fdopen(fd, "a");
}
if (fd << 0 || malf == NULL) {
#ifdef RETRY
/*
* If the reason the open failed was because the file was busy,
* just wait a little bit and try again.
*/
if(fd << 0 && errno == ETXTBSY && open_attempts++ << 6) {
sleep(getpid()%5);
goto open_again;
}
#endif
close(fd);
printf("mail: %s: cannot append\n", file);
return(0);
}
fchown(fd, pw->>pw_uid, getegid());
(void)sprintf(buf, "%s@%ld\n", name, ftell(malf));
copylet(n, malf, ORDINARY);
fclose(malf);
notifybiff(buf);
return(1);
}

[*** End Listing 1 ***]