diff options
| author | Richard M. Stallman | 1994-04-05 23:04:36 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-05 23:04:36 +0000 |
| commit | 63cf923df4cc9c9858fa2543ba80b603262b6fad (patch) | |
| tree | af2a12cc5784dd5b87c245000df15bfabb663d91 /lib-src | |
| parent | 1e00c2ff9164aff0d12c5df4365a03ae169365a0 (diff) | |
| download | emacs-63cf923df4cc9c9858fa2543ba80b603262b6fad.tar.gz emacs-63cf923df4cc9c9858fa2543ba80b603262b6fad.zip | |
(main): Fix up MAIL_USE_MMDF conditional where
the indesc open was moved inside a fork.
Handle MAIL_USE_LOCKF.
(MAIL_USE_SYSTEM_LOCK): New conditional macro.
Define it if either MAIL_USE_FLOCK or MAIL_USE_LOCKF.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/movemail.c | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 67dca3ad6a9..1d63d385a42 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -18,11 +18,11 @@ You should have received a copy of the GNU General Public License | |||
| 18 | along with GNU Emacs; see the file COPYING. If not, write to | 18 | along with GNU Emacs; see the file COPYING. If not, write to |
| 19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | 19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | 20 | ||
| 21 | /* Important notice: defining MAIL_USE_FLOCK *will cause loss of mail* | 21 | /* Important notice: defining MAIL_USE_FLOCK or MAIL_USE_LOCKF *will |
| 22 | if you do it on a system that does not normally use flock as its way of | 22 | cause loss of mail* if you do it on a system that does not normally |
| 23 | interlocking access to inbox files. The setting of MAIL_USE_FLOCK | 23 | use flock as its way of interlocking access to inbox files. The |
| 24 | *must agree* with the system's own conventions. | 24 | setting of MAIL_USE_FLOCK and MAIL_USE_LOCKF *must agree* with the |
| 25 | It is not a choice that is up to you. | 25 | system's own conventions. It is not a choice that is up to you. |
| 26 | 26 | ||
| 27 | So, if your system uses lock files rather than flock, then the only way | 27 | So, if your system uses lock files rather than flock, then the only way |
| 28 | you can get proper operation is to enable movemail to write lockfiles there. | 28 | you can get proper operation is to enable movemail to write lockfiles there. |
| @@ -75,6 +75,14 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |||
| 75 | #include <sys/locking.h> | 75 | #include <sys/locking.h> |
| 76 | #endif | 76 | #endif |
| 77 | 77 | ||
| 78 | #ifdef MAIL_USE_LOCKF | ||
| 79 | #define MAIL_USE_SYSTEM_LOCK | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifdef MAIL_USE_FLOCK | ||
| 83 | #define MAIL_USE_SYSTEM_LOCK | ||
| 84 | #endif | ||
| 85 | |||
| 78 | #ifdef MAIL_USE_MMDF | 86 | #ifdef MAIL_USE_MMDF |
| 79 | extern int lk_open (), lk_close (); | 87 | extern int lk_open (), lk_close (); |
| 80 | #endif | 88 | #endif |
| @@ -103,14 +111,14 @@ main (argc, argv) | |||
| 103 | int nread; | 111 | int nread; |
| 104 | WAITTYPE status; | 112 | WAITTYPE status; |
| 105 | 113 | ||
| 106 | #ifndef MAIL_USE_FLOCK | 114 | #ifndef MAIL_USE_SYSTEM_LOCK |
| 107 | struct stat st; | 115 | struct stat st; |
| 108 | long now; | 116 | long now; |
| 109 | int tem; | 117 | int tem; |
| 110 | char *lockname, *p; | 118 | char *lockname, *p; |
| 111 | char *tempname; | 119 | char *tempname; |
| 112 | int desc; | 120 | int desc; |
| 113 | #endif /* not MAIL_USE_FLOCK */ | 121 | #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 114 | 122 | ||
| 115 | delete_lockname = 0; | 123 | delete_lockname = 0; |
| 116 | 124 | ||
| @@ -164,7 +172,7 @@ main (argc, argv) | |||
| 164 | pfatal_with_name (inname); | 172 | pfatal_with_name (inname); |
| 165 | 173 | ||
| 166 | #ifndef MAIL_USE_MMDF | 174 | #ifndef MAIL_USE_MMDF |
| 167 | #ifndef MAIL_USE_FLOCK | 175 | #ifndef MAIL_USE_SYSTEM_LOCK |
| 168 | /* Use a lock file named /usr/spool/mail/$USER.lock: | 176 | /* Use a lock file named /usr/spool/mail/$USER.lock: |
| 169 | If it exists, the mail file is locked. */ | 177 | If it exists, the mail file is locked. */ |
| 170 | /* Note: this locking mechanism is *required* by the mailer | 178 | /* Note: this locking mechanism is *required* by the mailer |
| @@ -183,9 +191,9 @@ main (argc, argv) | |||
| 183 | which uses lock files for this purpose. Some systems use other methods. | 191 | which uses lock files for this purpose. Some systems use other methods. |
| 184 | 192 | ||
| 185 | If your system uses the `flock' system call for mail locking, | 193 | If your system uses the `flock' system call for mail locking, |
| 186 | define MAIL_USE_FLOCK in config.h or the s-*.h file | 194 | define MAIL_USE_SYSTEM_LOCK in config.h or the s-*.h file |
| 187 | and recompile movemail. If the s- file for your system | 195 | and recompile movemail. If the s- file for your system |
| 188 | should define MAIL_USE_FLOCK but does not, send a bug report | 196 | should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report |
| 189 | to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ | 197 | to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ |
| 190 | 198 | ||
| 191 | lockname = concat (inname, ".lock", ""); | 199 | lockname = concat (inname, ".lock", ""); |
| @@ -224,17 +232,19 @@ main (argc, argv) | |||
| 224 | } | 232 | } |
| 225 | 233 | ||
| 226 | delete_lockname = lockname; | 234 | delete_lockname = lockname; |
| 227 | #endif /* not MAIL_USE_FLOCK */ | 235 | #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 236 | #endif /* not MAIL_USE_MMDF */ | ||
| 228 | 237 | ||
| 229 | if (fork () == 0) | 238 | if (fork () == 0) |
| 230 | { | 239 | { |
| 231 | seteuid (getuid ()); | 240 | seteuid (getuid ()); |
| 232 | 241 | ||
| 233 | #ifdef MAIL_USE_FLOCK | 242 | #ifndef MAIL_USE_MMDF |
| 243 | #ifdef MAIL_USE_SYSTEM_LOCK | ||
| 234 | indesc = open (inname, O_RDWR); | 244 | indesc = open (inname, O_RDWR); |
| 235 | #else /* if not MAIL_USE_FLOCK */ | 245 | #else /* if not MAIL_USE_SYSTEM_LOCK */ |
| 236 | indesc = open (inname, O_RDONLY); | 246 | indesc = open (inname, O_RDONLY); |
| 237 | #endif /* not MAIL_USE_FLOCK */ | 247 | #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 238 | #else /* MAIL_USE_MMDF */ | 248 | #else /* MAIL_USE_MMDF */ |
| 239 | indesc = lk_open (inname, O_RDONLY, 0, 0, 10); | 249 | indesc = lk_open (inname, O_RDONLY, 0, 0, 10); |
| 240 | #endif /* MAIL_USE_MMDF */ | 250 | #endif /* MAIL_USE_MMDF */ |
| @@ -252,13 +262,17 @@ main (argc, argv) | |||
| 252 | outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); | 262 | outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
| 253 | if (outdesc < 0) | 263 | if (outdesc < 0) |
| 254 | pfatal_with_name (outname); | 264 | pfatal_with_name (outname); |
| 255 | #ifdef MAIL_USE_FLOCK | 265 | #ifdef MAIL_USE_SYSTEM_LOCK |
| 266 | #ifdef MAIL_USE_LOCKF | ||
| 267 | if (lockf (indesc, F_LOCK, 0) < 0) pfatal_with_name (inname); | ||
| 268 | #else /* not MAIL_USE_LOCKF */ | ||
| 256 | #ifdef XENIX | 269 | #ifdef XENIX |
| 257 | if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname); | 270 | if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname); |
| 258 | #else | 271 | #else |
| 259 | if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname); | 272 | if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname); |
| 260 | #endif | 273 | #endif |
| 261 | #endif /* MAIL_USE_FLOCK */ | 274 | #endif /* not MAIL_USE_LOCKF */ |
| 275 | #endif /* MAIL_USE_SYSTEM_LOCK */ | ||
| 262 | 276 | ||
| 263 | { | 277 | { |
| 264 | char buf[1024]; | 278 | char buf[1024]; |
| @@ -287,14 +301,14 @@ main (argc, argv) | |||
| 287 | if (close (outdesc) != 0) | 301 | if (close (outdesc) != 0) |
| 288 | pfatal_and_delete (outname); | 302 | pfatal_and_delete (outname); |
| 289 | 303 | ||
| 290 | #ifdef MAIL_USE_FLOCK | 304 | #ifdef MAIL_USE_SYSTEM_LOCK |
| 291 | #if defined (STRIDE) || defined (XENIX) | 305 | #if defined (STRIDE) || defined (XENIX) |
| 292 | /* Stride, xenix have file locking, but no ftruncate. This mess will do. */ | 306 | /* Stride, xenix have file locking, but no ftruncate. This mess will do. */ |
| 293 | close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); | 307 | close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); |
| 294 | #else | 308 | #else |
| 295 | ftruncate (indesc, 0L); | 309 | ftruncate (indesc, 0L); |
| 296 | #endif /* STRIDE or XENIX */ | 310 | #endif /* STRIDE or XENIX */ |
| 297 | #endif /* MAIL_USE_FLOCK */ | 311 | #endif /* MAIL_USE_SYSTEM_LOCK */ |
| 298 | 312 | ||
| 299 | #ifdef MAIL_USE_MMDF | 313 | #ifdef MAIL_USE_MMDF |
| 300 | lk_close (indesc, 0, 0, 0); | 314 | lk_close (indesc, 0, 0, 0); |
| @@ -302,7 +316,7 @@ main (argc, argv) | |||
| 302 | close (indesc); | 316 | close (indesc); |
| 303 | #endif | 317 | #endif |
| 304 | 318 | ||
| 305 | #ifndef MAIL_USE_FLOCK | 319 | #ifndef MAIL_USE_SYSTEM_LOCK |
| 306 | /* Delete the input file; if we can't, at least get rid of its | 320 | /* Delete the input file; if we can't, at least get rid of its |
| 307 | contents. */ | 321 | contents. */ |
| 308 | #ifdef MAIL_UNLINK_SPOOL | 322 | #ifdef MAIL_UNLINK_SPOOL |
| @@ -311,7 +325,7 @@ main (argc, argv) | |||
| 311 | if (unlink (inname) < 0 && errno != ENOENT) | 325 | if (unlink (inname) < 0 && errno != ENOENT) |
| 312 | #endif /* MAIL_UNLINK_SPOOL */ | 326 | #endif /* MAIL_UNLINK_SPOOL */ |
| 313 | creat (inname, 0600); | 327 | creat (inname, 0600); |
| 314 | #endif /* not MAIL_USE_FLOCK */ | 328 | #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 315 | 329 | ||
| 316 | exit (0); | 330 | exit (0); |
| 317 | } | 331 | } |
| @@ -322,9 +336,9 @@ main (argc, argv) | |||
| 322 | else if (WRETCODE (status) != 0) | 336 | else if (WRETCODE (status) != 0) |
| 323 | exit (WRETCODE (status)); | 337 | exit (WRETCODE (status)); |
| 324 | 338 | ||
| 325 | #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_FLOCK) | 339 | #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK) |
| 326 | unlink (lockname); | 340 | unlink (lockname); |
| 327 | #endif /* not MAIL_USE_MMDF and not MAIL_USE_FLOCK */ | 341 | #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */ |
| 328 | exit (0); | 342 | exit (0); |
| 329 | } | 343 | } |
| 330 | 344 | ||