comparison lib-src/movemail.c @ 25:b446124cdf5a

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Sun, 14 May 1989 22:52:53 +0000
parents b437d0778a66
children f60b88b46f97
comparison
equal deleted inserted replaced
24:2354a499c504 25:b446124cdf5a
50 50
51 #ifdef XENIX 51 #ifdef XENIX
52 #include <sys/locking.h> 52 #include <sys/locking.h>
53 #endif 53 #endif
54 54
55 #ifdef MAIL_USE_MMDF
56 extern int lk_open (), lk_close ();
57 #endif
58
55 /* Cancel substitutions made by config.h for Emacs. */ 59 /* Cancel substitutions made by config.h for Emacs. */
56 #undef open 60 #undef open
57 #undef read 61 #undef read
58 #undef write 62 #undef write
59 #undef close 63 #undef close
87 if (argc < 3) 91 if (argc < 3)
88 fatal ("two arguments required"); 92 fatal ("two arguments required");
89 93
90 inname = argv[1]; 94 inname = argv[1];
91 outname = argv[2]; 95 outname = argv[2];
96
97 #ifdef MAIL_USE_MMDF
98 mmdf_init (argv[0]);
99 #endif
92 100
93 /* Check access to input and output file. */ 101 /* Check access to input and output file. */
94 if (access (inname, R_OK | W_OK) != 0) 102 if (access (inname, R_OK | W_OK) != 0)
95 pfatal_with_name (inname); 103 pfatal_with_name (inname);
96 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0) 104 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
122 } 130 }
123 131
124 setuid (getuid()); 132 setuid (getuid());
125 #endif /* MAIL_USE_POP */ 133 #endif /* MAIL_USE_POP */
126 134
135 #ifndef MAIL_USE_MMDF
127 #ifndef MAIL_USE_FLOCK 136 #ifndef MAIL_USE_FLOCK
128 /* Use a lock file named /usr/spool/mail/$USER.lock: 137 /* Use a lock file named /usr/spool/mail/$USER.lock:
129 If it exists, the mail file is locked. */ 138 If it exists, the mail file is locked. */
130 lockname = concat (inname, ".lock", ""); 139 lockname = concat (inname, ".lock", "");
131 strcpy (tempname, inname); 140 strcpy (tempname, inname);
167 #ifdef MAIL_USE_FLOCK 176 #ifdef MAIL_USE_FLOCK
168 indesc = open (inname, O_RDWR); 177 indesc = open (inname, O_RDWR);
169 #else /* if not MAIL_USE_FLOCK */ 178 #else /* if not MAIL_USE_FLOCK */
170 indesc = open (inname, O_RDONLY); 179 indesc = open (inname, O_RDONLY);
171 #endif /* not MAIL_USE_FLOCK */ 180 #endif /* not MAIL_USE_FLOCK */
181 #else /* MAIL_USE_MMDF */
182 indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
183 #endif /* MAIL_USE_MMDF */
184
172 if (indesc < 0) 185 if (indesc < 0)
173 pfatal_with_name (inname); 186 pfatal_with_name (inname);
174 187
175 #if defined(BSD) || defined(XENIX) 188 #if defined(BSD) || defined(XENIX)
176 /* In case movemail is setuid to root, make sure the user can 189 /* In case movemail is setuid to root, make sure the user can
223 (void) close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); 236 (void) close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
224 #else 237 #else
225 (void) ftruncate (indesc, 0L); 238 (void) ftruncate (indesc, 0L);
226 #endif /* STRIDE or XENIX */ 239 #endif /* STRIDE or XENIX */
227 #endif /* MAIL_USE_FLOCK */ 240 #endif /* MAIL_USE_FLOCK */
241
242 #ifdef MAIL_USE_MMDF
243 lk_close (indesc, 0, 0, 0);
244 #else
228 close (indesc); 245 close (indesc);
246 #endif
229 247
230 #ifndef MAIL_USE_FLOCK 248 #ifndef MAIL_USE_FLOCK
231 /* Delete the input file; if we can't, at least get rid of its contents. */ 249 /* Delete the input file; if we can't, at least get rid of its contents. */
232 if (unlink (inname) < 0) 250 if (unlink (inname) < 0)
233 if (errno != ENOENT) 251 if (errno != ENOENT)
234 creat (inname, 0666); 252 creat (inname, 0666);
235 (void) unlink (lockname); 253 #ifndef MAIL_USE_MMDF
254 unlink (lockname);
255 #endif /* not MAIL_USE_MMDF */
236 #endif /* not MAIL_USE_FLOCK */ 256 #endif /* not MAIL_USE_FLOCK */
237 exit (0); 257 exit (0);
238 } 258 }
239 259
240 /* Print error message and exit. */ 260 /* Print error message and exit. */