From e10ddcb9d913f7938fc37c72568eea4e8287ade4 Mon Sep 17 00:00:00 2001
From: Neil Brown <neilb@suse.de>
Date: Mon, 21 Oct 2013 17:40:55 +1100
Subject: [PATCH] exportfs: exit with error code if there was any error.
Reference: bnc#846064

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>
---
 support/include/exportfs.h |    3 ---
 support/include/xlog.h     |    1 +
 support/nfs/exports.c      |    6 ------
 support/nfs/xlog.c         |    4 ++++
 utils/exportfs/exportfs.c  |    2 --
 5 files changed, 5 insertions(+), 11 deletions(-)

--- nfs-utils-1.2.8.orig/support/include/exportfs.h
+++ nfs-utils-1.2.8/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 */
--- nfs-utils-1.2.8.orig/support/include/xlog.h
+++ nfs-utils-1.2.8/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);
--- nfs-utils-1.2.8.orig/support/nfs/exports.c
+++ nfs-utils-1.2.8/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;
@@ -132,7 +130,6 @@ getexportent(int fromkernel, int fromexp
 	}
 	if (ok < 0) {
 		xlog(L_ERROR, "expected client(options...)");
-		export_errno = EINVAL;
 		return NULL;
 	}
 	first = 0;
@@ -152,7 +149,6 @@ getexportent(int fromkernel, int fromexp
 		ok = getexport(exp, sizeof(exp));
 		if (ok < 0) {
 			xlog(L_ERROR, "expected client(options...)");
-			export_errno = EINVAL;
 			return NULL;
 		}
 	}
@@ -172,7 +168,6 @@ getexportent(int fromkernel, int fromexp
 		*opt++ = '\0';
 		if (!(sp = strchr(opt, ')')) || sp[1] != '\0') {
 			syntaxerr("bad option list");
-			export_errno = EINVAL;
 			return NULL;
 		}
 		*sp = '\0';
@@ -567,7 +562,6 @@ parseopts(char *cp, struct exportent *ep
 				     flname, flline, opt);	
 bad_option:
 				free(opt);
-				export_errno = EINVAL;
 				return -1;
 			}
 		} else if (strncmp(opt, "anongid=", 8) == 0) {
--- nfs-utils-1.2.8.orig/support/nfs/xlog.c
+++ nfs-utils-1.2.8/support/nfs/xlog.c
@@ -38,6 +38,8 @@ static int  logmask = 0;		/* What will b
 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, },
@@ -189,6 +191,8 @@ void
 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);
--- nfs-utils-1.2.8.orig/utils/exportfs/exportfs.c
+++ nfs-utils-1.2.8/utils/exportfs/exportfs.c
@@ -103,8 +103,6 @@ main(int argc, char **argv)
 	xlog_stderr(1);
 	xlog_syslog(0);
 
-	export_errno = 0;
-
 	while ((c = getopt(argc, argv, "afhio:ruv")) != EOF) {
 		switch(c) {
 		case 'a':