diff options
author | asami <asami@FreeBSD.org> | 1996-03-15 00:14:09 +0000 |
---|---|---|
committer | asami <asami@FreeBSD.org> | 1996-03-15 00:14:09 +0000 |
commit | f177e4de95f41c997afa5f3c121cc0b59c03e6b7 (patch) | |
tree | dcb9f4ba5b5b278d2a997f5282042ab5255359e8 | |
parent | 25dec96ec5f0da71ccf7d0d6a2f27a524f8a66f5 (diff) | |
download | FreeBSD-src-f177e4de95f41c997afa5f3c121cc0b59c03e6b7.zip FreeBSD-src-f177e4de95f41c997afa5f3c121cc0b59c03e6b7.tar.gz |
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)
-rw-r--r-- | sbin/mount/mount.c | 23 | ||||
-rw-r--r-- | sbin/mount_ifs/mount.c | 23 |
2 files changed, 38 insertions, 8 deletions
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index 1be00ec..5dbe573 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -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. */ diff --git a/sbin/mount_ifs/mount.c b/sbin/mount_ifs/mount.c index 1be00ec..5dbe573 100644 --- a/sbin/mount_ifs/mount.c +++ b/sbin/mount_ifs/mount.c @@ -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. */ |