Change the messages slightly when there is no "mount_type" executable

found when the user specifies "mount -t type".  Instead of printing
out one message for each path element (/sbin, /usr/sbin), it prints
out:

mount: exec mount_type not found in /sbin, /usr/sbin: No such file or directory

The code is quite long for such a stupid little piece of aesthesism
but it is very straghtforward so I guess it's ok.  Besides, I don't
want to do a "char foo[100];" and have malloc break down when someone
decides to add a few more paths to a variable that's far apart from
this code. :)

By the way, there is no malloc() off-by-one error for the '\0' at the
end of the string although I don't explicitly add 1 to the length.
The code allocates strlen(path element)+2 bytes for each path element,
and doesn't use the last two bytes (for the delimiting ", ").

Reviewed by:	the list (I hope)
This commit is contained in:
Satoshi Asami 1996-03-15 00:14:09 +00:00
parent 81ec856a3b
commit b6cf6bb275
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=14626
2 changed files with 38 additions and 8 deletions

View File

@ -327,13 +327,28 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
exit(mount_ufs(argc, (char * const *) argv));
/* Go find an executable. */
edir = edirs;
do {
for (edir = edirs; *edir; edir++) {
(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);
}
if (errno == ENOENT) {
int len = 0;
char *cp;
for (edir = edirs; *edir; edir++)
len += strlen(*edir) + 2; /* ", " */
if ((cp = malloc(len)) == NULL) {
warn(NULL);
exit(1);
}
cp[0] = '\0';
for (edir = edirs; *edir; edir++) {
strcat(cp, *edir);
if (edir[1] != NULL)
strcat(cp, ", ");
}
warn("exec mount_%s not found in %s", vfstype, cp);
}
exit(1);
/* NOTREACHED */
default: /* Parent. */

View File

@ -327,13 +327,28 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
exit(mount_ufs(argc, (char * const *) argv));
/* Go find an executable. */
edir = edirs;
do {
for (edir = edirs; *edir; edir++) {
(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);
}
if (errno == ENOENT) {
int len = 0;
char *cp;
for (edir = edirs; *edir; edir++)
len += strlen(*edir) + 2; /* ", " */
if ((cp = malloc(len)) == NULL) {
warn(NULL);
exit(1);
}
cp[0] = '\0';
for (edir = edirs; *edir; edir++) {
strcat(cp, *edir);
if (edir[1] != NULL)
strcat(cp, ", ");
}
warn("exec mount_%s not found in %s", vfstype, cp);
}
exit(1);
/* NOTREACHED */
default: /* Parent. */