- /* Create the lock file, but not under the lock file name. */
- /* Give up if cannot do that. */
- desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666);
- if (desc < 0)
- pfatal_with_name ("lock file--see source file lib-src/movemail.c");
- close (desc);
-
- tem = link (tempname, lockname);
+ /* Use a lock file named after our first argument with .lock appended:
+ If it exists, the mail file is locked. */
+ /* Note: this locking mechanism is *required* by the mailer
+ (on systems which use it) to prevent loss of mail.
+
+ On systems that use a lock file, extracting the mail without locking
+ WILL occasionally cause loss of mail due to timing errors!
+
+ So, if creation of the lock file fails
+ due to access permission on the mail spool directory,
+ you simply MUST change the permission
+ and/or make movemail a setgid program
+ so it can create lock files properly.
+
+ You might also wish to verify that your system is one
+ which uses lock files for this purpose. Some systems use other methods.
+
+ If your system uses the `flock' system call for mail locking,
+ define MAIL_USE_SYSTEM_LOCK in config.h or the s-*.h file
+ and recompile movemail. If the s- file for your system
+ should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report
+ to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
+
+ lockname = concat (inname, ".lock", "");
+ tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
+ strcpy (tempname, inname);
+ p = tempname + strlen (tempname);
+ while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
+ p--;
+ *p = 0;
+ strcpy (p, "EXXXXXX");
+ mktemp (tempname);