Blame ecryptfs-utils-87-mtab.patch

9b69d7
diff -up ecryptfs-utils-87/src/libecryptfs/main.c.mtabfix ecryptfs-utils-87/src/libecryptfs/main.c
f47a71
--- ecryptfs-utils-87/src/libecryptfs/main.c.mtabfix	2011-03-09 14:30:32.000000000 +0100
f47a71
+++ ecryptfs-utils-87/src/libecryptfs/main.c	2011-07-11 14:10:40.525812683 +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");
9b69d7
diff -up ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c.mtabfix ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c
f47a71
--- ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c.mtabfix	2011-07-11 13:53:36.942438496 +0200
f47a71
+++ ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c	2011-07-11 13:53:36.954438583 +0200
9b69d7
@@ -219,9 +219,18 @@ int check_ownerships(int uid, char *path
4a4073
 
4a4073
 
4a4073
 int update_mtab(char *dev, char *mnt, char *opt) {
4a4073
-/* Update /etc/mtab with new mount entry.
4a4073
+/* Update /etc/mtab with new mount entry unless it is a symbolic link
4a4073
  * Return 0 on success, 1 on failure.
4a4073
  */
4a4073
+	char dummy;
4a4073
+	int useMtab;
4a4073
+	/* Check if mtab is a symlink */
4a4073
+	useMtab = (readlink("/etc/mtab", &dummy, 1) < 0);
4a4073
+	if (!useMtab) {
4a4073
+		/* No need updating mtab */
4a4073
+		return 0;
4a4073
+	}
4a4073
+
4a4073
 	FILE *fh;
4a4073
 	struct mntent m;
4a4073
 	fh = setmntent("/etc/mtab", "a");