diff options
| author | Richard M. Stallman | 1996-09-29 22:45:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-09-29 22:45:55 +0000 |
| commit | 25025815729722ae438ea4647ee08958b5f7366d (patch) | |
| tree | 0d463199b93314e63246844b60c610b67e5b1847 /lib-src | |
| parent | 2729a2b5d8b2c5c158f463bc8e5dff8c9637284e (diff) | |
| download | emacs-25025815729722ae438ea4647ee08958b5f7366d.tar.gz emacs-25025815729722ae438ea4647ee08958b5f7366d.zip | |
(main): If the lock call fails with EBUSY or
EAGAIN, retry a few times.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/movemail.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 80f6afd3616..79ea6dcabab 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -295,6 +295,9 @@ main (argc, argv) | |||
| 295 | 295 | ||
| 296 | if (fork () == 0) | 296 | if (fork () == 0) |
| 297 | { | 297 | { |
| 298 | int lockcount = 0; | ||
| 299 | int status; | ||
| 300 | |||
| 298 | setuid (getuid ()); | 301 | setuid (getuid ()); |
| 299 | 302 | ||
| 300 | #ifndef MAIL_USE_MMDF | 303 | #ifndef MAIL_USE_MMDF |
| @@ -320,22 +323,53 @@ main (argc, argv) | |||
| 320 | outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); | 323 | outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
| 321 | if (outdesc < 0) | 324 | if (outdesc < 0) |
| 322 | pfatal_with_name (outname); | 325 | pfatal_with_name (outname); |
| 326 | |||
| 327 | /* This label exists so we can retry locking | ||
| 328 | after a delay, if it got EAGAIN or EBUSY. */ | ||
| 329 | retry_lock: | ||
| 330 | |||
| 331 | /* Try to lock it. */ | ||
| 323 | #ifdef MAIL_USE_SYSTEM_LOCK | 332 | #ifdef MAIL_USE_SYSTEM_LOCK |
| 324 | #ifdef MAIL_USE_LOCKF | 333 | #ifdef MAIL_USE_LOCKF |
| 325 | if (lockf (indesc, F_LOCK, 0) < 0) pfatal_with_name (inname); | 334 | status = lockf (indesc, F_LOCK, 0); |
| 326 | #else /* not MAIL_USE_LOCKF */ | 335 | #else /* not MAIL_USE_LOCKF */ |
| 327 | #ifdef XENIX | 336 | #ifdef XENIX |
| 328 | if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname); | 337 | status = locking (indesc, LK_RLCK, 0L); |
| 329 | #else | 338 | #else |
| 330 | #ifdef WINDOWSNT | 339 | #ifdef WINDOWSNT |
| 331 | if (locking (indesc, LK_RLCK, -1L) < 0) pfatal_with_name (inname); | 340 | status = locking (indesc, LK_RLCK, -1L); |
| 332 | #else | 341 | #else |
| 333 | if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname); | 342 | status = flock (indesc, LOCK_EX); |
| 334 | #endif | 343 | #endif |
| 335 | #endif | 344 | #endif |
| 336 | #endif /* not MAIL_USE_LOCKF */ | 345 | #endif /* not MAIL_USE_LOCKF */ |
| 337 | #endif /* MAIL_USE_SYSTEM_LOCK */ | 346 | #endif /* MAIL_USE_SYSTEM_LOCK */ |
| 338 | 347 | ||
| 348 | /* If it fails, retry up to 5 times | ||
| 349 | for certain failure codes. */ | ||
| 350 | if (status < 0) | ||
| 351 | { | ||
| 352 | if (++lockcount <= 5) | ||
| 353 | { | ||
| 354 | #ifdef EAGAIN | ||
| 355 | if (errno == EAGAIN) | ||
| 356 | { | ||
| 357 | sleep (1); | ||
| 358 | goto retry_lock; | ||
| 359 | } | ||
| 360 | #endif | ||
| 361 | #ifdef EBUSY | ||
| 362 | if (errno == EBUSY) | ||
| 363 | { | ||
| 364 | sleep (1); | ||
| 365 | goto retry_lock; | ||
| 366 | } | ||
| 367 | #endif | ||
| 368 | } | ||
| 369 | |||
| 370 | pfatal_with_name (inname); | ||
| 371 | } | ||
| 372 | |||
| 339 | { | 373 | { |
| 340 | char buf[1024]; | 374 | char buf[1024]; |
| 341 | 375 | ||