Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Mar 1996 21:32:41 -0800 (PST)
From:      asami@cs.berkeley.edu (Satoshi Asami)
To:        CVS-committers@freefall.freebsd.org, cvs-all@freefall.freebsd.org, cvs-sbin@freefall.freebsd.org
Subject:   Re: cvs commit: src/sbin/mount mount.c
Message-ID:  <199603060532.VAA13683@silvia.HIP.Berkeley.EDU>
In-Reply-To: <199603060411.UAA13389@silvia.HIP.Berkeley.EDU> (asami@cs.berkeley.edu)

next in thread | previous in thread | raw e-mail | index | archive | help
 * But anyway, people don't try this at home...the patch is totally
 * bogus, sizeof(array of "char *"s) will not return the total number of
 * characters used by the strings. ;)
 * 
 * I'll send out another one after dinner....

Ok, this one should be ok.  I also converted a "do-while" to a "for",
I don't know why it had to be three lines instead of one....

===
Index: mount.c
===================================================================
RCS file: /usr/cvs/src/sbin/mount/mount.c,v
retrieving revision 1.9
diff -c -r1.9 mount.c
*** mount.c	1996/03/03 08:44:22	1.9
--- mount.c	1996/03/06 05:29:50
***************
*** 327,339 ****
  			exit(mount_ufs(argc, (char * const *) argv));
  
  		/* Go find an executable. */
! 		edir = edirs;
! 		do {
  			(void)snprintf(execname,
  			    sizeof(execname), "%s/mount_%s", *edir, vfstype);
  			execv(execname, (char * const *)argv);
! 			warn("exec %s for %s", execname, name);
! 		} while (*++edir != NULL);
  		exit(1);
  		/* NOTREACHED */
  	default:				/* Parent. */
--- 327,354 ----
  			exit(mount_ufs(argc, (char * const *) argv));
  
  		/* Go find an executable. */
! 		for (edir = edirs; *edir; edir++) {
  			(void)snprintf(execname,
  			    sizeof(execname), "%s/mount_%s", *edir, vfstype);
  			execv(execname, (char * const *)argv);
! 		}
! 		if (errno == ENOENT) {
! 			int len = 0;
! 			char *tmp;
! 			for (edir = edirs; *edir; edir++)
! 				len += strlen(*edir) + 2;	/* ", " */
! 			if ((tmp = malloc(len)) == NULL) {
! 				warn(NULL);
! 				exit(1);
! 			}
! 			tmp[0] = '\0';
! 			for (edir = edirs; *edir; edir++) {
! 				strcat(tmp, *edir);
! 				if (edir[1] != NULL)
! 					strcat(tmp, ", ");
! 			}
! 			warn("exec mount_%s not found in %s", vfstype, tmp);
! 		}
  		exit(1);
  		/* NOTREACHED */
  	default:				/* Parent. */
===

I know it's more complicated than necessary (I can probably get away
with "char tmp[100]" or some such), but I don't want it to break when
someone decides to add 30 directories to the list.... :)

Satoshi



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199603060532.VAA13683>