home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / mail / sendmail / 3051 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.5 KB  |  73 lines

  1. Newsgroups: comp.mail.sendmail
  2. Path: sparky!uunet!gatech!darwin.sura.net!udel!intercon!psinntp!monymsys!sonyd1.Broadcast.Sony.COM!blilly.UUCP!bruce
  3. From: bruce@blilly.UUCP (Bruce Lilly)
  4. Subject: Re: Trouble writing to a file
  5. References: <FULL_GL.92Dec19060740@dolphin.pts.mot.com> <1992Dec21.155057.1303@blilly.UUCP>
  6. Organization: Bruce Lilly
  7. Date: Mon, 21 Dec 92 16:24:54 GMT
  8. Message-ID: <1992Dec21.162454.1467@blilly.UUCP>
  9. Reply-To: lilb@sony.compuserve.com (Bruce Lilly)
  10. Lines: 61
  11.  
  12. In article <1992Dec21.155057.1303@blilly.UUCP> lilb@sony.compuserve.com (Bruce Lilly) wrote:
  13. >
  14. >Note that although the combination of sgid bit set and group execute bit not
  15. >set indicates that mandatory file locking should be used (on System V and
  16. >its derivatives), no file locks are set by the code, so it is possible for
  17. >two or more processes to write to the file at the same time, resulting in
  18. >gibberish.
  19.  
  20. The following patches, based on UIUC/IDA 5.65c, take care of locking the
  21. file being mailed to.  Your line numbers, as well as your mileage, may
  22. vary.
  23.  
  24. *** deliver.c    Mon Dec 21 11:17:26 1992
  25. --- deliver.c    Mon Dec 21 11:17:32 1992
  26. ***************
  27. *** 1560,1565
  28.           if (f == NULL)
  29.               exit(EX_CANTCREAT);
  30.   
  31.           putfromline(f, ProgMailer);
  32.           (*CurEnv->e_puthdr)(f, ProgMailer, CurEnv);
  33.           putline("", f, ProgMailer);
  34.  
  35. --- 1560,1576 -----
  36.           if (f == NULL)
  37.               exit(EX_CANTCREAT);
  38.   
  39. +         /* lock the file to prevent multiple processes's output from colliding */
  40. +         /* this works fine for System V derived systems, since mandatory file locking
  41. +             is enforced by the kernel, given the file modes
  42. +         */
  43. +         /* for systems w/o mandatory file locking, it will still prevent cooperating
  44. +             processes (probably only other sendmail processes) from trying to
  45. +             write simultaneously
  46. +         */
  47. +         /* complaints about BSD's lack of mandatory locking to Leffler, McKusick et. al. */
  48. +         (void) flock(fileno(f), LOCK_EX); /* block if locked */
  49.           putfromline(f, ProgMailer);
  50.           (*CurEnv->e_puthdr)(f, ProgMailer, CurEnv);
  51.           putline("", f, ProgMailer);
  52. ***************
  53. *** 1565,1570
  54.           putline("", f, ProgMailer);
  55.           (*CurEnv->e_putbody)(f, ProgMailer, CurEnv);
  56.           putline("", f, ProgMailer);
  57.           (void) fclose(f);
  58.           (void) fflush(stdout);
  59.   
  60.  
  61. --- 1576,1582 -----
  62.           putline("", f, ProgMailer);
  63.           (*CurEnv->e_putbody)(f, ProgMailer, CurEnv);
  64.           putline("", f, ProgMailer);
  65. +         /* closing the file drops the lock */
  66.           (void) fclose(f);
  67.           (void) fflush(stdout);
  68.   
  69. -- 
  70.     Bruce Lilly        blilly!bruce@Broadcast.Sony.COM
  71.                     ...uunet!sonyusa!sonyd1!blilly!bruce
  72.