diff options
author | NeilBrown <neilb@suse.de> | 2013-10-22 04:36:54 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2013-10-22 04:36:54 -0400 |
commit | 232eb7ad09f9fd2ae4918699f850e4f8cadc2632 (patch) | |
tree | 75ee4dd5848ec657b794424e2000eed4f3daea9b /utils/exportfs/exportfs.c | |
parent | efe3c8d6cb4fc35909a64c0535087676a189fa5f (diff) | |
download | nfs-utils-232eb7ad09f9fd2ae4918699f850e4f8cadc2632.tar.gz nfs-utils-232eb7ad09f9fd2ae4918699f850e4f8cadc2632.tar.xz nfs-utils-232eb7ad09f9fd2ae4918699f850e4f8cadc2632.zip |
exportfs: exit with error code if there was any error.
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>
Diffstat (limited to 'utils/exportfs/exportfs.c')
-rw-r--r-- | utils/exportfs/exportfs.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c index 52fc03d..318deb3 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 void exportfs(char *arg, char *options, int verbose); -static void unexportfs(char *arg, int verbose); +static int exportfs(char *arg, char *options, int verbose); +static int 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); @@ -187,8 +187,12 @@ main(int argc, char **argv) if (f_all) export_all(f_verbose); else - for (i = optind; i < argc ; i++) - exportfs(argv[i], options, f_verbose); + 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; + } + } } /* If we are unexporting everything, then * don't care about what should be exported, as that @@ -201,8 +205,12 @@ main(int argc, char **argv) if (!f_reexport) xtab_export_read(); if (!f_export) - for (i = optind ; i < argc ; i++) - unexportfs(argv[i], f_verbose); + 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; + } + } if (!new_cache) rmtab_read(); } @@ -296,9 +304,10 @@ export_all(int verbose) } -static void +static int exportfs(char *arg, char *options, int verbose) { + int rc = 0; struct exportent *eep; nfs_export *exp = NULL; struct addrinfo *ai = NULL; @@ -311,7 +320,8 @@ exportfs(char *arg, char *options, int verbose) if (!path || *path != '/') { xlog(L_ERROR, "Invalid exporting option: %s", arg); - return; + export_errno = EINVAL; + return rc; } if ((htype = client_gettype(hname)) == MCL_FQDN) { @@ -339,13 +349,16 @@ exportfs(char *arg, char *options, int verbose) exp->m_warned = 0; validate_export(exp); + rc = 1; out: freeaddrinfo(ai); + return rc; } -static void +static int unexportfs(char *arg, int verbose) { + int rc = 0; nfs_export *exp; struct addrinfo *ai = NULL; char *path; @@ -357,7 +370,8 @@ unexportfs(char *arg, int verbose) if (!path || *path != '/') { xlog(L_ERROR, "Invalid unexporting option: %s", arg); - return; + export_errno = EINVAL; + return rc; } if ((htype = client_gettype(hname)) == MCL_FQDN) { @@ -397,9 +411,11 @@ unexportfs(char *arg, int verbose) #endif exp->m_xtabent = 0; exp->m_mayexport = 0; + rc = 1; } freeaddrinfo(ai); + return rc; } static int can_test(void) @@ -728,6 +744,7 @@ 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 |