- remove the mount.conf support (see #214891)
This commit is contained in:
parent
2cdb3efbb1
commit
dfa8a7f8fd
2 changed files with 5 additions and 353 deletions
|
|
@ -1,348 +0,0 @@
|
|||
From 47cd680cc6cbbfc42f0fe4dd5833a36859ca310a Mon Sep 17 00:00:00 2001
|
||||
From: Karel Zak <kzak@redhat.com>
|
||||
Date: Mon, 27 Jul 2009 21:15:27 +0200
|
||||
Subject: [PATCH] mount(8): add mount.conf and MTAB_LOCK_DIR=
|
||||
|
||||
The /etc directory is a really bad place for lock files on systems
|
||||
with read-only root FS.
|
||||
|
||||
This patch introduces the /etc/mount.conf file where is possible to
|
||||
define MTAB_LOCK_DIR=.
|
||||
|
||||
Signed-off-by: Karel Zak <kzak@redhat.com>
|
||||
---
|
||||
example.files/mount.conf | 20 +++++++
|
||||
include/pathnames.h | 7 ++-
|
||||
mount/fstab.c | 142 +++++++++++++++++++++++++++++++++++++---------
|
||||
mount/fstab.h | 1 +
|
||||
mount/mount.c | 6 ++-
|
||||
5 files changed, 147 insertions(+), 29 deletions(-)
|
||||
create mode 100644 example.files/mount.conf
|
||||
|
||||
diff --git a/example.files/mount.conf b/example.files/mount.conf
|
||||
new file mode 100644
|
||||
index 0000000..7813eba
|
||||
--- /dev/null
|
||||
+++ b/example.files/mount.conf
|
||||
@@ -0,0 +1,20 @@
|
||||
+#
|
||||
+# This is mount(8) config file
|
||||
+#
|
||||
+
|
||||
+# MTAB_LOCK_DIR is a directory where mount(8) stores "mtab~" and "mtab~.<pid>
|
||||
+# lock files. It's recommended to use the root filesystem for mount(8) lock
|
||||
+# files.
|
||||
+#
|
||||
+# The default is /etc.
|
||||
+#
|
||||
+# WARNING: If you want to use a directory on stand-alone filesystem you have to
|
||||
+# be very careful about your init scripts.
|
||||
+#
|
||||
+# For example use stand-alone /var for lock files and run "mount -a
|
||||
+# -F" (-F means fork()) in init scripts is really bad idea.
|
||||
+#
|
||||
+# Solution is to use "mount -n" to mount the filesystem and then "mount -f"
|
||||
+# to create proper /etc/mtab.
|
||||
+#
|
||||
+MTAB_LOCK_DIR=/etc
|
||||
diff --git a/include/pathnames.h b/include/pathnames.h
|
||||
index ead448e..e449c9d 100644
|
||||
--- a/include/pathnames.h
|
||||
+++ b/include/pathnames.h
|
||||
@@ -90,7 +90,12 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
-#define _PATH_MOUNTED_LOCK _PATH_MOUNTED "~"
|
||||
+#define _PATH_MOUNT_CONF "/etc/mount.conf"
|
||||
+
|
||||
+#define _PATH_MOUNTED_LOCKDIR "/etc/"
|
||||
+#define _MOUNTED_LOCK_FILENAME "mtab~"
|
||||
+#define _PATH_MOUNTED_LOCK _PATH_MOUNTED_LOCKDIR _MOUNTED_LOCK_FILENAME
|
||||
+
|
||||
#define _PATH_MOUNTED_TMP _PATH_MOUNTED ".tmp"
|
||||
|
||||
#ifndef _PATH_DEV
|
||||
diff --git a/mount/fstab.c b/mount/fstab.c
|
||||
index 82e90f3..8b1b244 100644
|
||||
--- a/mount/fstab.c
|
||||
+++ b/mount/fstab.c
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <mntent.h>
|
||||
+#include <dirent.h>
|
||||
+
|
||||
#include "mount_mntent.h"
|
||||
#include "fstab.h"
|
||||
#include "sundries.h"
|
||||
@@ -481,6 +483,7 @@ getfs_by_label (const char *label) {
|
||||
|
||||
/* Flag for already existing lock file. */
|
||||
static int we_created_lockfile = 0;
|
||||
+static DIR *lockdir;
|
||||
static int lockfile_fd = -1;
|
||||
|
||||
/* Flag to indicate that signals have been set up. */
|
||||
@@ -499,14 +502,85 @@ setlkw_timeout (int sig) {
|
||||
/* nothing, fcntl will fail anyway */
|
||||
}
|
||||
|
||||
+static char *
|
||||
+get_next_line(FILE *f, char *buf, size_t bufsz)
|
||||
+{
|
||||
+ char *s;
|
||||
+
|
||||
+ do {
|
||||
+ if (!fgets(buf, bufsz, f))
|
||||
+ goto err;
|
||||
+ s = strchr(buf, '\n');
|
||||
+ if (!s) {
|
||||
+ /* Missing final newline? Otherwise extremely */
|
||||
+ /* long line - assume file was corrupted */
|
||||
+ if (feof(f))
|
||||
+ s = index(buf, '\0');
|
||||
+ else {
|
||||
+ if (verbose)
|
||||
+ printf(_("%s: missing newline at line '%s'.\n"),
|
||||
+ _PATH_MOUNT_CONF, buf);
|
||||
+ goto err;
|
||||
+ }
|
||||
+ }
|
||||
+ *s = '\0';
|
||||
+ if (--s >= buf && *s == '\r')
|
||||
+ *s = '\0';
|
||||
+
|
||||
+ s = buf;
|
||||
+ while (*s == ' ' || *s == '\t') /* skip space */
|
||||
+ s++;
|
||||
+ } while (*s == '\0' || *s == '#');
|
||||
+
|
||||
+ return s;
|
||||
+err:
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+char *
|
||||
+get_lock_dirname(char *buf, size_t bufsz)
|
||||
+{
|
||||
+ FILE *f;
|
||||
+ char *s;
|
||||
+
|
||||
+ f = fopen(_PATH_MOUNT_CONF, "r");
|
||||
+ if (!f)
|
||||
+ goto err;
|
||||
+
|
||||
+ while((s = get_next_line(f, buf, bufsz))) {
|
||||
+ if (!strncmp(s, "MTAB_LOCK_DIR=", 14)) {
|
||||
+ s += 14;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ fclose(f);
|
||||
+ if (s) {
|
||||
+ size_t sz = strlen(s);
|
||||
+ char *end = sz > 1 ? s + (sz - 1) : NULL;
|
||||
+
|
||||
+ if (end && *end != '/') {
|
||||
+ *++end = '/';
|
||||
+ *++end = '\0';
|
||||
+ }
|
||||
+ return s;
|
||||
+ }
|
||||
+err:
|
||||
+ /* fallback */
|
||||
+ strncpy(buf, _PATH_MOUNTED_LOCKDIR, bufsz);
|
||||
+ buf[bufsz - 1] = '\0';
|
||||
+ return buf;
|
||||
+}
|
||||
+
|
||||
/* Remove lock file. */
|
||||
void
|
||||
unlock_mtab (void) {
|
||||
if (we_created_lockfile) {
|
||||
+ int lockdir_fd = dirfd(lockdir);
|
||||
close(lockfile_fd);
|
||||
lockfile_fd = -1;
|
||||
- unlink (_PATH_MOUNTED_LOCK);
|
||||
+ unlinkat(lockdir_fd, _MOUNTED_LOCK_FILENAME, 0);
|
||||
we_created_lockfile = 0;
|
||||
+ closedir(lockdir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,8 +601,6 @@ unlock_mtab (void) {
|
||||
/* Where does the link point to? Obvious choices are mtab and mtab~~.
|
||||
HJLu points out that the latter leads to races. Right now we use
|
||||
mtab~.<pid> instead. Use 20 as upper bound for the length of %d. */
|
||||
-#define MOUNTLOCK_LINKTARGET _PATH_MOUNTED_LOCK "%d"
|
||||
-#define MOUNTLOCK_LINKTARGET_LTH (sizeof(_PATH_MOUNTED_LOCK)+20)
|
||||
|
||||
/*
|
||||
* The original mount locking code has used sleep(1) between attempts and
|
||||
@@ -556,7 +628,10 @@ lock_mtab (void) {
|
||||
int i;
|
||||
struct timespec waittime;
|
||||
struct timeval maxtime;
|
||||
- char linktargetfile[MOUNTLOCK_LINKTARGET_LTH];
|
||||
+ const char *lockdirname;
|
||||
+ char buf[BUFSIZ];
|
||||
+ char linktargetfile[PATH_MAX];
|
||||
+ int lockdir_fd;
|
||||
|
||||
if (!signals_have_been_setup) {
|
||||
int sig = 0;
|
||||
@@ -577,18 +652,28 @@ lock_mtab (void) {
|
||||
signals_have_been_setup = 1;
|
||||
}
|
||||
|
||||
- sprintf(linktargetfile, MOUNTLOCK_LINKTARGET, getpid ());
|
||||
+ lockdirname = get_lock_dirname(buf, sizeof(buf));
|
||||
+
|
||||
+ lockdir = opendir(lockdirname);
|
||||
+ if (!lockdir) {
|
||||
+ die (EX_FILEIO, _("can't open %s: %s "),
|
||||
+ lockdirname, strerror(errno));
|
||||
+ }
|
||||
+ lockdir_fd = dirfd(lockdir);
|
||||
+
|
||||
+ snprintf(linktargetfile, sizeof(linktargetfile), "%s.%d",
|
||||
+ _MOUNTED_LOCK_FILENAME, getpid ());
|
||||
|
||||
- i = open (linktargetfile, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
|
||||
+ i = openat(lockdir_fd, linktargetfile, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
|
||||
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 "
|
||||
+ die (EX_FILEIO, _("can't create lock file %s%s: %s "
|
||||
"(use -n flag to override)"),
|
||||
- linktargetfile, strerror (errsv));
|
||||
+ lockdirname, linktargetfile, strerror(errsv));
|
||||
}
|
||||
close(i);
|
||||
|
||||
@@ -604,20 +689,22 @@ lock_mtab (void) {
|
||||
struct flock flock;
|
||||
int errsv, j;
|
||||
|
||||
- j = link(linktargetfile, _PATH_MOUNTED_LOCK);
|
||||
+ j = linkat(lockdir_fd, linktargetfile,
|
||||
+ lockdir_fd, _MOUNTED_LOCK_FILENAME, 0);
|
||||
errsv = errno;
|
||||
|
||||
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 "
|
||||
+ unlinkat(lockdir_fd, linktargetfile, 0);
|
||||
+ die (EX_FILEIO, _("can't link lock file %s%s: %s "
|
||||
"(use -n flag to override)"),
|
||||
- _PATH_MOUNTED_LOCK, strerror (errsv));
|
||||
+ lockdirname, _MOUNTED_LOCK_FILENAME, strerror(errsv));
|
||||
}
|
||||
|
||||
- lockfile_fd = open (_PATH_MOUNTED_LOCK, O_WRONLY);
|
||||
+ lockfile_fd = openat(lockdir_fd,
|
||||
+ _MOUNTED_LOCK_FILENAME, O_WRONLY);
|
||||
|
||||
if (lockfile_fd < 0) {
|
||||
/* Strange... Maybe the file was just deleted? */
|
||||
@@ -627,10 +714,10 @@ lock_mtab (void) {
|
||||
we_created_lockfile = 0;
|
||||
continue;
|
||||
}
|
||||
- (void) unlink(linktargetfile);
|
||||
- die (EX_FILEIO, _("can't open lock file %s: %s "
|
||||
+ unlinkat(lockdir_fd, linktargetfile, 0);
|
||||
+ die (EX_FILEIO, _("can't open lock file %s%s: %s "
|
||||
"(use -n flag to override)"),
|
||||
- _PATH_MOUNTED_LOCK, strerror (errsv));
|
||||
+ lockdirname, _MOUNTED_LOCK_FILENAME, strerror(errsv));
|
||||
}
|
||||
|
||||
flock.l_type = F_WRLCK;
|
||||
@@ -643,12 +730,13 @@ lock_mtab (void) {
|
||||
if (fcntl (lockfile_fd, F_SETLK, &flock) == -1) {
|
||||
if (verbose) {
|
||||
int errsv = errno;
|
||||
- printf(_("Can't lock lock file %s: %s\n"),
|
||||
- _PATH_MOUNTED_LOCK, strerror (errsv));
|
||||
+ printf(_("Can't lock lock file %s%s: %s\n"),
|
||||
+ lockdirname, _MOUNTED_LOCK_FILENAME,
|
||||
+ strerror(errsv));
|
||||
}
|
||||
/* proceed, since it was us who created the lockfile anyway */
|
||||
}
|
||||
- (void) unlink(linktargetfile);
|
||||
+ unlinkat(lockdir_fd, linktargetfile, 0);
|
||||
} else {
|
||||
/* Someone else made the link. Wait. */
|
||||
gettimeofday(&now, NULL);
|
||||
@@ -656,19 +744,19 @@ lock_mtab (void) {
|
||||
alarm(maxtime.tv_sec - now.tv_sec);
|
||||
if (fcntl (lockfile_fd, F_SETLKW, &flock) == -1) {
|
||||
int errsv = errno;
|
||||
- (void) unlink(linktargetfile);
|
||||
- die (EX_FILEIO, _("can't lock lock file %s: %s"),
|
||||
- _PATH_MOUNTED_LOCK, (errno == EINTR) ?
|
||||
- _("timed out") : strerror (errsv));
|
||||
+ unlinkat(lockdir_fd, linktargetfile, 0);
|
||||
+ die (EX_FILEIO, _("can't lock lock file %s%s: %s"),
|
||||
+ lockdirname, _MOUNTED_LOCK_FILENAME,
|
||||
+ (errno == EINTR) ?
|
||||
+ _("timed out") : strerror(errsv));
|
||||
}
|
||||
alarm(0);
|
||||
-
|
||||
nanosleep(&waittime, NULL);
|
||||
} else {
|
||||
- (void) unlink(linktargetfile);
|
||||
- die (EX_FILEIO, _("Cannot create link %s\n"
|
||||
+ unlinkat(lockdir_fd, linktargetfile, 0);
|
||||
+ die (EX_FILEIO, _("Cannot create link %s%s\n"
|
||||
"Perhaps there is a stale lock file?\n"),
|
||||
- _PATH_MOUNTED_LOCK);
|
||||
+ lockdirname, _MOUNTED_LOCK_FILENAME);
|
||||
}
|
||||
close(lockfile_fd);
|
||||
}
|
||||
diff --git a/mount/fstab.h b/mount/fstab.h
|
||||
index 8fc8fd4..b5bb5d9 100644
|
||||
--- a/mount/fstab.h
|
||||
+++ b/mount/fstab.h
|
||||
@@ -26,6 +26,7 @@ struct mntentchn *getfs_by_devdir (const char *dev, const char *dir);
|
||||
struct mntentchn *getfs_by_uuid (const char *uuid);
|
||||
struct mntentchn *getfs_by_label (const char *label);
|
||||
|
||||
+char *get_lock_dirname(char *buf, size_t bufsz);
|
||||
void lock_mtab (void);
|
||||
void unlock_mtab (void);
|
||||
void update_mtab (const char *special, struct my_mntent *with);
|
||||
diff --git a/mount/mount.c b/mount/mount.c
|
||||
index ef478c7..09086a8 100644
|
||||
--- a/mount/mount.c
|
||||
+++ b/mount/mount.c
|
||||
@@ -2178,9 +2178,13 @@ main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (verbose > 2) {
|
||||
+ char buf[BUFSIZ];
|
||||
+
|
||||
printf("mount: fstab path: \"%s\"\n", _PATH_MNTTAB);
|
||||
printf("mount: mtab path: \"%s\"\n", _PATH_MOUNTED);
|
||||
- printf("mount: lock path: \"%s\"\n", _PATH_MOUNTED_LOCK);
|
||||
+ printf("mount: lock path: \"%s%s\"\n",
|
||||
+ get_lock_dirname(buf, sizeof(buf)),
|
||||
+ _MOUNTED_LOCK_FILENAME);
|
||||
printf("mount: temp path: \"%s\"\n", _PATH_MOUNTED_TMP);
|
||||
printf("mount: UID: %d\n", getuid());
|
||||
printf("mount: eUID: %d\n", geteuid());
|
||||
--
|
||||
1.6.2.5
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
Summary: A collection of basic system utilities
|
||||
Name: util-linux-ng
|
||||
Version: 2.16
|
||||
Release: 2%{?dist}
|
||||
Release: 3%{?dist}
|
||||
License: GPLv2 and GPLv2+ and BSD with advertising and Public Domain
|
||||
Group: System Environment/Base
|
||||
URL: ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng
|
||||
|
|
@ -96,8 +96,6 @@ Patch3: util-linux-ng-2.14-blockdev-rmpart.patch
|
|||
Patch4: util-linux-ng-2.13-ctrlaltdel-man.patch
|
||||
# /etc/blkid.tab --> /etc/blkid/blkid.tab
|
||||
Patch5: util-linux-ng-2.16-blkid-cachefile.patch
|
||||
# 214891 - mount: move mtab locks to /var/lock
|
||||
Patch6: util-linux-ng-2.16-mount-conf.patch
|
||||
|
||||
### Ready for upstream?
|
||||
###
|
||||
|
|
@ -197,7 +195,6 @@ cp %{SOURCE8} %{SOURCE9} .
|
|||
%patch3 -p1
|
||||
%patch4 -p1
|
||||
%patch5 -p1
|
||||
%patch6 -p1
|
||||
%patch7 -p1
|
||||
%patch8 -p1
|
||||
|
||||
|
|
@ -474,7 +471,7 @@ fi
|
|||
|
||||
%files -f %{name}.files
|
||||
%defattr(-,root,root)
|
||||
%doc */README.* NEWS AUTHORS licenses/* README* example.files/mount.conf
|
||||
%doc */README.* NEWS AUTHORS licenses/* README*
|
||||
%doc getopt/getopt-*.{bash,tcsh}
|
||||
|
||||
%config(noreplace) %{_sysconfdir}/pam.d/chfn
|
||||
|
|
@ -710,6 +707,9 @@ fi
|
|||
|
||||
|
||||
%changelog
|
||||
* Thu Jul 30 2009 Karel Zak <kzak@redhat.com> 2.16-3
|
||||
- remove the mount.conf support (see #214891)
|
||||
|
||||
* Mon Jul 27 2009 Karel Zak <kzak@redhat.com> 2.16-2
|
||||
- fix #214891 - add mount.conf and MTAB_LOCK_DIR= option
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue