From: neilbrown Date: Mon, 2 Sep 2002 02:14:53 +0000 (+0000) Subject: Support "-P path" in statd as alternate to /var/lib/nfs X-Git-Tag: nfs-utils-1-0-2-pre1~1 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=9bea78d8f36cd5ab75d18e32224f0b90a635128c;p=nfs-utils.git Support "-P path" in statd as alternate to /var/lib/nfs --- diff --git a/ChangeLog b/ChangeLog index c50ca92..363141c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2002-09-02 Juan Gomez + NeilBrown + + statd to have " -P directory" arg to use that directory instead + of /var/lib/nfs. This is useful for fail-over clusters. + + * utils/statd/statd.h: define SM_DIR etc as var, not const. + * utils/statd/statd.c: define "-P" option to set SM_* + appropriately. + * utils/statd/monitor.c: sprintf to cope with SM_DIR not being + a constant any more. + * utils/statd/notify.c: ditto. + * utils/statd/statd.man: document -P option. + 2002-08-26 Chip Salzenberg * utils/nfsd/nfsd.man: Fix typo. diff --git a/utils/statd/monitor.c b/utils/statd/monitor.c index 27c409f..732bf82 100644 --- a/utils/statd/monitor.c +++ b/utils/statd/monitor.c @@ -168,7 +168,7 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) */ path=xmalloc(strlen(SM_DIR)+strlen(mon_name)+2); - sprintf(path, SM_DIR "/%s", mon_name); + sprintf(path, "%s/%s", SM_DIR, mon_name); if ((fd = open(path, O_WRONLY|O_SYNC|O_CREAT, S_IRUSR|S_IWUSR)) < 0) { /* Didn't fly. We won't monitor. */ log(L_ERROR, "creat(%s) failed: %m", path); diff --git a/utils/statd/notify.c b/utils/statd/notify.c index 89d2946..c3b4ca5 100644 --- a/utils/statd/notify.c +++ b/utils/statd/notify.c @@ -55,7 +55,7 @@ notify_hosts(void) char *fname; fname=xmalloc(strlen(SM_BAK_DIR)+sizeof(de->d_name)+2); dprintf(L_DEBUG, "We're on our own notify list?!?"); - sprintf(fname, SM_BAK_DIR "/%s", de->d_name); + sprintf(fname, "%s/%s", SM_BAK_DIR, de->d_name); if (unlink(fname)) log(L_ERROR, "unlink(%s): %s", fname, strerror(errno)); diff --git a/utils/statd/statd.c b/utils/statd/statd.c index 4fc135a..3a6ed61 100644 --- a/utils/statd/statd.c +++ b/utils/statd/statd.c @@ -24,6 +24,17 @@ #include #include +/* Added to enable specification of state directory path at run-time + * j_carlos_gomez@yahoo.com + */ + +char * DIR_BASE = DEFAULT_DIR_BASE; + +char * SM_DIR = DEFAULT_SM_DIR; +char * SM_BAK_DIR = DEFAULT_SM_BAK_DIR; +char * SM_STAT_PATH = DEFAULT_SM_STAT_PATH; + +/* ----- end of state directory path stuff ------- */ short int restart = 0; int run_mode = 0; /* foreground logging mode */ @@ -43,6 +54,7 @@ static struct option longopts[] = { "outgoing-port", 1, 0, 'o' }, { "port", 1, 0, 'p' }, { "name", 1, 0, 'n' }, + { "state-directory-path", 1, 0, 'P' }, { NULL, 0, 0, 0 } }; @@ -128,6 +140,7 @@ usage() fprintf(stderr," -o, --outgoing-port Port for outgoing connections\n"); fprintf(stderr," -V, -v, --version Display version information and exit.\n"); fprintf(stderr," -n, --name Specify a local hostname.\n"); + fprintf(stderr," -P State directory path.\n"); } /* @@ -161,7 +174,7 @@ int main (int argc, char **argv) MY_NAME = NULL; /* Process command line switches */ - while ((arg = getopt_long(argc, argv, "h?vVFdn:p:o:", longopts, NULL)) != EOF) { + while ((arg = getopt_long(argc, argv, "h?vVFdn:p:o:P:", longopts, NULL)) != EOF) { switch (arg) { case 'V': /* Version */ case 'v': @@ -194,6 +207,36 @@ int main (int argc, char **argv) case 'n': /* Specify local hostname */ MY_NAME = xstrdup(optarg); break; + case 'P': + + if ((DIR_BASE = xstrdup(optarg)) == NULL) { + fprintf(stderr, "%s: xstrdup(%s) failed!\n", + argv[0], optarg); + exit(1); + } + + SM_DIR = xmalloc(strlen(DIR_BASE) + 1 + sizeof("sm")); + SM_BAK_DIR = xmalloc(strlen(DIR_BASE) + 1 + sizeof("sm.bak")); + SM_STAT_PATH = xmalloc(strlen(DIR_BASE) + 1 + sizeof("state")); + + if ((SM_DIR == NULL) + || (SM_BAK_DIR == NULL) + || (SM_STAT_PATH == NULL)) { + + fprintf(stderr, "%s: xmalloc() failed!\n", + argv[0]); + exit(1); + } + if (DIR_BASE[strlen(DIR_BASE)-1] == '/') { + sprintf(SM_DIR, "%ssm", DIR_BASE ); + sprintf(SM_BAK_DIR, "%ssm.bak", DIR_BASE ); + sprintf(SM_STAT_PATH, "%sstate", DIR_BASE ); + } else { + sprintf(SM_DIR, "%s/sm", DIR_BASE ); + sprintf(SM_BAK_DIR, "%s/sm.bak", DIR_BASE ); + sprintf(SM_STAT_PATH, "%s/state", DIR_BASE ); + } + break; case '?': /* heeeeeelllllllpppp? heh */ case 'h': usage(); diff --git a/utils/statd/statd.h b/utils/statd/statd.h index 5476d50..5e2b6fd 100644 --- a/utils/statd/statd.h +++ b/utils/statd/statd.h @@ -14,13 +14,23 @@ * Paths and filenames. */ #if defined(NFS_STATEDIR) -# define DIR_BASE NFS_STATEDIR "/" +# define DEFAULT_DIR_BASE NFS_STATEDIR "/" #else -# define DIR_BASE "/var/lib/nfs/" +# define DEFAULT_DIR_BASE "/var/lib/nfs/" #endif -#define SM_DIR DIR_BASE "sm" -#define SM_BAK_DIR DIR_BASE "sm.bak" -#define SM_STAT_PATH DIR_BASE "state" + +#define DEFAULT_SM_DIR DEFAULT_DIR_BASE "sm" +#define DEFAULT_SM_BAK_DIR DEFAULT_DIR_BASE "sm.bak" +#define DEFAULT_SM_STAT_PATH DEFAULT_DIR_BASE "state" + +/* Added to support run-time specification of state directory path. + * j_carlos_gomez@yahoo.com + */ + +extern char * DIR_BASE; +extern char * SM_DIR; +extern char * SM_BAK_DIR; +extern char * SM_STAT_PATH; /* * Status definitions. diff --git a/utils/statd/statd.man b/utils/statd/statd.man index dbe8be1..2b10803 100644 --- a/utils/statd/statd.man +++ b/utils/statd/statd.man @@ -89,6 +89,12 @@ a standard port number that always or usually assigns. Specifying a port may be useful when implementing a firewall. .TP +.BI "\-P," "" " \-\-state\-directory\-path " directory +specify a directory in which to place statd state information. +If this option is not specified the default of +.BR /var/lib/nfs +is used. +.TP .B -? Causes .B rpc.statd