diff mbox

[05/11] l10n: Replace nl_langinfo(CODESET) check in command line tools

Message ID 20130702193113.48202.32930.stgit@manray.1015granger.net
State Accepted
Headers show

Commit Message

Chuck Lever July 2, 2013, 7:31 p.m. UTC
SteveD reports:
> The nfsref *always* fails with "Failed to set locale and langinfo"
>
> Steps to Reproduce:
> 1. type nfsref
>
> Additional info:
> The failure is be caused by the following checks:
>
>     /* Ensure UTF-8 strings can be handled transparently */
>     if (setlocale(LC_CTYPE, "") == NULL ||
>         strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
>         fprintf(stderr, "Failed to set locale and langinfo\n");
>         goto out;
>     }
>
> In f19
>   setlocale(LC_CTYPE, "") == 'en_US
> and
>   nl_langinfo(CODESET) == ISO-8859-1

The failing check was introduced in commit 0520ee72 "Initial
commit", Tue Mar 29 15:37:40 2011.  The point of that check is to
force the use of the UTF-8 codeset, since that codeset is required
by the FedFS protocol specification, but it appears to be based on
an incorrect assumption.

This assumption has worked silently until now.  Apparently Fedora
19 has changed the default shell LANG setting from "en_US.utf8" to
"en_US.iso88591" .

For now we are better off just taking the user's locale and then
determining over time where our libraries need to convert user data
to and from UTF-8 prior to network communication.

Replace the above logic everywhere in fedfs-utils with this:

	(void)setlocale(LC_ALL, "");

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=969392
Reported-by: Steve Dickson <steved@redhat.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 src/fedfsd/main.c                  |    7 +------
 src/libjunction/display-junction.c |    7 +------
 src/mount/fedfs-map-nfs4.c         |    7 +------
 src/mount/main.c                   |    7 +------
 src/nfsref/nfsref.c                |    8 +-------
 src/nsdbc/nsdb-annotate.c          |    8 +-------
 src/nsdbc/nsdb-create-fsl.c        |    8 +-------
 src/nsdbc/nsdb-create-fsn.c        |    8 +-------
 src/nsdbc/nsdb-delete-fsl.c        |    8 +-------
 src/nsdbc/nsdb-delete-fsn.c        |    8 +-------
 src/nsdbc/nsdb-delete-nsdb.c       |    8 +-------
 src/nsdbc/nsdb-describe.c          |    8 +-------
 src/nsdbc/nsdb-list.c              |    8 +-------
 src/nsdbc/nsdb-nces.c              |    8 +-------
 src/nsdbc/nsdb-remove-nci.c        |    8 +-------
 src/nsdbc/nsdb-resolve-fsn.c       |    8 +-------
 src/nsdbc/nsdb-simple-nce.c        |    8 +-------
 src/nsdbc/nsdb-update-fsl.c        |    8 +-------
 src/nsdbc/nsdb-update-nci.c        |    8 +-------
 src/nsdbparams/main.c              |    6 +-----
 20 files changed, 20 insertions(+), 134 deletions(-)
diff mbox

Patch

diff --git a/src/fedfsd/main.c b/src/fedfsd/main.c
index 7e481f6..6038a75 100644
--- a/src/fedfsd/main.c
+++ b/src/fedfsd/main.c
@@ -106,12 +106,7 @@  int main(int argc, char **argv)
 	gid_t gid;
 	int arg;
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit(EXIT_FAILURE);
-	}
+	(void)setlocale(LC_ALL, "");
 
 	xlog_stderr(0);
 	xlog_syslog(1);
diff --git a/src/libjunction/display-junction.c b/src/libjunction/display-junction.c
index 0feb5eb..ac5797b 100644
--- a/src/libjunction/display-junction.c
+++ b/src/libjunction/display-junction.c
@@ -55,12 +55,7 @@  main(int argc, char **argv)
 	FedFsStatus retval;
 	int fd;
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit(EXIT_FAILURE);
-	}
+	(void)setlocale(LC_ALL, "");
 
 	/* For the libraries */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
diff --git a/src/mount/fedfs-map-nfs4.c b/src/mount/fedfs-map-nfs4.c
index 896fd75..9600359 100644
--- a/src/mount/fedfs-map-nfs4.c
+++ b/src/mount/fedfs-map-nfs4.c
@@ -187,12 +187,7 @@  out:
  */
 int main(int argc, char *argv[])
 {
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, _("Failed to set locale and langinfo\n"));
-		return 1;
-	}
+	(void)setlocale(LC_ALL, "");
 
 	progname = basename(argv[0]);
 
diff --git a/src/mount/main.c b/src/mount/main.c
index 7af9776..70b6f0e 100644
--- a/src/mount/main.c
+++ b/src/mount/main.c
@@ -405,12 +405,7 @@  int main(int argc, char *argv[])
 	char *source, *target, *text_options;
 	int c, mnt_err;
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, _("Failed to set locale and langinfo\n"));
-		return 1;
-	}
+	(void)setlocale(LC_ALL, "");
 
 	progname = basename(argv[0]);
 
diff --git a/src/nfsref/nfsref.c b/src/nfsref/nfsref.c
index 78cda51..e27879a 100644
--- a/src/nfsref/nfsref.c
+++ b/src/nfsref/nfsref.c
@@ -99,17 +99,11 @@  main(int argc, char **argv)
 	int arg, exit_status;
 	_Bool help;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IWGRP | S_IWOTH);
 
 	exit_status = EXIT_FAILURE;
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		goto out;
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-annotate.c b/src/nsdbc/nsdb-annotate.c
index c14b8f5..d35c7a4 100644
--- a/src/nsdbc/nsdb-annotate.c
+++ b/src/nsdbc/nsdb-annotate.c
@@ -115,15 +115,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-create-fsl.c b/src/nsdbc/nsdb-create-fsl.c
index 8af3177..06134e9 100644
--- a/src/nsdbc/nsdb-create-fsl.c
+++ b/src/nsdbc/nsdb-create-fsl.c
@@ -114,15 +114,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-create-fsn.c b/src/nsdbc/nsdb-create-fsn.c
index 5f8fd21..d6c39ea 100644
--- a/src/nsdbc/nsdb-create-fsn.c
+++ b/src/nsdbc/nsdb-create-fsn.c
@@ -117,15 +117,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-delete-fsl.c b/src/nsdbc/nsdb-delete-fsl.c
index 9355606..f64a8fd 100644
--- a/src/nsdbc/nsdb-delete-fsl.c
+++ b/src/nsdbc/nsdb-delete-fsl.c
@@ -113,15 +113,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-delete-fsn.c b/src/nsdbc/nsdb-delete-fsn.c
index 20518bf..3060c24 100644
--- a/src/nsdbc/nsdb-delete-fsn.c
+++ b/src/nsdbc/nsdb-delete-fsn.c
@@ -111,15 +111,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-delete-nsdb.c b/src/nsdbc/nsdb-delete-nsdb.c
index 2e25a31..2e793bf 100644
--- a/src/nsdbc/nsdb-delete-nsdb.c
+++ b/src/nsdbc/nsdb-delete-nsdb.c
@@ -102,15 +102,9 @@  main(int argc, char **argv)
 	char *nce;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-describe.c b/src/nsdbc/nsdb-describe.c
index deaec2d..ec060be 100644
--- a/src/nsdbc/nsdb-describe.c
+++ b/src/nsdbc/nsdb-describe.c
@@ -110,15 +110,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-list.c b/src/nsdbc/nsdb-list.c
index 02c9c09..e6de357 100644
--- a/src/nsdbc/nsdb-list.c
+++ b/src/nsdbc/nsdb-list.c
@@ -293,15 +293,9 @@  main(int argc, char **argv)
 	char *nce;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-nces.c b/src/nsdbc/nsdb-nces.c
index d31cacc..c67fd18 100644
--- a/src/nsdbc/nsdb-nces.c
+++ b/src/nsdbc/nsdb-nces.c
@@ -102,15 +102,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg, i;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-remove-nci.c b/src/nsdbc/nsdb-remove-nci.c
index 0224314..f6b58c9 100644
--- a/src/nsdbc/nsdb-remove-nci.c
+++ b/src/nsdbc/nsdb-remove-nci.c
@@ -104,15 +104,9 @@  main(int argc, char **argv)
 	char *nce;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-resolve-fsn.c b/src/nsdbc/nsdb-resolve-fsn.c
index 38ec28d..1230e6d 100644
--- a/src/nsdbc/nsdb-resolve-fsn.c
+++ b/src/nsdbc/nsdb-resolve-fsn.c
@@ -256,15 +256,9 @@  main(int argc, char **argv)
 	int fsn_ttl, arg;
 	nsdb_t host;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-simple-nce.c b/src/nsdbc/nsdb-simple-nce.c
index e70c604..75c0386 100644
--- a/src/nsdbc/nsdb-simple-nce.c
+++ b/src/nsdbc/nsdb-simple-nce.c
@@ -102,15 +102,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-update-fsl.c b/src/nsdbc/nsdb-update-fsl.c
index 406373d..f5a4cb9 100644
--- a/src/nsdbc/nsdb-update-fsl.c
+++ b/src/nsdbc/nsdb-update-fsl.c
@@ -115,15 +115,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbc/nsdb-update-nci.c b/src/nsdbc/nsdb-update-nci.c
index 1d3c833..2da0aa1 100644
--- a/src/nsdbc/nsdb-update-nci.c
+++ b/src/nsdbc/nsdb-update-nci.c
@@ -108,15 +108,9 @@  main(int argc, char **argv)
 	nsdb_t host;
 	int arg;
 
+	(void)setlocale(LC_ALL, "");
 	(void)umask(S_IRWXO);
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL ||
-	    strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
-		fprintf(stderr, "Failed to set locale and langinfo\n");
-		exit((int)FEDFS_ERR_INVAL);
-	}
-
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)
 		progname++;
diff --git a/src/nsdbparams/main.c b/src/nsdbparams/main.c
index 103761f..951e31e 100644
--- a/src/nsdbparams/main.c
+++ b/src/nsdbparams/main.c
@@ -184,11 +184,7 @@  main(int argc, char **argv)
 
 	exit_status = EXIT_FAILURE;
 
-	/* Ensure UTF-8 strings can be handled transparently */
-	if (setlocale(LC_CTYPE, "") == NULL)
-		goto out;
-	if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0)
-		goto out;
+	(void)setlocale(LC_ALL, "");
 
 	/* Set the basename */
 	if ((progname = strrchr(argv[0], '/')) != NULL)