svn commit: r187093 - head/sbin/mount

David E. O'Brien obrien at FreeBSD.org
Mon Jan 12 00:22:38 PST 2009


Author: obrien
Date: Mon Jan 12 08:22:36 2009
New Revision: 187093
URL: http://svn.freebsd.org/changeset/base/187093

Log:
  Use a dynamically grown buffer for building the argv for the sub-mounts.
  Also fix RCSid spamage.
  
  Inspired by patch from:	Christoph Mallon <christoph.mallon at gmx.de>

Modified:
  head/sbin/mount/mount.c

Modified: head/sbin/mount/mount.c
==============================================================================
--- head/sbin/mount/mount.c	Mon Jan 12 07:45:03 2009	(r187092)
+++ head/sbin/mount/mount.c	Mon Jan 12 08:22:36 2009	(r187093)
@@ -31,16 +31,14 @@
 static const char copyright[] =
 "@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
 	The Regents of the University of California.  All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
 #if 0
 static char sccsid[] = "@(#)mount.c	8.25 (Berkeley) 5/8/95";
 #endif
-static const char rcsid[] =
-  "$FreeBSD$";
 #endif /* not lint */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 #include <sys/param.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
@@ -70,10 +68,8 @@ static const char rcsid[] =
 
 int debug, fstab_style, verbose;
 
-#define	MAX_ARGS 100
 struct cpa {
-	char	*a[MAX_ARGS];
-	ssize_t	m;
+	char	**a;
 	int	c;
 };
 
@@ -507,9 +503,14 @@ hasopt(const char *mntopts, const char *
 static void
 append_arg(struct cpa *sa, char *arg)
 {
-	if (sa->c >= sa->m)
-		errx(1, "Cannot process more than %zd mount arguments", sa->m);
+	static int a_sz;
 
+	if (sa->c + 1 == a_sz) {
+		a_sz = a_sz == 0 ? 8 : a_sz * 2;
+		sa->a = realloc(sa->a, sizeof(sa->a) * a_sz);
+		if (sa->a == NULL)
+			errx(1, "realloc failed");
+	}
 	sa->a[++sa->c] = arg;
 }
 
@@ -521,6 +522,7 @@ mountfs(const char *vfstype, const char 
 	struct statfs sf;
 	int i, ret;
 	char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
+	static int mnt_argv_inited;
 
 	/* resolve the mountpoint with realpath(3) */
 	(void)checkpath(name, mntpath);
@@ -555,7 +557,10 @@ mountfs(const char *vfstype, const char 
 	/* Construct the name of the appropriate mount command */
 	(void)snprintf(execname, sizeof(execname), "mount_%s", vfstype);
 
-	mnt_argv.m = MAX_ARGS;
+	if (!mnt_argv_inited) {
+		mnt_argv_inited++;
+		mnt_argv.a = NULL;
+	}
 	mnt_argv.c = -1;
 	append_arg(&mnt_argv, execname);
 	mangle(optbuf, &mnt_argv);


More information about the svn-src-head mailing list