home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.mail.sendmail
- Path: sparky!uunet!gatech!darwin.sura.net!udel!intercon!psinntp!monymsys!sonyd1.Broadcast.Sony.COM!blilly.UUCP!bruce
- From: bruce@blilly.UUCP (Bruce Lilly)
- Subject: Re: Trouble writing to a file
- References: <FULL_GL.92Dec19060740@dolphin.pts.mot.com> <1992Dec21.155057.1303@blilly.UUCP>
- Organization: Bruce Lilly
- Date: Mon, 21 Dec 92 16:24:54 GMT
- Message-ID: <1992Dec21.162454.1467@blilly.UUCP>
- Reply-To: lilb@sony.compuserve.com (Bruce Lilly)
- Lines: 61
-
- In article <1992Dec21.155057.1303@blilly.UUCP> lilb@sony.compuserve.com (Bruce Lilly) wrote:
- >
- >Note that although the combination of sgid bit set and group execute bit not
- >set indicates that mandatory file locking should be used (on System V and
- >its derivatives), no file locks are set by the code, so it is possible for
- >two or more processes to write to the file at the same time, resulting in
- >gibberish.
-
- The following patches, based on UIUC/IDA 5.65c, take care of locking the
- file being mailed to. Your line numbers, as well as your mileage, may
- vary.
-
- *** deliver.c Mon Dec 21 11:17:26 1992
- --- deliver.c Mon Dec 21 11:17:32 1992
- ***************
- *** 1560,1565
- if (f == NULL)
- exit(EX_CANTCREAT);
-
- putfromline(f, ProgMailer);
- (*CurEnv->e_puthdr)(f, ProgMailer, CurEnv);
- putline("", f, ProgMailer);
-
- --- 1560,1576 -----
- if (f == NULL)
- exit(EX_CANTCREAT);
-
- + /* lock the file to prevent multiple processes's output from colliding */
- + /* this works fine for System V derived systems, since mandatory file locking
- + is enforced by the kernel, given the file modes
- + */
- + /* for systems w/o mandatory file locking, it will still prevent cooperating
- + processes (probably only other sendmail processes) from trying to
- + write simultaneously
- + */
- + /* complaints about BSD's lack of mandatory locking to Leffler, McKusick et. al. */
- + (void) flock(fileno(f), LOCK_EX); /* block if locked */
- +
- putfromline(f, ProgMailer);
- (*CurEnv->e_puthdr)(f, ProgMailer, CurEnv);
- putline("", f, ProgMailer);
- ***************
- *** 1565,1570
- putline("", f, ProgMailer);
- (*CurEnv->e_putbody)(f, ProgMailer, CurEnv);
- putline("", f, ProgMailer);
- (void) fclose(f);
- (void) fflush(stdout);
-
-
- --- 1576,1582 -----
- putline("", f, ProgMailer);
- (*CurEnv->e_putbody)(f, ProgMailer, CurEnv);
- putline("", f, ProgMailer);
- + /* closing the file drops the lock */
- (void) fclose(f);
- (void) fflush(stdout);
-
- --
- Bruce Lilly blilly!bruce@Broadcast.Sony.COM
- ...uunet!sonyusa!sonyd1!blilly!bruce
-