diff options
author | Scott Mayhew <smayhew@redhat.com> | 2017-02-15 10:16:35 -0500 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2017-02-15 10:41:59 -0500 |
commit | 1789737ec6dd43c9d1436aeb6c07fab52206f412 (patch) | |
tree | 8de3910340ba6eaa293933cea8549cdd9f24e71e /support/nsm/file.c | |
parent | 0712b5507866d6b3c900623eb1f81fffaec80ae2 (diff) | |
download | nfs-utils-1789737ec6dd43c9d1436aeb6c07fab52206f412.tar.gz nfs-utils-1789737ec6dd43c9d1436aeb6c07fab52206f412.tar.xz nfs-utils-1789737ec6dd43c9d1436aeb6c07fab52206f412.zip |
libnsm.a: refactor nsm_setup_pathnames() and nsm_make_pathname()
Move the logic in nsm_setup_pathnames() and nsm_make_pathname() to
similar generic functions in libmisc.a so that the exportfs and
rpc.mountd programs can make use of them later.
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Scott Mayhew <smayhew@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'support/nsm/file.c')
-rw-r--r-- | support/nsm/file.c | 46 |
1 files changed, 4 insertions, 42 deletions
diff --git a/support/nsm/file.c b/support/nsm/file.c index aafa755..52f5401 100644 --- a/support/nsm/file.c +++ b/support/nsm/file.c @@ -88,6 +88,7 @@ #include "xlog.h" #include "nsm.h" +#include "misc.h" #define RPCARGSLEN (4 * (8 + 1)) #define LINELEN (RPCARGSLEN + SM_PRIV_SIZE * 2 + 1) @@ -170,25 +171,7 @@ __attribute__((__malloc__)) static char * nsm_make_pathname(const char *directory) { - size_t size; - char *path; - int len; - - size = strlen(nsm_base_dirname) + strlen(directory) + 2; - if (size > PATH_MAX) - return NULL; - - path = malloc(size); - if (path == NULL) - return NULL; - - len = snprintf(path, size, "%s/%s", nsm_base_dirname, directory); - if (error_check(len, size)) { - free(path); - return NULL; - } - - return path; + return generic_make_pathname(nsm_base_dirname, directory); } /* @@ -293,29 +276,8 @@ out: _Bool nsm_setup_pathnames(const char *progname, const char *parentdir) { - static char buf[PATH_MAX]; - struct stat st; - char *path; - - /* First: test length of name and whether it exists */ - if (lstat(parentdir, &st) == -1) { - (void)fprintf(stderr, "%s: Failed to stat %s: %s", - progname, parentdir, strerror(errno)); - return false; - } - - /* Ensure we have a clean directory pathname */ - strncpy(buf, parentdir, sizeof(buf)); - path = dirname(buf); - if (*path == '.') { - (void)fprintf(stderr, "%s: Unusable directory %s", - progname, parentdir); - return false; - } - - xlog(D_CALL, "Using %s as the state directory", parentdir); - strncpy(nsm_base_dirname, parentdir, sizeof(nsm_base_dirname)); - return true; + return generic_setup_basedir(progname, parentdir, nsm_base_dirname, + PATH_MAX); } /** |