changeset 447:2e226dcdaf0f

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Sat, 07 Dec 1991 22:01:44 +0000
parents 76b7a95526d3
children 129e6320092c
files lib-src/movemail.c
diffstat 1 files changed, 62 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/lib-src/movemail.c	Fri Dec 06 07:16:11 1991 +0000
+++ b/lib-src/movemail.c	Sat Dec 07 22:01:44 1991 +0000
@@ -29,7 +29,7 @@
  * 
  * New module: popmail.c
  * Modified routines:
- *	main - added code within #ifdef MAIL_USE_POP; added setuid(getuid())
+ *	main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ())
  *		after POP code. 
  * New routines in movemail.c:
  *	get_errmsg - return pointer to system error message
@@ -133,7 +133,7 @@
       exit (status);
     }
 
-  setuid (getuid());
+  setuid (getuid ());
 #endif /* MAIL_USE_POP */
 
   /* Check access to input file.  */
@@ -173,7 +173,7 @@
   *p = 0;
   strcpy (p, "EXXXXXX");
   mktemp (tempname);
-  (void) unlink (tempname);
+  unlink (tempname);
 
   while (1)
     {
@@ -185,7 +185,7 @@
       close (desc);
 
       tem = link (tempname, lockname);
-      (void) unlink (tempname);
+      unlink (tempname);
       if (tem >= 0)
 	break;
       sleep (1);
@@ -195,7 +195,7 @@
 	{
 	  now = time (0);
 	  if (st.st_ctime < now - 60)
-	    (void) unlink (lockname);
+	    unlink (lockname);
 	}
     }
 
@@ -214,7 +214,7 @@
   if (indesc < 0)
     pfatal_with_name (inname);
 
-#if defined(BSD) || defined(XENIX)
+#if defined (BSD) || defined (XENIX)
   /* In case movemail is setuid to root, make sure the user can
      read the output file.  */
   /* This is desirable for all systems
@@ -238,7 +238,7 @@
       if (nread != write (outdesc, buf, nread))
 	{
 	  int saved_errno = errno;
-	  (void) unlink (outname);
+	  unlink (outname);
 	  errno = saved_errno;
 	  pfatal_with_name (outname);
 	}
@@ -247,24 +247,20 @@
     }
 
 #ifdef BSD
-  fsync (outdesc);
+  if (fsync (outdesc) < 0)
+    pfatal_and_delete (outname);
 #endif
 
   /* Check to make sure no errors before we zap the inbox.  */
   if (close (outdesc) != 0)
-    {
-      int saved_errno = errno;
-      (void) unlink (outname);
-      errno = saved_errno;
-      pfatal_with_name (outname);
-  }
+    pfatal_and_delete (outname);
 
 #ifdef MAIL_USE_FLOCK
-#if defined(STRIDE) || defined(XENIX)
+#if defined (STRIDE) || defined (XENIX)
   /* Stride, xenix have file locking, but no ftruncate.  This mess will do. */
-  (void) close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
+  close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
 #else
-  (void) ftruncate (indesc, 0L);
+  ftruncate (indesc, 0L);
 #endif /* STRIDE or XENIX */
 #endif /* MAIL_USE_FLOCK */
 
@@ -321,6 +317,22 @@
   fatal (s, name);
 }
 
+pfatal_and_delete (name)
+     char *name;
+{
+  extern int errno, sys_nerr;
+  extern char *sys_errlist[];
+  char *s;
+
+  if (errno < sys_nerr)
+    s = concat ("", sys_errlist[errno], " for %s");
+  else
+    s = "cannot open %s";
+
+  unlink (name);
+  fatal (s, name);
+}
+
 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3.  */
 
 char *
@@ -402,29 +414,25 @@
 
   if (pop_init (host) == NOTOK)
     {
-      error (Errmsg);
-      return 1;
+      fatal (Errmsg);
     }
 
   if (getline (response, sizeof response, sfi) != OK)
     {
-      error (response);
-      return 1;
+      fatal (response);
     }
 
-  if (pop_command ("USER %s", user) == NOTOK 
+  if (pop_command ("USER %s", user) == NOTOK
       || pop_command ("RPOP %s", user) == NOTOK)
     {
-      error (Errmsg);
       pop_command ("QUIT");
-      return 1;
+      fatal (Errmsg);
     }
 
   if (pop_stat (&nmsgs, &nbytes) == NOTOK)
     {
-      error (Errmsg);
       pop_command ("QUIT");
-      return 1;
+      fatal (Errmsg);
     }
 
   if (!nmsgs)
@@ -437,18 +445,14 @@
   if (mbfi < 0)
     {
       pop_command ("QUIT");
-      error ("Error in open: %s, %s", get_errmsg (), outfile);
-      return 1;
+      pfatal_and_delete (outfile);
     }
   fchown (mbfi, getuid (), -1);
 
   if ((mbf = fdopen (mbfi, "w")) == NULL)
     {
       pop_command ("QUIT");
-      error ("Error in fdopen: %s", get_errmsg ());
-      close (mbfi);
-      unlink (outfile);
-      return 1;
+      pfatal_and_delete (outfile);
     }
 
   for (i = 1; i <= nmsgs; i++)
@@ -456,29 +460,37 @@
       mbx_delimit_begin (mbf);
       if (pop_retr (i, mbx_write, mbf) != OK)
 	{
-	  error (Errmsg);
 	  pop_command ("QUIT");
 	  close (mbfi);
-	  return 1;
+	  unlink (outfile);
+	  fatal (Errmsg);
 	}
       mbx_delimit_end (mbf);
       fflush (mbf);
     }
 
+  if (fsync (mbfi) < 0)
+    {
+      pop_command ("QUIT");
+      pfatal_and_delete (outfile);
+    }
+
+  if (close (mbfi) == -1)
+    {
+      pop_command ("QUIT");
+      pfatal_and_delete (outfile);
+    }
+
   for (i = 1; i <= nmsgs; i++)
     {
       if (pop_command ("DELE %d", i) == NOTOK)
 	{
-	  error (Errmsg);
-	  pop_command ("QUIT");
-	  close (mbfi);
-	  return 1;
+	  /* Better to ignore this failure.  */
 	}
     }
 
   pop_command ("QUIT");
-  close (mbfi);
-  return 0;
+  return (0);
 }
 
 pop_init (host)
@@ -550,7 +562,8 @@
       return NOTOK;
     }
 
-  if (debug) fprintf (stderr, "<--- %s\n", buf);
+  if (debug)
+    fprintf (stderr, "<--- %s\n", buf);
   if (*buf != '+')
     {
       strcpy (Errmsg, buf);
@@ -568,8 +581,10 @@
 {
   char buf[128];
 
-  if (debug) fprintf (stderr, "---> STAT\n");
-  if (putline ("STAT", Errmsg, sfo) == NOTOK) return NOTOK;
+  if (debug)
+    fprintf (stderr, "---> STAT\n");
+  if (putline ("STAT", Errmsg, sfo) == NOTOK)
+    return NOTOK;
 
   if (getline (buf, sizeof buf, sfi) != OK)
     {
@@ -656,17 +671,14 @@
      register int n;
      FILE *f;
 {
-  if (getline (buf, n, f) != OK) return NOTOK;
+  if (getline (buf, n, f) != OK)
+    return NOTOK;
   if (*buf == '.')
     {
       if (*(buf+1) == NULL)
-	{
-	  return DONE;
-	}
+	return DONE;
       else
-	{
-	  strcpy (buf, buf+1);
-	}
+	strcpy (buf, buf+1);
     }
   return OK;
 }