From: Erez Zadok Date: Wed, 26 Oct 2005 14:59:19 +0000 (+0000) Subject: * amd/amq_subr.c (amqproc_pawd_1_svc): repeatedly resolve path in X-Git-Tag: am-utils-6_2a2~30 X-Git-Url: https://git.fsl.cs.sunysb.edu/?a=commitdiff_plain;h=245d30750852c121ac7da8f271651db951706bf5;p=am-utils-6.1.git * amd/amq_subr.c (amqproc_pawd_1_svc): repeatedly resolve path in Amd, not in pawd (to avoid repeated network RPCs). * amq/pawd.c (transform_dir): move repeated path resolution into Amd. --- diff --git a/ChangeLog b/ChangeLog index d9f1fc6..14838ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-10-26 Erez Zadok + + * amd/amq_subr.c (amqproc_pawd_1_svc): repeatedly resolve path in + Amd, not in pawd (to avoid repeated network RPCs). + + * amq/pawd.c (transform_dir): move repeated path resolution into Amd. + 2005-10-25 Erez Zadok * amq/pawd.c (transform_dir): resolve path repeatedly until diff --git a/amd/amq_subr.c b/amd/amq_subr.c index 8615508..10cdd72 100644 --- a/amd/amq_subr.c +++ b/amd/amq_subr.c @@ -192,37 +192,58 @@ amqproc_getpid_1_svc(voidp argp, struct svc_req *rqstp) } -/* process PAWD string of remote pawd tool */ +/* + * Process PAWD string of remote pawd tool. + * + * We repeat the resolution of the string until the resolved string resolves + * to itself. This ensures that we follow path resolutions through all + * possible Amd mount points until we reach some sort of convergence. To + * prevent possible infinite loops, we break out of this loop if the strings + * do not converge after MAX_PAWD_TRIES times. + */ amq_string * amqproc_pawd_1_svc(voidp argp, struct svc_req *rqstp) { static amq_string res; - int index, len; +#define MAX_PAWD_TRIES 10 + int index, len, maxagain = MAX_PAWD_TRIES; am_node *mp; char *mountpoint; char *dir = *(char **) argp; static char tmp_buf[MAXPATHLEN]; - - tmp_buf[0] = '\0'; /* default is empty string: no match */ - for (mp = get_first_exported_ap(&index); - mp; - mp = get_next_exported_ap(&index)) { - if (STREQ(mp->am_mnt->mf_ops->fs_type, "toplvl")) - continue; - if (STREQ(mp->am_mnt->mf_ops->fs_type, "auto")) - continue; - mountpoint = (mp->am_link ? mp->am_link : mp->am_mnt->mf_mount); - len = strlen(mountpoint); - if (len == 0) - continue; - if (!NSTREQ(mountpoint, dir, len)) - continue; - if (dir[len] != '\0' && dir[len] != '/') - continue; - xstrlcpy(tmp_buf, mp->am_path, sizeof(tmp_buf)); - xstrlcat(tmp_buf, &dir[len], sizeof(tmp_buf)); - break; - } + char prev_buf[MAXPATHLEN]; + + tmp_buf[0] = prev_buf[0] = '\0'; /* default is empty string: no match */ + do { + for (mp = get_first_exported_ap(&index); + mp; + mp = get_next_exported_ap(&index)) { + if (STREQ(mp->am_mnt->mf_ops->fs_type, "toplvl")) + continue; + if (STREQ(mp->am_mnt->mf_ops->fs_type, "auto")) + continue; + mountpoint = (mp->am_link ? mp->am_link : mp->am_mnt->mf_mount); + len = strlen(mountpoint); + if (len == 0) + continue; + if (!NSTREQ(mountpoint, dir, len)) + continue; + if (dir[len] != '\0' && dir[len] != '/') + continue; + xstrlcpy(tmp_buf, mp->am_path, sizeof(tmp_buf)); + xstrlcat(tmp_buf, &dir[len], sizeof(tmp_buf)); + break; + } /* end of "for" loop */ + /* once tmp_buf and prev_buf are equal, break out of "do" loop */ + if (STREQ(tmp_buf, prev_buf)) + break; + else + xstrlcpy(prev_buf, tmp_buf, sizeof(prev_buf)); + } while (--maxagain); + /* check if we couldn't resolve the string after MAX_PAWD_TRIES times */ + if (maxagain <= 0) + plog(XLOG_WARNING, "path \"%s\" did not resolve after %d tries", + tmp_buf, MAX_PAWD_TRIES); res = tmp_buf; return &res; diff --git a/amq/pawd.c b/amq/pawd.c index a7d77f6..1b44202 100644 --- a/amq/pawd.c +++ b/amq/pawd.c @@ -57,8 +57,6 @@ #include #include -/* maximum number of transformations for each path */ -#define MAX_LOOP 10 /* statics */ static char *localhost = "localhost"; @@ -185,7 +183,6 @@ transform_dir(char *dir) struct timeval tmo = {10, 0}; char *dummystr; amq_string *spp; - int again = 1, maxloop = MAX_LOOP; #ifdef DISK_HOME_HACK if (ch = hack_name(dir)) @@ -212,21 +209,11 @@ transform_dir(char *dir) return dir; xstrlcpy(transform, dir, sizeof(transform)); - while (again) { - if (--maxloop <= 0) { - fprintf(stderr, "pawd: exceeded maximum no. of transformations (%d)\n", - MAX_LOOP); - break; - } - again = 0; - dummystr = transform; - spp = amqproc_pawd_1((amq_string *) &dummystr, clnt); - if (spp && *spp && **spp) { - if (STREQ(transform, *spp)) - again++; - xstrlcpy(transform, *spp, sizeof(transform)); - XFREE(*spp); - } + dummystr = transform; + spp = amqproc_pawd_1((amq_string *) &dummystr, clnt); + if (spp && *spp && **spp) { + xstrlcpy(transform, *spp, sizeof(transform)); + XFREE(*spp); } clnt_destroy(clnt); return transform;