* Make hasmntval() return an 0 on error, 1 on success and
authorzoulasc <christos@zoulas.com>
Fri, 8 Apr 2016 19:29:33 +0000 (15:29 -0400)
committerzoulasc <christos@zoulas.com>
Fri, 8 Apr 2016 19:29:33 +0000 (15:29 -0400)
  place the value in an argument. Update all users and
  check properly for errors. Get rid of hasmntvalerr().
* Add hasmntvaldelim() which takes a string delimiter. This
  is now used to chop vers=4.1 to 4, so that we can parse the
  version correctly (we don't care about the .1 part yet)

ChangeLog
amd/autil.c
amd/ops_cdfs.c
amd/ops_nfs.c
amd/ops_pcfs.c
amd/ops_ufs.c
amd/srvr_nfs.c
hlfsd/hlfsd.c
include/am_utils.h
libamu/mount_fs.c
libamu/mtab.c

index 99960a898a94a17ab9a7c3f49fbd95566c965193..b09dc8a1482cc66f4b8ff012bc14d2bc7b71b765 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2016-04-08  Christos Zoulas <christos@zoulas.com>
+
+       * Make hasmntval() return an 0 on error, 1 on success and
+         place the value in an argument. Update all users and
+         check properly for errors. Get rid of hasmntvalerr().
+       * Add hasmntvaldelim() which takes a string delimiter. This
+         is now used to chop vers=4.1 to 4, so that we can parse the
+         version correctly (we don't care about the .1 part yet)
+         
 2016-03-31  Christos Zoulas <christos@zoulas.com>
 
        * Fix SEGV on amq time printing.
index efd18ef4202f1f03ed41a91d1c2c779c51dbd95e..35d87089df0ca57ed0590afc701e3c5b2615b27b 100644 (file)
@@ -279,7 +279,7 @@ am_mounted(am_node *mp)
     if (amu_hasmntopt(&mnt, "nounmount") || amu_hasmntopt(&mnt, "noumount"))
       notimeout = 1;
     /* utimeout=N option: user wants to unmount this option AND set timeout */
-    if ((mp->am_timeo = hasmntval(&mnt, "utimeout")) == 0)
+    if (!hasmntval(&mnt, "utimeout", &mp->am_timeo))
       mp->am_timeo = gopt.am_timeo; /* otherwise use default timeout */
     else
       notimeout = 0;
@@ -480,8 +480,7 @@ amfs_mount(am_node *mp, mntfs *mf, char *opts)
     mnt.mnt_type = HIDE_MOUNT_TYPE;
   }
 
-  retry = hasmntval(&mnt, MNTTAB_OPT_RETRY);
-  if (retry <= 0)
+  if (!hasmntval(&mnt, MNTTAB_OPT_RETRY, &retry) || retry <= 0)
     retry = 2;                 /* XXX: default to 2 retries */
 
   /*
@@ -526,7 +525,7 @@ again:
     nfs_args_t nfs_args;
     am_nfs_handle_t *fhp, anh;
 #ifndef HAVE_TRANSPORT_TYPE_TLI
-    u_short port;
+    int port;
     struct sockaddr_in sin;
 #endif /* not HAVE_TRANSPORT_TYPE_TLI */
 
@@ -547,8 +546,7 @@ again:
     /* as per POSIX, sin_len need not be set (used internally by kernel) */
     sin.sin_family = AF_INET;
     sin.sin_addr = myipaddr;
-    port = hasmntval(&mnt, MNTTAB_OPT_PORT);
-    if (port) {
+    if (hasmntval(&mnt, MNTTAB_OPT_PORT, &port) && port > 0 && port < 65536) {
       sin.sin_port = htons(port);
     } else {
       plog(XLOG_ERROR, "no port number specified for %s", dir);
index 6ceb76408b03b2d3d4a1ca8d4d9d0d1fa881a6dc..5c56cd972fa0dae7048e1ec3b82bcde1995ab1b2 100644 (file)
@@ -190,7 +190,12 @@ mount_cdfs(char *mntdir, char *fs_name, char *opts, int on_autofs)
 #endif /* HAVE_CDFS_ARGS_T_ISO_FLAGS */
 
 #ifdef HAVE_CDFS_ARGS_T_ISO_PGTHRESH
-  cdfs_args.iso_pgthresh = hasmntval(&mnt, MNTTAB_OPT_PGTHRESH);
+  {
+    int thresh;
+    if (!hasmntval(&mnt, MNTTAB_OPT_PGTHRESH, &thresh) || thresh < 0)
+      thresh = 0;
+    cdfs_args.iso_pgthresh = thresh;
+  }
 #endif /* HAVE_CDFS_ARGS_T_ISO_PGTHRESH */
 
 #ifdef HAVE_CDFS_ARGS_T_NORRIP
index 2dbfa5b5e2eebb4e95cc341a4da20a285493a1a0..3907a285cb9ea2bcac790a78092ccf18131d3b30 100644 (file)
@@ -888,8 +888,7 @@ mount_nfs_fh(am_nfs_handle_t *fhp, char *mntdir, char *fs_name, mntfs *mf)
   plog(XLOG_INFO, "mount_nfs_fh: NFS version %d", (int) nfs_version);
   plog(XLOG_INFO, "mount_nfs_fh: using NFS transport %s", nfs_proto);
 
-  retry = hasmntval(&mnt, MNTTAB_OPT_RETRY);
-  if (retry <= 0)
+  if (!hasmntval(&mnt, MNTTAB_OPT_RETRY, &retry) || retry <= 0)
     retry = 1;                 /* XXX */
 
   genflags = compute_mount_flags(&mnt);
index b4c8dcd5feccc23d243b33cf360b2370828b6ae5..cf88b64c55d166c3c02b9a5c01fee8a529388bfa 100644 (file)
@@ -139,17 +139,19 @@ mount_pcfs(char *mntdir, char *fs_name, char *opts, int on_autofs)
 #endif /* HAVE_PCFS_ARGS_T_FSPEC */
 
 #ifdef HAVE_PCFS_ARGS_T_MASK
-  pcfs_args.mask = 0777;       /* this may be the msdos file modes */
-  if ((mask = hasmntval(&mnt, MNTTAB_OPT_MASK)) > 0)
+  if (hasmntval(&mnt, MNTTAB_OPT_MASK, &mask) && mask > 0)
     pcfs_args.mask = mask;
+  else
+    pcfs_args.mask = 0777;     /* this may be the msdos file modes */
   if (amuDebug(D_TRACE))
     plog(XLOG_DEBUG, "mount_pcfs: mask=%o (octal)", (u_int) pcfs_args.mask);
 #endif /* HAVE_PCFS_ARGS_T_MASK */
 
 #ifdef HAVE_PCFS_ARGS_T_DIRMASK
-  pcfs_args.dirmask = 0777;    /* this may be the msdos dir modes */
-  if ((mask = hasmntval(&mnt, MNTTAB_OPT_DIRMASK)) > 0)
+  if (hasmntval(&mnt, MNTTAB_OPT_DIRMASK, &mask) && mask > 0)
     pcfs_args.dirmask = mask;
+  else
+    pcfs_args.dirmask = 0777;    /* this may be the msdos dir modes */
   if (amuDebug(D_TRACE))
     plog(XLOG_DEBUG, "mount_pcfs: dirmask=%o (octal)", (u_int) pcfs_args.dirmask);
 #endif /* HAVE_PCFS_ARGS_T_DIRMASK */
index 0d8f3068dbe50518c59044dad150720c9ecc4ea4..858cb6be3444afcbd552f9e1ae4428ad36d8fe71 100644 (file)
@@ -144,7 +144,11 @@ mount_ufs(char *mntdir, char *fs_name, char *opts, int on_autofs)
 #endif /* HAVE_UFS_ARGS_T_FSPEC */
 
 #ifdef HAVE_UFS_ARGS_T_UFS_PGTHRESH
-  ufs_args.ufs_pgthresh = hasmntval(&mnt, MNTTAB_OPT_PGTHRESH);
+  {
+    int thresh;
+    if (!hasmntval(&mnt, MNTTAB_OPT_PGTHRESH, &thresh) || thresh < 0)
+       thresh = 0;
+    ufs_args.ufs_pgthresh = thresh;
 #endif /* HAVE_UFS_ARGS_T_UFS_PGTHRESH */
 
   /*
index 1418a1a85ea47ae57864b90e8d7aebbfaae3b6ac..996243118d855c1130a126598d992d0758d8232f 100644 (file)
@@ -704,10 +704,10 @@ find_nfs_srvr(mntfs *mf)
   struct hostent *hp = NULL;
   struct sockaddr_in *ip = NULL;
   u_long nfs_version = 0;      /* default is no version specified */
+  int val;
   u_long best_nfs_version = 0;
   char *nfs_proto = NULL;      /* no IP protocol either */
-  int nfs_port = 0;
-  int nfs_port_opt = 0;
+  int nfs_port;
   int fserver_is_down = 0;
 
   if (mf->mf_fo == NULL) {
@@ -721,7 +721,8 @@ find_nfs_srvr(mntfs *mf)
    * are required or not.  < 0 = no pings.
    */
   mnt.mnt_opts = mf->mf_mopts;
-  pingval = hasmntval(&mnt, "ping");
+  if (!hasmntval(&mnt, "ping", &pingval) || pingval < 0)
+    pingval = 0;
 
   if (mf->mf_flags & MFF_NFS_SCALEDOWN) {
     /*
@@ -739,7 +740,10 @@ find_nfs_srvr(mntfs *mf)
      * to decide the highest NFS version to try.
      */
 #ifdef MNTTAB_OPT_VERS
-    nfs_version = hasmntval(&mnt, MNTTAB_OPT_VERS);
+    if (!hasmntvaldelim(&mnt, MNTTAB_OPT_VERS, ",.", &val) || val < 0)
+      nfs_version = 0;
+    else
+      nfs_version = val;
 #endif /* MNTTAB_OPT_VERS */
 
 #ifdef MNTTAB_OPT_PROTO
@@ -934,11 +938,11 @@ find_nfs_srvr(mntfs *mf)
    * If the port has been determined from the portmapper, use that.
    * Default to NFS_PORT otherwise (cf. RFC 2054, 3).
    */
-  nfs_port_opt = hasmntval(&mnt, MNTTAB_OPT_PORT);
-  if (nfs_port_opt > 0)
-    nfs_port = htons(nfs_port_opt);
-  if (!nfs_port)
+  if (!hasmntval(&mnt, MNTTAB_OPT_PORT, &nfs_port)
+    || nfs_port > 65535 || nfs_port <= 0)
     nfs_port = htons(NFS_PORT);
+  else
+    nfs_port = htons(nfs_port);
 
   dlog("%s: using port %d for nfs on %s", __func__,
     (int) ntohs(nfs_port), host);
@@ -1050,7 +1054,9 @@ no_dns:
   fs->fs_flags |= FSF_PING_UNINIT; /* pinger hasn't been initialized */
   np = ALLOC(struct nfs_private);
   memset((voidp) np, 0, sizeof(*np));
-  np->np_mountd = htons(hasmntval(&mnt, "mountport"));
+  if (!hasmntval(&mnt, "mountport", &val) || val < 0)
+    val = 0;
+  np->np_mountd = htons(val);
   if (np->np_mountd == 0) {
     np->np_mountd_inval = 'Y';
     np->np_xid = XID_ALLOC();
index 701abcdca515455fbf266bb51b6ded5312e54d01..4968ed0f52de0f02067c6876071ea056ef8abe49 100644 (file)
@@ -530,8 +530,7 @@ main(int argc, char *argv[])
 
   genflags = compute_mount_flags(&mnt);
 
-  retry = hasmntval(&mnt, MNTTAB_OPT_RETRY);
-  if (retry <= 0)
+  if (!hasmntval(&mnt, MNTTAB_OPT_RETRY, &retry) || retry <= 0)
     retry = 1;                 /* XXX */
 
   memmove(&anh.v2, root_fhp, sizeof(*root_fhp));
index ff13c26648c05f309d7291d9fd9bd3b712ac96dd..dfe15df08fdfde7775c19cf29f3a684f39cfecd2 100644 (file)
@@ -290,8 +290,8 @@ extern int compute_mount_flags(mntent_t *);
 extern void discard_nfs_args(void *, u_long);
 extern u_long get_amd_program_number(void);
 extern int getcreds(struct svc_req *, uid_t *, gid_t *, SVCXPRT *);
-extern int hasmntval(mntent_t *, char *);
-extern unsigned int hasmntvalerr(mntent_t *, char *, int *);
+extern int hasmntval(mntent_t *, char *, int *);
+extern int hasmntvaldelim(mntent_t *, char *, const char *, int *);
 extern char *hasmntstr(mntent_t *, char *);
 extern char *hasmnteq(mntent_t *, char *);
 extern char *haseq(char *);
index 366eb8b0cbd73799d295b16f13926e0d873d4f28..1147ef9a86abcd99a618c9580410558d9ff1f9a4 100644 (file)
@@ -188,8 +188,10 @@ static void
 addvers(char *zopts, size_t l, mntent_t *mnt, u_long have_vers,
   u_long want_vers)
 {
-  if (have_vers == want_vers &&
-      hasmntval(mnt, MNTTAB_OPT_VERS) != want_vers) {
+  int val;
+  if (have_vers == want_vers
+    && hasmntvaldelim(mnt, MNTTAB_OPT_VERS, ".,", &val)
+    && (u_long)val != want_vers) {
     char optsbuf[48];
     xsnprintf(optsbuf, sizeof(optsbuf),
              "%s=%d", MNTTAB_OPT_VERS, want_vers);
@@ -391,7 +393,7 @@ compute_nfs_attrcache_flags(struct nfs_common_args *nap, mntent_t *mntp)
    * on the values of the attribute caches.
    */
 #ifdef MNTTAB_OPT_ACTIMEO
-  err_acval = hasmntvalerr(mntp, MNTTAB_OPT_ACTIMEO, &acval);  /* attr cache timeout (sec) */
+  err_acval = !hasmntval(mntp, MNTTAB_OPT_ACTIMEO, &acval);    /* attr cache timeout (sec) */
 #endif /* MNTTAB_OPT_ACTIMEO */
 
   /*** acregmin ***/
@@ -402,7 +404,7 @@ compute_nfs_attrcache_flags(struct nfs_common_args *nap, mntent_t *mntp)
   } else {
 # ifdef MNTTAB_OPT_ACREGMIN
     int tmp;
-    err_acrdmm = hasmntvalerr(mntp, MNTTAB_OPT_ACREGMIN, &tmp);
+    err_acrdmm = !hasmntval(mntp, MNTTAB_OPT_ACREGMIN, &tmp);
     nap->acregmin = tmp;
 # else /* not MNTTAB_OPT_ACREGMIN */
     nap->acregmin = 0;
@@ -423,7 +425,7 @@ compute_nfs_attrcache_flags(struct nfs_common_args *nap, mntent_t *mntp)
   } else {
 # ifdef MNTTAB_OPT_ACREGMAX
     int tmp;
-    err_acrdmm = hasmntvalerr(mntp, MNTTAB_OPT_ACREGMAX, &tmp);
+    err_acrdmm = !hasmntval(mntp, MNTTAB_OPT_ACREGMAX, &tmp);
     nap->acregmax = tmp;
 # else /* not MNTTAB_OPT_ACREGMAX */
     nap->acregmax = 0;
@@ -444,7 +446,7 @@ compute_nfs_attrcache_flags(struct nfs_common_args *nap, mntent_t *mntp)
   } else {
 # ifdef MNTTAB_OPT_ACDIRMIN
     int tmp;
-    err_acrdmm = hasmntvalerr(mntp, MNTTAB_OPT_ACDIRMIN, &tmp);
+    err_acrdmm = !hasmntval(mntp, MNTTAB_OPT_ACDIRMIN, &tmp);
     nap->acdirmin = tmp;
 # else /* not MNTTAB_OPT_ACDIRMIN */
     nap->acdirmin = 0;
@@ -465,7 +467,7 @@ compute_nfs_attrcache_flags(struct nfs_common_args *nap, mntent_t *mntp)
   } else {
 # ifdef MNTTAB_OPT_ACDIRMAX
     int tmp;
-    err_acrdmm = hasmntvalerr(mntp, MNTTAB_OPT_ACDIRMAX, &tmp);
+    err_acrdmm = !hasmntval(mntp, MNTTAB_OPT_ACDIRMAX, &tmp);
     nap->acdirmax = tmp;
 # else /* not MNTTAB_OPT_ACDIRMAX */
     nap->acdirmax = 0;
@@ -492,6 +494,7 @@ static void
 compute_nfs_common_args(struct nfs_common_args *nap, mntent_t *mntp,
     const char *nfs_proto, u_long nfs_version)
 {
+  int val;
 #ifdef MNT2_NFS_OPT_TCP
   if (nfs_proto && STREQ(nfs_proto, "tcp"))
     nap->flags |= MNT2_NFS_OPT_TCP;
@@ -536,7 +539,10 @@ compute_nfs_common_args(struct nfs_common_args *nap, mntent_t *mntp,
 # endif /* not MNTTAB_OPT_RESVPORT */
 #endif /* MNT2_NFS_OPT_RESVPORT */
 
-  nap->rsize = hasmntval(mntp, MNTTAB_OPT_RSIZE);
+  if (!hasmntval(mntp, MNTTAB_OPT_RSIZE, &val) || val <= 0)
+    nap->rsize = 0;
+  else
+    nap->rsize = val;
 #ifdef MNT2_NFS_OPT_RSIZE
   if (nap->rsize)
     nap->flags |= MNT2_NFS_OPT_RSIZE;
@@ -544,7 +550,10 @@ compute_nfs_common_args(struct nfs_common_args *nap, mntent_t *mntp,
   if (nfs_version == NFS_VERSION && nap->rsize > 8192)
     nap->rsize = 8192;
 
-  nap->wsize = hasmntval(mntp, MNTTAB_OPT_WSIZE);
+  if (!hasmntval(mntp, MNTTAB_OPT_WSIZE, &val) || val <= 0)
+    nap->wsize = 0;
+  else
+    nap->wsize = val;
 #ifdef MNT2_NFS_OPT_WSIZE
   if (nap->wsize)
     nap->flags |= MNT2_NFS_OPT_WSIZE;
@@ -552,13 +561,19 @@ compute_nfs_common_args(struct nfs_common_args *nap, mntent_t *mntp,
   if (nfs_version == NFS_VERSION && nap->wsize > 8192)
     nap->wsize = 8192;
 
-  nap->timeo = hasmntval(mntp, MNTTAB_OPT_TIMEO);
+  if (!hasmntval(mntp, MNTTAB_OPT_TIMEO, &val) || val <= 0)
+    nap->timeo = 0;
+  else
+    nap->timeo = val;
 #ifdef MNT2_NFS_OPT_TIMEO
   if (nap->timeo)
     nap->flags |= MNT2_NFS_OPT_TIMEO;
 #endif /* MNT2_NFS_OPT_TIMEO */
 
-  nap->retrans = hasmntval(mntp, MNTTAB_OPT_RETRANS);
+  if (!hasmntval(mntp, MNTTAB_OPT_RETRANS, &val) || val <= 0)
+    nap->retrans = 0;
+  else
+    nap->retrans = val;
 #ifdef MNT2_NFS_OPT_RETRANS
   if (nap->retrans)
     nap->flags |= MNT2_NFS_OPT_RETRANS;
@@ -861,6 +876,7 @@ compute_nfs23_args(nfs_args_t *nap,
                   char *host_name,
                   char *fs_name)
 {
+  int val;
   struct nfs_common_args a;
   /* initialize just in case */
   memset((voidp) nap, 0, sizeof(nfs_args_t));
@@ -995,18 +1011,30 @@ compute_nfs23_args(nfs_args_t *nap,
   /************************************************************************/
 
 #ifdef MNT2_NFS_OPT_BIODS
-  if ((nap->biods = hasmntval(mntp, MNTTAB_OPT_BIODS)))
+  if (!hasmntval(mntp, MNTTAB_OPT_BIODS, &val) || val <= 0)
+    nap->biods = 0;
+  else {
+    nap->biods = val;
     nap->flags |= MNT2_NFS_OPT_BIODS;
+  }
 #endif /* MNT2_NFS_OPT_BIODS */
 
 #ifdef MNTTAB_OPT_SYMTTL       /* symlink cache time-to-live */
-  if ((nap->symttl = hasmntval(mntp, MNTTAB_OPT_SYMTTL)))
+  if (!hasmntval(mntp, MNTTAB_OPT_SYMTTL, &val) || val <= 0)
+    nap->symttl = 0;
+  else {
+    nap->symttl = val;
     nap->flags |= MNT2_NFS_OPT_SYMTTL;
+  }
 #endif /* MNTTAB_OPT_SYMTTL */
 
 #ifdef MNT2_NFS_OPT_PGTHRESH   /* paging threshold */
-  if ((nap->pg_thresh = hasmntval(mntp, MNTTAB_OPT_PGTHRESH)))
+  if (!hasmntval(mntp, MNTTAB_OPT_PGTHRESH, &val) || val <= 0)
+    nap->pg_thresh = 0;
+  else {
+    nap->pg_thresh = val;
     nap->flags |= MNT2_NFS_OPT_PGTHRESH;
+  }
 #endif /* MNT2_NFS_OPT_PGTHRESH */
 
 #if defined(MNT2_NFS_OPT_POSIX) && defined(MNTTAB_OPT_POSIX)
@@ -1020,7 +1048,7 @@ compute_nfs23_args(nfs_args_t *nap,
 
 #ifdef HAVE_TRANSPORT_TYPE_TLI
   /* set up syncaddr field */
-  nap->syncaddr = (struct netbuf *) NULL;
+  nap->syncaddr = NULL;
 
   /* set up knconf field */
   if (get_knetconfig(&nap->knconf, nfsncp, nfs_proto) < 0) {
@@ -1043,9 +1071,12 @@ compute_nfs23_args(nfs_args_t *nap,
 #endif /* HAVE_NFS_ARGS_T_OPTSTR */
 
 #if defined(MNT2_NFS_OPT_MAXGRPS) && defined(MNTTAB_OPT_MAXGROUPS)
-  nap->maxgrouplist = hasmntval(mntp, MNTTAB_OPT_MAXGROUPS);
-  if (nap->maxgrouplist != 0)
+  if (!hasmntval(mntp, MNTTAB_OPT_MAXGROUPS, &val) || val <= 0)
+    nap->maxgrouplist = 0;
+  else {
+    nap->maxgrouplist = val;
     nap->flags |= MNT2_NFS_OPT_MAXGRPS;
+  }
 #endif /* defined(MNT2_NFS_OPT_MAXGRPS) && defined(MNTTAB_OPT_MAXGROUPS) */
 
   /************************************************************************/
@@ -1267,6 +1298,7 @@ compute_nfs4_args(nfs4_args_t *nap,
 {
   char *s;
   struct nfs_common_args a;
+  int val;
   uint16_t nfs_port;
 
   /* initialize just in case */
@@ -1304,11 +1336,10 @@ compute_nfs4_args(nfs4_args_t *nap,
   nap->host_addr = xmalloc(nap->host_addrlen);
   memcpy(nap->host_addr, ip_addr, nap->host_addrlen);
 
-  nfs_port = hasmntval(mntp, MNTTAB_OPT_PORT);
-  if (nfs_port == 0)
+  if (!hasmntval(mntp, MNTTAB_OPT_PORT, &val) || val <= 0 || val > 65536)
     nfs_port = htons(NFS_PORT);
   else
-    nfs_port = htons(nfs_port);
+    nfs_port = htons(val);
 
   ((struct sockaddr_in *)nap->host_addr)->sin_port = nfs_port;
 
@@ -1341,9 +1372,13 @@ compute_nfs4_args(nfs4_args_t *nap,
 #endif /* MNT2_NFS_OPT_POSIX && MNTTAB_OPT_POSIX */
 
 #if defined(MNT2_NFS_OPT_MAXGRPS) && defined(MNTTAB_OPT_MAXGROUPS)
-  nap->maxgrouplist = hasmntval(mntp, MNTTAB_OPT_MAXGROUPS);
-  if (nap->maxgrouplist != 0)
+  nap->maxgrouplist = 
+  if (!hasmntval(mntp, MNTTAB_OPT_MAXGROUPS, &val) || val <= 0)
+    nap->maxgrouplist = 0;
+  else {
+    nap->maxgrouplist = val;
     nap->flags |= MNT2_NFS_OPT_MAXGRPS;
+  }
 #endif /* defined(MNT2_NFS_OPT_MAXGRPS) && defined(MNTTAB_OPT_MAXGROUPS) */
 
 #ifdef HAVE_NFS_ARGS_T_OPTSTR
index ee603af34359240c50710ae646deb36d71b5ea73..737f1b5567b478458a03df008203cd2ad4c6a82e 100644 (file)
@@ -133,22 +133,12 @@ hasmnteq(mntent_t *mnt, char *opt)
 
 
 /*
- * Wrapper around hasmntvalerr(), which retains backwards compatibiliy with
- * older use of hasmntval().
- *
- * XXX: eventually, all use of hasmntval() should be replaced with
- * hasmntvalerr().
+ * Wrapper around hasmntvaldelim(), which uses the standard "," delim
  */
 int
-hasmntval(mntent_t *mnt, char *opt)
+hasmntval(mntent_t *mnt, char *opt, int *valp)
 {
-  int err, val = 0;
-
-  err = hasmntvalerr(mnt, opt, &val);
-  if (err)        /* if there was an error (hasmntvalerr returned 1) */
-    return 0;     /* redundant: val==0 above, but leave here for clarity */
-  /* otherwise there was no error */
-  return val;
+  return hasmntvaldelim(mnt, opt, ",", valp);
 }
 
 
@@ -158,36 +148,31 @@ hasmntval(mntent_t *mnt, char *opt)
  * valp (argument won't be touched if no value is set, for example due to an
  * error).
  *
- * Returns non-zero (1) on error; returns 0 on success.
- *
- * XXX: eventually, all use of hasmntval() should be replaced with
- * hasmntvalerr().
+ * Returns 0 on error; returns 1 on success.
  */
-unsigned int
-hasmntvalerr(mntent_t *mnt, char *opt, int *valp)
+int
+hasmntvaldelim(mntent_t *mnt, char *opt, const char *delim, int *valp)
 {
   char *str = amu_hasmntopt(mnt, opt);
-  int err = 1;              /* 1 means no good value was set (an error) */
   char *eq, *endptr;
   long int i;
 
   /* exit if no option specificed */
-  if (!str) {
-    goto out;
-  }
+  if (!str)
+    return 0;
 
   eq = hasmnteq(mnt, opt);
 
   if (!eq) {             /* no argument to option ('=' sign was missing) */
     plog(XLOG_MAP, "numeric option to \"%s\" missing", opt);
-    goto out;
+    return 0;
   }
 
   /* if got here, then we had an '=' after option name */
   endptr = NULL;
   i = strtol(eq, &endptr, 0); /* hex and octal allowed ;-) */
   if (!endptr ||
-      (endptr != eq && (*endptr == ',' || *endptr == '\0'))) {
+      (endptr != eq && (*endptr == '\0' || strchr(delim, *endptr)))) {
       /*
        * endptr set means strtol saw a non-digit.  If the non-digit is a
        * comma, it's probably the start of the next option.  If the comma is
@@ -198,15 +183,13 @@ hasmntvalerr(mntent_t *mnt, char *opt, int *valp)
        * string.
        */
     *valp = (int) i;           /* set good value */
-    err = 0;                   /* no error */
+    return 1;
   } else {
     /* whatever was after the '=' sign wasn't a number */
     plog(XLOG_MAP, "invalid numeric option in \"%s\": \"%s\"", opt, str);
     /* fall through to error/exit processing */
+    return 0;
   }
-
- out:
-  return err;
 }