diff options
author | NeilBrown <neilb@suse.de> | 2013-11-05 14:03:53 -0500 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2013-11-05 14:03:53 -0500 |
commit | d4a408776d611cd62235232d65d488d02fca78e4 (patch) | |
tree | 47e2d232cad7f277746e1e1cdbf66a1bf75fb5af | |
parent | da88f28656da305ed319867211753baac32c4242 (diff) | |
download | nfs-utils-d4a408776d611cd62235232d65d488d02fca78e4.tar.gz nfs-utils-d4a408776d611cd62235232d65d488d02fca78e4.tar.xz nfs-utils-d4a408776d611cd62235232d65d488d02fca78e4.zip |
exportfs: exit with error code if there was any error (take 2).
exportfs currently exits with a non-zero error for some errors,
but not for others.
It does this by having various support routines set the global
variable "export_errno".
Change this to have 'xlog' set export_errno if an ERROR is
reported. That way all errors will be caught.
Note that the exit error code is changed from 22 (EINVAL)
to the more traditional '1'.
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r-- | support/export/hostname.c | 2 | ||||
-rw-r--r-- | support/include/exportfs.h | 3 | ||||
-rw-r--r-- | support/include/xlog.h | 1 | ||||
-rw-r--r-- | support/nfs/exports.c | 6 | ||||
-rw-r--r-- | support/nfs/xlog.c | 5 | ||||
-rw-r--r-- | utils/exportfs/exportfs.c | 43 |
6 files changed, 19 insertions, 41 deletions
diff --git a/support/export/hostname.c b/support/export/hostname.c index e53d692..3e949a1 100644 --- a/support/export/hostname.c +++ b/support/export/hostname.c @@ -175,12 +175,10 @@ host_addrinfo(const char *hostname) case 0: return ai; case EAI_SYSTEM: - export_errno = errno; xlog(D_GENERAL, "%s: failed to resolve %s: (%d) %m", __func__, hostname, errno); break; default: - export_errno = EINVAL; xlog(D_GENERAL, "%s: failed to resolve %s: %s", __func__, hostname, gai_strerror(error)); break; diff --git a/support/include/exportfs.h b/support/include/exportfs.h index 1fbf754..97b2327 100644 --- a/support/include/exportfs.h +++ b/support/include/exportfs.h @@ -179,7 +179,4 @@ struct export_features { struct export_features *get_export_features(void); void fix_pseudoflavor_flags(struct exportent *ep); -/* Record export error. */ -extern int export_errno; - #endif /* EXPORTFS_H */ diff --git a/support/include/xlog.h b/support/include/xlog.h index fd1a3f4..fd34ec2 100644 --- a/support/include/xlog.h +++ b/support/include/xlog.h @@ -35,6 +35,7 @@ struct xlog_debugfac { int df_fac; }; +extern int export_errno; void xlog_open(char *progname); void xlog_stderr(int on); void xlog_syslog(int on); diff --git a/support/nfs/exports.c b/support/nfs/exports.c index d3160d3..d18667f 100644 --- a/support/nfs/exports.c +++ b/support/nfs/exports.c @@ -47,8 +47,6 @@ struct flav_info flav_map[] = { const int flav_map_size = sizeof(flav_map)/sizeof(flav_map[0]); -int export_errno; - static char *efname = NULL; static XFILE *efp = NULL; static int first; @@ -133,7 +131,6 @@ getexportent(int fromkernel, int fromexports) } if (ok < 0) { xlog(L_ERROR, "expected client(options...)"); - export_errno = EINVAL; return NULL; } first = 0; @@ -153,7 +150,6 @@ getexportent(int fromkernel, int fromexports) ok = getexport(exp, sizeof(exp)); if (ok < 0) { xlog(L_ERROR, "expected client(options...)"); - export_errno = EINVAL; return NULL; } } @@ -173,7 +169,6 @@ getexportent(int fromkernel, int fromexports) *opt++ = '\0'; if (!(sp = strchr(opt, ')')) || sp[1] != '\0') { syntaxerr("bad option list"); - export_errno = EINVAL; return NULL; } *sp = '\0'; @@ -590,7 +585,6 @@ parseopts(char *cp, struct exportent *ep, int warn, int *had_subtree_opt_ptr) flname, flline, opt); bad_option: free(opt); - export_errno = EINVAL; return -1; } } else if (strncmp(opt, "anongid=", 8) == 0) { diff --git a/support/nfs/xlog.c b/support/nfs/xlog.c index 6820346..83d07e1 100644 --- a/support/nfs/xlog.c +++ b/support/nfs/xlog.c @@ -38,6 +38,8 @@ static int logmask = 0; /* What will be logged */ static char log_name[256]; /* name of this program */ static int log_pid = -1; /* PID of this program */ +int export_errno = 0; + static void xlog_toggle(int sig); static struct xlog_debugfac debugnames[] = { { "general", D_GENERAL, }, @@ -190,6 +192,9 @@ xlog(int kind, const char* fmt, ...) { va_list args; + if (kind & (L_ERROR|D_GENERAL)) + export_errno = 1; + va_start(args, fmt); xlog_backend(kind, fmt, args); va_end(args); diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c index 6962444..da5fe21 100644 --- a/utils/exportfs/exportfs.c +++ b/utils/exportfs/exportfs.c @@ -35,8 +35,8 @@ #include "xlog.h" static void export_all(int verbose); -static int exportfs(char *arg, char *options, int verbose); -static int unexportfs(char *arg, int verbose); +static void exportfs(char *arg, char *options, int verbose); +static void unexportfs(char *arg, int verbose); static void exports_update(int verbose); static void dump(int verbose, int export_format); static void error(nfs_export *exp, int err); @@ -104,8 +104,6 @@ main(int argc, char **argv) xlog_stderr(1); xlog_syslog(0); - export_errno = 0; - while ((c = getopt(argc, argv, "afhio:ruvs")) != EOF) { switch(c) { case 'a': @@ -187,12 +185,8 @@ main(int argc, char **argv) if (f_all) export_all(f_verbose); else - for (i = optind; i < argc ; i++) { - if(!exportfs(argv[i], options, f_verbose)) { - /* Only flag a generic EINVAL if no errno is set */ - export_errno = (export_errno) ? export_errno : EINVAL; - } - } + for (i = optind; i < argc ; i++) + exportfs(argv[i], options, f_verbose); } /* If we are unexporting everything, then * don't care about what should be exported, as that @@ -205,12 +199,8 @@ main(int argc, char **argv) if (!f_reexport) xtab_export_read(); if (!f_export) - for (i = optind ; i < argc ; i++) { - if (!unexportfs(argv[i], f_verbose)) { - /* Only flag a generic EINVAL if no errno is set */ - export_errno = (export_errno) ? export_errno : EINVAL; - } - } + for (i = optind ; i < argc ; i++) + unexportfs(argv[i], f_verbose); if (!new_cache) rmtab_read(); } @@ -304,10 +294,9 @@ export_all(int verbose) } -static int +static void exportfs(char *arg, char *options, int verbose) { - int rc = 0; struct exportent *eep; nfs_export *exp = NULL; struct addrinfo *ai = NULL; @@ -320,8 +309,7 @@ exportfs(char *arg, char *options, int verbose) if (!path || *path != '/') { xlog(L_ERROR, "Invalid exporting option: %s", arg); - export_errno = EINVAL; - return rc; + return; } if ((htype = client_gettype(hname)) == MCL_FQDN) { @@ -349,29 +337,26 @@ exportfs(char *arg, char *options, int verbose) exp->m_warned = 0; validate_export(exp); - rc = 1; out: freeaddrinfo(ai); - return rc; } -static int +static void unexportfs(char *arg, int verbose) { - int rc = 0; nfs_export *exp; struct addrinfo *ai = NULL; char *path; char *hname = arg; int htype; + int success = 0; if ((path = strchr(arg, ':')) != NULL) *path++ = '\0'; if (!path || *path != '/') { xlog(L_ERROR, "Invalid unexporting option: %s", arg); - export_errno = EINVAL; - return rc; + return; } if ((htype = client_gettype(hname)) == MCL_FQDN) { @@ -411,13 +396,12 @@ unexportfs(char *arg, int verbose) #endif exp->m_xtabent = 0; exp->m_mayexport = 0; - rc = 1; + success = 1; } - if (!rc && verbose) + if (!success) xlog(L_ERROR, "Could not find '%s:%s' to unexport.", arg, path); freeaddrinfo(ai); - return rc; } static int can_test(void) @@ -746,7 +730,6 @@ error(nfs_export *exp, int err) { xlog(L_ERROR, "%s:%s: %s", exp->m_client->m_hostname, exp->m_export.e_path, strerror(err)); - export_errno = (export_errno) ? export_errno : err; } static void |