Blame ecryptfs-utils-87-mtab.patch

88dca2
diff -up ecryptfs-utils-90/src/libecryptfs/main.c.mtabfix ecryptfs-utils-90/src/libecryptfs/main.c
88dca2
--- ecryptfs-utils-90/src/libecryptfs/main.c.mtabfix	2011-02-22 18:35:26.000000000 +0100
88dca2
+++ ecryptfs-utils-90/src/libecryptfs/main.c	2011-08-11 10:24:24.274245958 +0200
f47a71
@@ -382,6 +382,7 @@ out:
f47a71
 
f47a71
 int ecryptfs_mount(char *source, char *target, unsigned long flags, char *opts)
f47a71
 {
f47a71
+	char dummy;
f47a71
 	FILE *mtab_fd = NULL;
f47a71
 	struct mntent mountent;
f47a71
 	char *fullpath_source = NULL;
f47a71
@@ -425,11 +426,14 @@ int ecryptfs_mount(char *source, char *t
f47a71
 		syslog(LOG_ERR, "Failed to perform eCryptfs mount: [%m]\n");
f47a71
 		goto out;
9b69d7
 	}
f47a71
-	mtab_fd = setmntent("/etc/mtab", "a");
f47a71
-	if (!mtab_fd) {
9b69d7
-		rc = -EACCES;
9b69d7
-		syslog(LOG_ERR, "Failed to update the mount table\n");
9b69d7
-		goto out;
f47a71
+	/* it's possible that /etc/mtab is just a symlink to /proc/mounts */
f47a71
+	if (readlink("/etc/mtab", &dummy, 1) < 0) {
f47a71
+		mtab_fd = setmntent("/etc/mtab", "a");
f47a71
+		if (!mtab_fd) {
9b69d7
+			rc = -EACCES;
9b69d7
+			syslog(LOG_ERR, "Failed to update the mount table\n");
9b69d7
+			goto out;
9b69d7
+		}
9b69d7
 	}
9b69d7
 	mountent.mnt_fsname = fullpath_source;
9b69d7
 	mountent.mnt_dir = fullpath_target;
9b69d7
@@ -464,7 +468,7 @@ int ecryptfs_mount(char *source, char *t
9b69d7
 	}
9b69d7
 	mountent.mnt_freq = 0;
9b69d7
 	mountent.mnt_passno = 0;
9b69d7
-	if (addmntent(mtab_fd, &mountent)) {
9b69d7
+	if (mtab_fd && addmntent(mtab_fd, &mountent)) {
9b69d7
 		rc = -EIO;
9b69d7
 		syslog(LOG_ERR, "Failed to write to the mount "
9b69d7
 		       "table\n");
88dca2
diff -up ecryptfs-utils-90/src/utils/mount.ecryptfs_private.c.mtabfix ecryptfs-utils-90/src/utils/mount.ecryptfs_private.c