From b6cf6bb275df72fcf49d9816a0946a1eda53c845 Mon Sep 17 00:00:00 2001 From: Satoshi Asami Date: Fri, 15 Mar 1996 00:14:09 +0000 Subject: [PATCH] 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) --- sbin/mount/mount.c | 23 +++++++++++++++++++---- 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 1be00ec7d26c..5dbe573bbde0 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 1be00ec7d26c..5dbe573bbde0 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. */