Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Fixing swap1_stop
On Wed, 9 Aug 2017 03:38:20 -0400 christos%zoulas.com@localhost (Christos Zoulas)
wrote:
> I think it is better to modify mount to either pass a format string
> to it or to quote the pathnames so that the output is predictable.
Here's my second attempt at the latter solution (the first attempt
involved writing a utility functional called shquote which gcc
subsequently informed me was already in the standard library. oops).
It's intended to leave the output completely unchanged in all "normal"
cases, but to quote the mount point (or the device file) if either
filename contains white space or shell operators.
Example output:
$ ./mount
/dev/wd0a on / type ffs (synchronous, local)
/dev/cgd0a on /config type ffs (synchronous, local)
/dev/cgd0e on /var type ffs (log, local)
/dev/wd0f on /build type ffs (log, local)
/dev/cgd0f on /home type ffs (log, local)
kernfs on /kern type kernfs (local)
ptyfs on /dev/pts type ptyfs (local)
procfs on /proc type procfs (local)
tmpfs on /var/shm type tmpfs (nosuid, local)
tmpfs on '/home/idleroux/silly name' type tmpfs (local)
--
IDL
--- mount.c.orig 2017-08-13 15:28:55.214873672 -0400
+++ mount.c 2017-08-13 19:46:24.658887689 -0400
@@ -82,6 +82,7 @@
static int mountfs(const char *, const char *, const char *,
int, const char *, const char *, int, char *, size_t);
static void prmount(struct statvfs *);
+static void quoteifneeded(const char *, char *, size_t);
__dead static void usage(void);
@@ -566,6 +567,22 @@
return (0);
}
+
+static void
+quoteifneeded(const char *name, char *buf, size_t buflen)
+{
+ const char *sp;
+ const char shops[] = " \t\n'\"&();|<>";
+
+ for (sp = name; *sp; ++sp) {
+ if (strchr(shops, *sp)) {
+ shquote(name, buf, buflen);
+ return;
+ }
+ }
+ strlcpy(buf, name, buflen);
+}
+
static void
prmount(struct statvfs *sfp)
{
@@ -573,9 +590,14 @@
const struct opt *o;
struct passwd *pw;
int f;
+ char mntfrombuf[VFS_MNAMELEN];
+ char mntonbuf[VFS_MNAMELEN];
+
+ quoteifneeded(sfp->f_mntfromname, mntfrombuf, sizeof(mntfrombuf));
+ quoteifneeded(sfp->f_mntonname, mntonbuf, sizeof(mntonbuf));
- (void)printf("%s on %s type %.*s", sfp->f_mntfromname,
- sfp->f_mntonname, (int)sizeof(sfp->f_fstypename),
+ (void)printf("%s on %s type %.*s", mntfrombuf, mntonbuf,
+ (int)sizeof(sfp->f_fstypename),
sfp->f_fstypename);
flags = sfp->f_flag & MNT_VISFLAGMASK;
Home |
Main Index |
Thread Index |
Old Index