Index: sbin/mount/mount.c =================================================================== --- sbin/mount/mount.c (revision 229083) +++ sbin/mount/mount.c (working copy) @@ -539,7 +539,8 @@ mountfs(const char *vfstype, const char static struct cpa mnt_argv; /* resolve the mountpoint with realpath(3) */ - (void)checkpath(name, mntpath); + if (checkpath_noexit(name, mntpath) != 0) + return (1); name = mntpath; if (mntopts == NULL) Index: sbin/mount/getmntopts.c =================================================================== --- sbin/mount/getmntopts.c (revision 229083) +++ sbin/mount/getmntopts.c (working copy) @@ -124,16 +124,30 @@ rmslashes(char *rrpin, char *rrpout) *rrpout = '\0'; } -void -checkpath(const char *path, char *resolved) +int +checkpath_noexit(const char *path, char *resolved) { struct stat sb; if (realpath(path, resolved) != NULL && stat(resolved, &sb) == 0) { - if (!S_ISDIR(sb.st_mode)) - errx(EX_USAGE, "%s: not a directory", resolved); - } else - errx(EX_USAGE, "%s: %s", resolved, strerror(errno)); + if (!S_ISDIR(sb.st_mode)) { + warnx("%s: not a directory", resolved); + return (1); + } + } else { + warnx("%s: %s", resolved, strerror(errno)); + return (1); + } + + return (0); +} + +void +checkpath(const char *path, char *resolved) +{ + + if (checkpath_noexit(path, resolved) != 0) + exit(EX_USAGE); } void Index: sbin/mount/mntopts.h =================================================================== --- sbin/mount/mntopts.h (revision 229083) +++ sbin/mount/mntopts.h (working copy) @@ -94,6 +94,7 @@ struct mntopt { void getmntopts(const char *, const struct mntopt *, int *, int *); void rmslashes(char *, char *); void checkpath(const char *, char resolved_path[]); +int checkpath_noexit(const char *, char resolved_path[]); extern int getmnt_silent; void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, size_t len); void build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, const char *fmt, ...); Index: sbin/mount/mount_fs.c =================================================================== --- sbin/mount/mount_fs.c (revision 229083) +++ sbin/mount/mount_fs.c (working copy) @@ -82,7 +82,6 @@ mount_fs(const char *vfstype, int argc, char fstype[32]; char errmsg[255]; char *p, *val; - int ret; strlcpy(fstype, vfstype, sizeof(fstype)); memset(errmsg, 0, sizeof(errmsg)); @@ -118,17 +117,19 @@ mount_fs(const char *vfstype, int argc, dev = argv[0]; dir = argv[1]; - (void)checkpath(dir, mntpath); + if (checkpath_noexit(dir, mntpath) != 0) + return (1); (void)rmslashes(dev, dev); build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1); build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1); build_iovec(&iov, &iovlen, "from", dev, (size_t)-1); build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg)); - - ret = nmount(iov, iovlen, mntflags); - if (ret < 0) - err(1, "%s %s", dev, errmsg); - return (ret); + if (nmount(iov, iovlen, mntflags) == -1) { + warn("%s %s", dev, errmsg); + return (1); + } + + return (0); }