walters / rpms / nfs-utils

Forked from rpms/nfs-utils 6 years ago
Clone
6173722
--- nfs-utils-1.0.9/utils/mount/mount.c.orig	2006-10-25 10:52:32.000000000 -0400
6173722
+++ nfs-utils-1.0.9/utils/mount/mount.c	2006-10-25 12:09:52.000000000 -0400
6173722
@@ -163,16 +163,29 @@ static char * fix_opts_string (int flags
6173722
 	return new_opts;
6173722
 }
6173722
 
6173722
-void copy_mntent(struct mntent *ment, nfs_mntent_t *nment)
6173722
+static inline void dup_mntent(struct mntent *ment, nfs_mntent_t *nment)
6173722
 {
6173722
 	/* Not sure why nfs_mntent_t should exist */
6173722
-	strcpy(nment->mnt_fsname, ment->mnt_fsname);
6173722
-	strcpy(nment->mnt_dir, ment->mnt_dir);
6173722
-	strcpy(nment->mnt_type, ment->mnt_type);
6173722
-	strcpy(nment->mnt_opts, ment->mnt_opts);
6173722
+	nment->mnt_fsname = strdup(ment->mnt_fsname);
6173722
+	nment->mnt_dir = strdup(ment->mnt_dir);
6173722
+	nment->mnt_type = strdup(ment->mnt_type);
6173722
+	nment->mnt_opts = strdup(ment->mnt_opts);
6173722
 	nment->mnt_freq = ment->mnt_freq;
6173722
 	nment->mnt_passno = ment->mnt_passno;
6173722
 }
6173722
+static inline void 
6173722
+free_mntent(struct mntent *ment, int remount)
6173722
+{
6173722
+	free(ment->mnt_fsname);
6173722
+	free(ment->mnt_dir);
6173722
+	free(ment->mnt_type);
6173722
+	/* 
6173722
+	 * Note: free(ment->mnt_opts) happens in discard_mntentchn()
6173722
+	 * via update_mtab() on remouts
6173722
+	 */
6173722
+	 if (!remount)
6173722
+	 	free(ment->mnt_opts);
6173722
+}
6173722
 
6173722
 int add_mtab(char *fsname, char *mount_point, char *fstype, int flags, char *opts, int freq, int passno)
6173722
 {
6173722
@@ -190,8 +203,9 @@ int add_mtab(char *fsname, char *mount_p
6173722
 	if(flags & MS_REMOUNT) {
6173722
 		nfs_mntent_t nment;
6173722
 		
6173722
-		copy_mntent(&ment, &nment);
6173722
+		dup_mntent(&ment, &nment);
6173722
 		update_mtab(nment.mnt_dir, &nment);
6173722
+		free_mntent(&nment, 1);
6173722
 		return 0;
6173722
 	}
6173722
 
6173722
@@ -341,10 +355,11 @@ static void mount_error(char *node)
6173722
 			fprintf(stderr, "%s: %s\n", progname, strerror(errno));
6173722
 	}
6173722
 }
6173722
+#define NFS_MOUNT_VERS_DEFAULT 3
6173722
 
6173722
 int main(int argc, char *argv[])
6173722
 {
6173722
-	int c, flags = 0, nfs_mount_vers = 0, mnt_err = 1, fake = 0;
6173722
+	int c, flags = 0, nfs_mount_vers, mnt_err = 1, fake = 0;
6173722
 	char *spec, *mount_point, *extra_opts = NULL;
6173722
 	char *mount_opts = NULL, *p;
6173722
 	struct mntentchn *mc;
6173722
@@ -375,6 +390,10 @@ int main(int argc, char *argv[])
6173722
 		return 0;
6173722
 	}
6173722
 
6173722
+	nfs_mount_vers = NFS_MOUNT_VERS_DEFAULT;
6173722
+	if (!strcmp(progname, "mount.nfs4"))
6173722
+		nfs_mount_vers = 4;
6173722
+
6173722
 	while ((c = getopt_long (argc - 2, argv + 2, "rt:vVwfno:hs",
6173722
 				longopts, NULL)) != -1) {
6173722
 		switch (c) {
6173722
@@ -465,9 +484,9 @@ int main(int argc, char *argv[])
6173722
 		}
6173722
 	}
6173722
 
6173722
-	if (!strcmp(progname, "mount.nfs4") || nfs_mount_vers == 4) {
6173722
-		nfs_mount_vers = 4;
6173722
-		mnt_err = nfs4mount(spec, mount_point, &flags, &extra_opts, &mount_opts, 0);
6173722
+	if (nfs_mount_vers == 4) {
6173722
+		mnt_err = nfs4mount(spec, mount_point, &flags, 
6173722
+			&extra_opts, &mount_opts, 0);
6173722
 	}
6173722
 	else {
6173722
 		if (!strcmp(progname, "mount.nfs")) {
6173722
@@ -475,21 +494,19 @@ int main(int argc, char *argv[])
6173722
 					&extra_opts, &mount_opts, &nfs_mount_vers, 0);
6173722
 		}
6173722
 	}
6173722
-
6173722
 	if (fake)
6173722
 		return 0;
6173722
 	if (mnt_err)
6173722
 		exit(EX_FAIL);
6173722
 
6173722
-	if(!(flags & MS_REMOUNT)) {
6173722
-		mnt_err = do_mount_syscall(spec, mount_point,
6173722
-				nfs_mount_vers == 4 ? "nfs4" : "nfs", flags, mount_opts);
6173722
-
6173722
-		if(mnt_err) {
6173722
-			mount_error(mount_point);
6173722
-			exit(EX_FAIL);
6173722
-		}
6173722
+	mnt_err = do_mount_syscall(spec, mount_point,
6173722
+			nfs_mount_vers == 4 ? "nfs4" : "nfs", flags, mount_opts);
6173722
+
6173722
+	if(mnt_err) {
6173722
+		mount_error(mount_point);
6173722
+		exit(EX_FAIL);
6173722
 	}
6173722
+
6173722
 	if(!nomtab) {
6173722
 		add_mtab(spec, mount_point, nfs_mount_vers == 4 ? "nfs4" : "nfs",
6173722
 			 flags, extra_opts, 0, 0);