2007-03-11 00:11:31 +01:00
|
|
|
Index: util-linux-2.12r/mount/fstab.c
|
|
|
|
===================================================================
|
|
|
|
--- util-linux-2.12r.orig/mount/fstab.c
|
|
|
|
+++ util-linux-2.12r/mount/fstab.c
|
|
|
|
@@ -395,6 +395,7 @@ getfsvolspec (const char *label) {
|
2006-12-19 00:18:10 +01:00
|
|
|
|
|
|
|
/* Flag for already existing lock file. */
|
|
|
|
static int we_created_lockfile = 0;
|
2007-03-11 00:11:31 +01:00
|
|
|
+static int lockfile_fd = -1;
|
2006-12-19 00:18:10 +01:00
|
|
|
|
|
|
|
/* Flag to indicate that signals have been set up. */
|
|
|
|
static int signals_have_been_setup = 0;
|
2007-03-11 00:11:31 +01:00
|
|
|
@@ -416,6 +417,8 @@ setlkw_timeout (int sig) {
|
|
|
|
void
|
2006-12-19 00:18:10 +01:00
|
|
|
unlock_mtab (void) {
|
|
|
|
if (we_created_lockfile) {
|
2007-03-11 00:11:31 +01:00
|
|
|
+ close(lockfile_fd);
|
|
|
|
+ lockfile_fd = -1;
|
2006-12-19 00:18:10 +01:00
|
|
|
unlink (MOUNTED_LOCK);
|
|
|
|
we_created_lockfile = 0;
|
|
|
|
}
|
2007-03-11 00:11:31 +01:00
|
|
|
@@ -443,7 +446,7 @@ unlock_mtab (void) {
|
2006-12-19 00:18:10 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
lock_mtab (void) {
|
2007-03-11 00:11:31 +01:00
|
|
|
- int tries = 3;
|
|
|
|
+ int tries = 100000, i;
|
2006-12-19 00:18:10 +01:00
|
|
|
char linktargetfile[MOUNTLOCK_LINKTARGET_LTH];
|
|
|
|
|
2007-03-11 00:11:31 +01:00
|
|
|
at_die = unlock_mtab;
|
|
|
|
@@ -469,45 +472,48 @@ lock_mtab (void) {
|
2006-12-19 00:18:10 +01:00
|
|
|
|
|
|
|
sprintf(linktargetfile, MOUNTLOCK_LINKTARGET, getpid ());
|
|
|
|
|
2007-03-11 00:11:31 +01:00
|
|
|
+ i = open (linktargetfile, O_WRONLY|O_CREAT, 0);
|
|
|
|
+ if (i < 0) {
|
|
|
|
+ int errsv = errno;
|
|
|
|
+ /* linktargetfile does not exist (as a file)
|
|
|
|
+ and we cannot create it. Read-only filesystem?
|
|
|
|
+ Too many files open in the system?
|
|
|
|
+ Filesystem full? */
|
|
|
|
+ die (EX_FILEIO, _("can't create lock file %s: %s "
|
|
|
|
+ "(use -n flag to override)"),
|
|
|
|
+ linktargetfile, strerror (errsv));
|
|
|
|
+ }
|
|
|
|
+ close(i);
|
|
|
|
+
|
2006-12-19 00:18:10 +01:00
|
|
|
/* Repeat until it was us who made the link */
|
2007-03-11 00:11:31 +01:00
|
|
|
while (!we_created_lockfile) {
|
|
|
|
struct flock flock;
|
|
|
|
- int errsv, fd, i, j;
|
|
|
|
-
|
|
|
|
- i = open (linktargetfile, O_WRONLY|O_CREAT, 0);
|
|
|
|
- if (i < 0) {
|
|
|
|
- int errsv = errno;
|
|
|
|
- /* linktargetfile does not exist (as a file)
|
|
|
|
- and we cannot create it. Read-only filesystem?
|
|
|
|
- Too many files open in the system?
|
|
|
|
- Filesystem full? */
|
|
|
|
- die (EX_FILEIO, _("can't create lock file %s: %s "
|
|
|
|
- "(use -n flag to override)"),
|
|
|
|
- linktargetfile, strerror (errsv));
|
|
|
|
- }
|
|
|
|
- close(i);
|
|
|
|
+ int errsv, j;
|
|
|
|
|
|
|
|
j = link(linktargetfile, MOUNTED_LOCK);
|
|
|
|
errsv = errno;
|
|
|
|
|
|
|
|
- (void) unlink(linktargetfile);
|
|
|
|
-
|
|
|
|
if (j == 0)
|
|
|
|
we_created_lockfile = 1;
|
|
|
|
|
|
|
|
if (j < 0 && errsv != EEXIST) {
|
|
|
|
+ (void) unlink(linktargetfile);
|
|
|
|
die (EX_FILEIO, _("can't link lock file %s: %s "
|
|
|
|
"(use -n flag to override)"),
|
|
|
|
MOUNTED_LOCK, strerror (errsv));
|
|
|
|
}
|
|
|
|
|
|
|
|
- fd = open (MOUNTED_LOCK, O_WRONLY);
|
|
|
|
+ lockfile_fd = open (MOUNTED_LOCK, O_WRONLY);
|
|
|
|
|
|
|
|
- if (fd < 0) {
|
|
|
|
+ if (lockfile_fd < 0) {
|
|
|
|
int errsv = errno;
|
|
|
|
/* Strange... Maybe the file was just deleted? */
|
|
|
|
- if (errno == ENOENT && tries-- > 0)
|
|
|
|
+ if (errno == ENOENT && tries-- > 0) {
|
|
|
|
+ if (tries % 200 == 0)
|
|
|
|
+ usleep(30);
|
|
|
|
continue;
|
|
|
|
+ }
|
|
|
|
+ (void) unlink(linktargetfile);
|
|
|
|
die (EX_FILEIO, _("can't open lock file %s: %s "
|
|
|
|
"(use -n flag to override)"),
|
|
|
|
MOUNTED_LOCK, strerror (errsv));
|
|
|
|
@@ -520,7 +526,7 @@ lock_mtab (void) {
|
|
|
|
|
2006-12-19 00:18:10 +01:00
|
|
|
if (j == 0) {
|
|
|
|
/* We made the link. Now claim the lock. */
|
2007-03-11 00:11:31 +01:00
|
|
|
- if (fcntl (fd, F_SETLK, &flock) == -1) {
|
|
|
|
+ if (fcntl (lockfile_fd, F_SETLK, &flock) == -1) {
|
2006-12-19 00:18:10 +01:00
|
|
|
if (verbose) {
|
2007-03-11 00:11:31 +01:00
|
|
|
int errsv = errno;
|
2006-12-19 00:18:10 +01:00
|
|
|
printf(_("Can't lock lock file %s: %s\n"),
|
2007-03-11 00:11:31 +01:00
|
|
|
@@ -528,13 +534,15 @@ lock_mtab (void) {
|
2006-12-19 00:18:10 +01:00
|
|
|
}
|
2007-03-11 00:11:31 +01:00
|
|
|
/* proceed anyway */
|
2006-12-19 00:18:10 +01:00
|
|
|
}
|
2007-03-11 00:11:31 +01:00
|
|
|
+ (void) unlink(linktargetfile);
|
2006-12-19 00:18:10 +01:00
|
|
|
} else {
|
|
|
|
static int tries = 0;
|
|
|
|
|
2007-03-11 00:11:31 +01:00
|
|
|
/* Someone else made the link. Wait. */
|
|
|
|
alarm(LOCK_TIMEOUT);
|
|
|
|
- if (fcntl (fd, F_SETLKW, &flock) == -1) {
|
|
|
|
+ if (fcntl (lockfile_fd, F_SETLKW, &flock) == -1) {
|
|
|
|
int errsv = errno;
|
|
|
|
+ (void) unlink(linktargetfile);
|
|
|
|
die (EX_FILEIO, _("can't lock lock file %s: %s"),
|
|
|
|
MOUNTED_LOCK, (errno == EINTR) ?
|
|
|
|
_("timed out") : strerror (errsv));
|
|
|
|
@@ -542,16 +550,18 @@ lock_mtab (void) {
|
|
|
|
alarm(0);
|
|
|
|
/* Limit the number of iterations - maybe there
|
|
|
|
still is some old /etc/mtab~ */
|
|
|
|
- if (tries++ > 3) {
|
|
|
|
- if (tries > 5)
|
|
|
|
- die (EX_FILEIO, _("Cannot create link %s\n"
|
|
|
|
- "Perhaps there is a stale lock file?\n"),
|
|
|
|
- MOUNTED_LOCK);
|
|
|
|
- sleep(1);
|
|
|
|
- }
|
|
|
|
+ ++tries;
|
|
|
|
+ if (tries % 200 == 0)
|
|
|
|
+ usleep(30);
|
|
|
|
+ if (tries > 100000) {
|
|
|
|
+ (void) unlink(linktargetfile);
|
|
|
|
+ close(lockfile_fd);
|
|
|
|
+ die (EX_FILEIO, _("Cannot create link %s\n"
|
|
|
|
+ "Perhaps there is a stale lock file?\n"),
|
|
|
|
+ MOUNTED_LOCK);
|
|
|
|
+ }
|
|
|
|
+ close(lockfile_fd);
|
|
|
|
}
|
|
|
|
-
|
2006-12-19 00:18:10 +01:00
|
|
|
- close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|