]> code.delx.au - gnu-emacs/blobdiff - lib-src/movemail.c
Fix compilation with GC_MARK_STACK == GC_USE_GCPROS_AS_BEFORE.
[gnu-emacs] / lib-src / movemail.c
index 3ea4f4521c112e0d58d6a22dc8fd3ae8d7a3eb27..616cbde5394b43cfd1e53e3a5e1d107552b6dba7 100644 (file)
@@ -1,8 +1,8 @@
 /* movemail foo bar -- move file foo to file bar,
    locking file foo the way /bin/mail respects.
 
-Copyright (C) 1986, 1992-1994, 1996, 1999, 2001-2012
-  Free Software Foundation, Inc.
+Copyright (C) 1986, 1992-1994, 1996, 1999, 2001-2013 Free Software
+Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -22,7 +22,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Important notice: defining MAIL_USE_FLOCK or MAIL_USE_LOCKF *will
    cause loss of mail* if you do it on a system that does not normally
-   use flock as its way of interlocking access to inbox files.  The
+   use flock/lockf as its way of interlocking access to inbox files.  The
    setting of MAIL_USE_FLOCK and MAIL_USE_LOCKF *must agree* with the
    system's own conventions.  It is not a choice that is up to you.
 
@@ -65,9 +65,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <getopt.h>
 #include <unistd.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif
 #include <string.h>
 #include "syswait.h"
 #ifdef MAIL_USE_POP
@@ -98,17 +96,15 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <fcntl.h>
 #endif /* WINDOWSNT */
 
-#ifndef F_OK
-#define F_OK 0
-#define X_OK 1
-#define W_OK 2
-#define R_OK 4
-#endif
-
 #ifdef WINDOWSNT
 #include <sys/locking.h>
 #endif
 
+/* If your system uses the `flock' or `lockf' system call for mail locking,
+   define MAIL_USE_SYSTEM_LOCK.  If your system type should always define
+   MAIL_USE_LOCKF or MAIL_USE_FLOCK but configure does not do this,
+   please make a bug report.  */
+
 #ifdef MAIL_USE_LOCKF
 #define MAIL_USE_SYSTEM_LOCK
 #endif
@@ -289,13 +285,7 @@ main (int argc, char **argv)
         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 and recompile movemail.
-        If your system type should always define MAIL_USE_SYSTEM_LOCK
-        but does not, send a bug report to bug-gnu-emacs@gnu.org so we
-        can change the default in configure.  */
+        uses lock files for this purpose.  Some systems use other methods.  */
 
       inname_len = strlen (inname);
       lockname = xmalloc (inname_len + sizeof ".lock");
@@ -338,11 +328,8 @@ main (int argc, char **argv)
 
          tem = link (tempname, lockname);
 
-#ifdef EPERM
-         if (tem < 0 && errno == EPERM)
-           fatal ("Unable to create hard link between %s and %s",
-                  tempname, lockname);
-#endif
+         if (tem < 0 && errno != EEXIST)
+           pfatal_with_name (lockname);
 
          unlink (tempname);
          if (tem >= 0)
@@ -443,22 +430,10 @@ main (int argc, char **argv)
         for certain failure codes.  */
       if (status < 0)
        {
-         if (++lockcount <= 5)
+         if (++lockcount <= 5 && (errno == EAGAIN || errno == EBUSY))
            {
-#ifdef EAGAIN
-             if (errno == EAGAIN)
-               {
-                 sleep (1);
-                 goto retry_lock;
-               }
-#endif
-#ifdef EBUSY
-             if (errno == EBUSY)
-               {
-                 sleep (1);
-                 goto retry_lock;
-               }
-#endif
+             sleep (1);
+             goto retry_lock;
            }
 
          pfatal_with_name (inname);