Clang comes up with more printf format warnings
Correcting “format string is not a string literal” warning
requires us to declare that parameter is a printf style 
format using the attribute flag

Upstream-Status: Pending

Signed-off-by: Khem Raj <raj.khem@gmail.com>

Index: nfs-utils-2.3.3/support/include/xcommon.h
===================================================================
--- nfs-utils-2.3.3.orig/support/include/xcommon.h
+++ nfs-utils-2.3.3/support/include/xcommon.h
@@ -27,7 +27,7 @@
 
 /* Functions in sundries.c that are used in mount.c and umount.c  */ 
 char *canonicalize (const char *path);
-void nfs_error (const char *fmt, ...);
+void nfs_error (const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2)));
 void *xmalloc (size_t size);
 void *xrealloc(void *p, size_t size);
 void xfree(void *);
@@ -36,9 +36,9 @@ char *xstrndup (const char *s, int n);
 char *xstrconcat2 (const char *, const char *);
 char *xstrconcat3 (const char *, const char *, const char *);
 char *xstrconcat4 (const char *, const char *, const char *, const char *);
-void die (int errcode, const char *fmt, ...);
+void die (int errcode, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
 
-extern void die(int err, const char *fmt, ...);
+extern void die(int err, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
 extern void (*at_die)(void);
 
 /* exit status - bits below are ORed */
Index: nfs-utils-2.3.3/support/include/xlog.h
===================================================================
--- nfs-utils-2.3.3.orig/support/include/xlog.h
+++ nfs-utils-2.3.3/support/include/xlog.h
@@ -43,10 +43,10 @@ void			xlog_config(int fac, int on);
 void			xlog_sconfig(char *, int on);
 void			xlog_from_conffile(char *);
 int			xlog_enabled(int fac);
-void			xlog(int fac, const char *fmt, ...);
-void			xlog_warn(const char *fmt, ...);
-void			xlog_err(const char *fmt, ...);
-void			xlog_errno(int err, const char *fmt, ...);
-void			xlog_backend(int fac, const char *fmt, va_list args);
+void			xlog(int fac, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
+void			xlog_warn(const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2)));
+void			xlog_err(const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2)));
+void			xlog_errno(int err, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
+void			xlog_backend(int fac, const char *fmt, va_list args) __attribute__((__format__ (__printf__, 2, 0)));
 
 #endif /* XLOG_H */
Index: nfs-utils-2.3.3/support/nfs/xcommon.c
===================================================================
--- nfs-utils-2.3.3.orig/support/nfs/xcommon.c
+++ nfs-utils-2.3.3/support/nfs/xcommon.c
@@ -93,7 +93,10 @@ nfs_error (const char *fmt, ...) {
 
      fmt2 = xstrconcat2 (fmt, "\n");
      va_start (args, fmt);
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
      vfprintf (stderr, fmt2, args);
+#pragma clang diagnostic pop
      va_end (args);
      free (fmt2);
 }
Index: nfs-utils-2.3.3/utils/exportfs/exportfs.c
===================================================================
--- nfs-utils-2.3.3.orig/utils/exportfs/exportfs.c
+++ nfs-utils-2.3.3/utils/exportfs/exportfs.c
@@ -644,6 +644,7 @@ out:
 	return result;
 }
 
+__attribute__((__format__ (__printf__, 2, 3)))
 static char
 dumpopt(char c, char *fmt, ...)
 {
Index: nfs-utils-2.3.3/utils/statd/statd.c
===================================================================
--- nfs-utils-2.3.3.orig/utils/statd/statd.c
+++ nfs-utils-2.3.3/utils/statd/statd.c
@@ -136,7 +136,7 @@ static void log_modes(void)
 	strcat(buf, "TI-RPC ");
 #endif
 
-	xlog_warn(buf);
+	xlog_warn("%s", buf);
 }
 
 /*
Index: nfs-utils-2.3.3/support/nfs/svc_create.c
===================================================================
--- nfs-utils-2.3.3.orig/support/nfs/svc_create.c
+++ nfs-utils-2.3.3/support/nfs/svc_create.c
@@ -184,7 +184,7 @@ svc_create_sock(const struct sockaddr *s
 		type = SOCK_STREAM;
 		break;
 	default:
-		xlog(D_GENERAL, "%s: Unrecognized bind address semantics: %u",
+		xlog(D_GENERAL, "%s: Unrecognized bind address semantics: %lu",
 			__func__, nconf->nc_semantics);
 		return -1;
 	}
Index: nfs-utils-2.3.3/support/nsm/rpc.c
===================================================================
--- nfs-utils-2.3.3.orig/support/nsm/rpc.c
+++ nfs-utils-2.3.3/support/nsm/rpc.c
@@ -182,7 +182,7 @@ nsm_xmit_getport(const int sock, const s
 	uint32_t xid;
 	XDR xdr;
 
-	xlog(D_CALL, "Sending PMAP_GETPORT for %u, %u, udp", program, version);
+	xlog(D_CALL, "Sending PMAP_GETPORT for %lu, %lu, udp", program, version);
 
 	nsm_init_xdrmem(msgbuf, NSM_MAXMSGSIZE, &xdr);
 	xid = nsm_init_rpc_header(PMAPPROG, PMAPVERS,
Index: nfs-utils-2.3.3/utils/mountd/cache.c
===================================================================
--- nfs-utils-2.3.3.orig/utils/mountd/cache.c
+++ nfs-utils-2.3.3/utils/mountd/cache.c
@@ -968,8 +968,7 @@ lookup_export(char *dom, char *path, str
 			} else if (found_type == i && found->m_warned == 0) {
 				xlog(L_WARNING, "%s exported to both %s and %s, "
 				     "arbitrarily choosing options from first",
-				     path, found->m_client->m_hostname, exp->m_client->m_hostname,
-				     dom);
+				     path, found->m_client->m_hostname, exp->m_client->m_hostname);
 				found->m_warned = 1;
 			}
 		}
Index: nfs-utils-2.3.3/utils/mountd/mountd.c
===================================================================
--- nfs-utils-2.3.3.orig/utils/mountd/mountd.c
+++ nfs-utils-2.3.3/utils/mountd/mountd.c
@@ -213,7 +213,7 @@ static void
 sig_hup (int sig)
 {
 	/* don't exit on SIGHUP */
-	xlog (L_NOTICE, "Received SIGHUP... Ignoring.\n", sig);
+	xlog (L_NOTICE, "Received SIGHUP(%d)... Ignoring.\n", sig);
 	return;
 }
 
Index: nfs-utils-2.3.3/utils/statd/rmtcall.c
===================================================================
--- nfs-utils-2.3.3.orig/utils/statd/rmtcall.c
+++ nfs-utils-2.3.3/utils/statd/rmtcall.c
@@ -247,7 +247,7 @@ process_reply(FD_SET_TYPE *rfds)
 		xlog_warn("%s: service %d not registered on localhost",
 			__func__, NL_MY_PROG(lp));
 	} else {
-		xlog(D_GENERAL, "%s: Callback to %s (for %d) succeeded",
+		xlog(D_GENERAL, "%s: Callback to %s (for %s) succeeded",
 			__func__, NL_MY_NAME(lp), NL_MON_NAME(lp));
 	}
 	nlist_free(&notify, lp);
Index: nfs-utils-2.3.3/utils/statd/svc_run.c
===================================================================
--- nfs-utils-2.3.3.orig/utils/statd/svc_run.c
+++ nfs-utils-2.3.3/utils/statd/svc_run.c
@@ -53,6 +53,7 @@
 
 #include <errno.h>
 #include <time.h>
+#include <inttypes.h>
 #include "statd.h"
 #include "notlist.h"
 
@@ -104,8 +105,8 @@ my_svc_run(int sockfd)
 
 			tv.tv_sec  = NL_WHEN(notify) - now;
 			tv.tv_usec = 0;
-			xlog(D_GENERAL, "Waiting for reply... (timeo %d)",
-							tv.tv_sec);
+			xlog(D_GENERAL, "Waiting for reply... (timeo %jd)",
+							(intmax_t)tv.tv_sec);
 			selret = select(FD_SETSIZE, &readfds,
 				(void *) 0, (void *) 0, &tv);
 		} else {
