Blame ecryptfs-utils-87-mtab.patch

9b69d7
diff -up ecryptfs-utils-87/src/libecryptfs/main.c.mtabfix ecryptfs-utils-87/src/libecryptfs/main.c
9b69d7
--- ecryptfs-utils-87/src/libecryptfs/main.c.mtabfix	2011-07-11 13:46:12.809240356 +0200
9b69d7
+++ ecryptfs-utils-87/src/libecryptfs/main.c	2011-07-11 13:46:12.825240472 +0200
9b69d7
@@ -427,9 +427,13 @@ int ecryptfs_mount(char *source, char *t
9b69d7
 	}
9b69d7
 	mtab_fd = setmntent("/etc/mtab", "a");
9b69d7
 	if (!mtab_fd) {
9b69d7
-		rc = -EACCES;
9b69d7
-		syslog(LOG_ERR, "Failed to update the mount table\n");
9b69d7
-		goto out;
9b69d7
+		/* it's possible that /etc/mtab is just a symlink to /proc/mounts */
9b69d7
+		char dummy;
9b69d7
+		if (readlink("/etc/mtab", &dummy, 1) < 0) {
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
9b69d7
--- ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c.mtabfix	2011-07-11 13:45:54.927111621 +0200
9b69d7
+++ ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c	2011-07-11 13:45:54.946111757 +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");