Blob Blame History Raw
diff -up ecryptfs-utils-87/src/libecryptfs/main.c.mtabfix ecryptfs-utils-87/src/libecryptfs/main.c
--- ecryptfs-utils-87/src/libecryptfs/main.c.mtabfix	2011-07-11 13:46:12.809240356 +0200
+++ ecryptfs-utils-87/src/libecryptfs/main.c	2011-07-11 13:46:12.825240472 +0200
@@ -427,9 +427,13 @@ int ecryptfs_mount(char *source, char *t
 	}
 	mtab_fd = setmntent("/etc/mtab", "a");
 	if (!mtab_fd) {
-		rc = -EACCES;
-		syslog(LOG_ERR, "Failed to update the mount table\n");
-		goto out;
+		/* it's possible that /etc/mtab is just a symlink to /proc/mounts */
+		char dummy;
+		if (readlink("/etc/mtab", &dummy, 1) < 0) {
+			rc = -EACCES;
+			syslog(LOG_ERR, "Failed to update the mount table\n");
+			goto out;
+		}
 	}
 	mountent.mnt_fsname = fullpath_source;
 	mountent.mnt_dir = fullpath_target;
@@ -464,7 +468,7 @@ int ecryptfs_mount(char *source, char *t
 	}
 	mountent.mnt_freq = 0;
 	mountent.mnt_passno = 0;
-	if (addmntent(mtab_fd, &mountent)) {
+	if (mtab_fd && addmntent(mtab_fd, &mountent)) {
 		rc = -EIO;
 		syslog(LOG_ERR, "Failed to write to the mount "
 		       "table\n");
diff -up ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c.mtabfix ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c
--- ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c.mtabfix	2011-07-11 13:45:54.927111621 +0200
+++ ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c	2011-07-11 13:45:54.946111757 +0200
@@ -219,9 +219,18 @@ int check_ownerships(int uid, char *path
 
 
 int update_mtab(char *dev, char *mnt, char *opt) {
-/* Update /etc/mtab with new mount entry.
+/* Update /etc/mtab with new mount entry unless it is a symbolic link
  * Return 0 on success, 1 on failure.
  */
+	char dummy;
+	int useMtab;
+	/* Check if mtab is a symlink */
+	useMtab = (readlink("/etc/mtab", &dummy, 1) < 0);
+	if (!useMtab) {
+		/* No need updating mtab */
+		return 0;
+	}
+
 	FILE *fh;
 	struct mntent m;
 	fh = setmntent("/etc/mtab", "a");