OBS User unknown 2007-03-10 23:11:31 +00:00 committed by Git OBS Bridge
parent 7eaa830bff
commit 5991503efa
3 changed files with 134 additions and 61 deletions

View File

@ -1,86 +1,152 @@
--- util-linux-2.12q/mount/fstab.c Index: util-linux-2.12r/mount/fstab.c
+++ util-linux-2.12q/mount/fstab.c ===================================================================
@@ -395,6 +395,7 @@ --- util-linux-2.12r.orig/mount/fstab.c
+++ util-linux-2.12r/mount/fstab.c
@@ -395,6 +395,7 @@ getfsvolspec (const char *label) {
/* Flag for already existing lock file. */ /* Flag for already existing lock file. */
static int we_created_lockfile = 0; static int we_created_lockfile = 0;
+static int lock_file_desc = -1; +static int lockfile_fd = -1;
/* Flag to indicate that signals have been set up. */ /* Flag to indicate that signals have been set up. */
static int signals_have_been_setup = 0; static int signals_have_been_setup = 0;
@@ -417,6 +418,8 @@ @@ -416,6 +417,8 @@ setlkw_timeout (int sig) {
void
unlock_mtab (void) { unlock_mtab (void) {
if (we_created_lockfile) { if (we_created_lockfile) {
+ close(lockfile_fd);
+ lockfile_fd = -1;
unlink (MOUNTED_LOCK); unlink (MOUNTED_LOCK);
+ close(lock_file_desc);
+ lock_file_desc = -1;
we_created_lockfile = 0; we_created_lockfile = 0;
} }
} @@ -443,7 +446,7 @@ unlock_mtab (void) {
@@ -443,6 +446,7 @@
void void
lock_mtab (void) { lock_mtab (void) {
+ sigset_t sigmask; - int tries = 3;
int tries = 3; + int tries = 100000, i;
char linktargetfile[MOUNTLOCK_LINKTARGET_LTH]; char linktargetfile[MOUNTLOCK_LINKTARGET_LTH];
@@ -467,6 +471,10 @@ at_die = unlock_mtab;
signals_have_been_setup = 1; @@ -469,45 +472,48 @@ lock_mtab (void) {
}
+ /* Allow all signals while trying to lock mtab */
+ sigemptyset(&sigmask);
+ sigprocmask(SIG_SETMASK, &sigmask, &sigmask);
+
sprintf(linktargetfile, MOUNTLOCK_LINKTARGET, getpid ()); sprintf(linktargetfile, MOUNTLOCK_LINKTARGET, getpid ());
+ 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);
+
/* Repeat until it was us who made the link */ /* Repeat until it was us who made the link */
@@ -521,12 +529,21 @@ while (!we_created_lockfile) {
if (j == 0) { struct flock flock;
/* We made the link. Now claim the lock. */ - int errsv, fd, i, j;
if (fcntl (fd, F_SETLK, &flock) == -1) { -
+ int errsv = errno; - i = open (linktargetfile, O_WRONLY|O_CREAT, 0);
+ if (!tries--) - if (i < 0) {
+ die(EX_FILEIO, - int errsv = errno;
+ _("Can't lock lock file %s: %s\n"), - /* linktargetfile does not exist (as a file)
+ MOUNTED_LOCK, strerror (errsv)); - and we cannot create it. Read-only filesystem?
if (verbose) { - Too many files open in the system?
- int errsv = errno; - Filesystem full? */
printf(_("Can't lock lock file %s: %s\n"), - die (EX_FILEIO, _("can't create lock file %s: %s "
MOUNTED_LOCK, strerror (errsv)); - "(use -n flag to override)"),
} - linktargetfile, strerror (errsv));
- /* proceed anyway */ - }
+ /* bummer - someone raced us to the file - close(i);
+ * lock. Start all over again. */ + int errsv, j;
+ unlink(MOUNTED_LOCK);
+ } else { j = link(linktargetfile, MOUNTED_LOCK);
+ we_created_lockfile = 1; errsv = errno;
+ lock_file_desc = fd;
} - (void) unlink(linktargetfile);
} else { -
static int tries = 0; if (j == 0)
@@ -551,8 +568,14 @@ 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) {
if (j == 0) {
/* We made the link. Now claim the lock. */
- if (fcntl (fd, F_SETLK, &flock) == -1) {
+ if (fcntl (lockfile_fd, F_SETLK, &flock) == -1) {
if (verbose) {
int errsv = errno;
printf(_("Can't lock lock file %s: %s\n"),
@@ -528,13 +534,15 @@ lock_mtab (void) {
}
/* proceed anyway */
}
+ (void) unlink(linktargetfile);
} else {
static int tries = 0;
/* 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);
}
-
- close(fd); - close(fd);
+ /* If we created the lock file, keep the fd else
+ * our POSIX lock will go away immediately */
+ if (!we_created_lockfile)
+ close(fd);
} }
+
+ /* Restore original signal mask */
+ sigprocmask(SIG_SETMASK, &sigmask, NULL);
} }
/*
--- util-linux-2.12q/mount/paths.h
+++ util-linux-2.12q/mount/paths.h
@@ -7,4 +7,4 @@
#define MOUNTED_LOCK "/etc/mtab~"
#define MOUNTED_TEMP "/etc/mtab.tmp"
#endif
-#define LOCK_TIMEOUT 10
+#define LOCK_TIMEOUT 30

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Thu Mar 9 11:00:11 CET 2007 - mkoenig@suse.de
- mount: fix mtablock patch to avoid mtab corruption [#226783]
------------------------------------------------------------------- -------------------------------------------------------------------
Thu Mar 8 17:27:22 CET 2007 - mkoenig@suse.de Thu Mar 8 17:27:22 CET 2007 - mkoenig@suse.de

View File

@ -20,7 +20,7 @@ License: BSD License and BSD-like, GNU General Public License (GPL)
Group: System/Base Group: System/Base
Autoreqprov: on Autoreqprov: on
Version: 2.12r Version: 2.12r
Release: 78 Release: 80
Summary: A collection of basic system utilities Summary: A collection of basic system utilities
Source: ftp://ftp.kernel.org/pub/linux/utils/util-linux/%name-%version.tar.bz2 Source: ftp://ftp.kernel.org/pub/linux/utils/util-linux/%name-%version.tar.bz2
Source2: nologin.c Source2: nologin.c
@ -622,6 +622,8 @@ fi
%endif %endif
%changelog %changelog
* Fri Mar 09 2007 - mkoenig@suse.de
- mount: fix mtablock patch to avoid mtab corruption [#226783]
* Thu Mar 08 2007 - mkoenig@suse.de * Thu Mar 08 2007 - mkoenig@suse.de
- partx: fix warning for too long literal - partx: fix warning for too long literal
* Wed Mar 07 2007 - rguenther@suse.de * Wed Mar 07 2007 - rguenther@suse.de