From patchwork Tue Apr 12 14:00:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 65626 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1939468qge; Tue, 12 Apr 2016 07:03:37 -0700 (PDT) X-Received: by 10.194.134.134 with SMTP id pk6mr3978708wjb.176.1460469817048; Tue, 12 Apr 2016 07:03:37 -0700 (PDT) Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com. [209.132.183.37]) by mx.google.com with ESMTPS id g82si24059059wme.12.2016.04.12.07.03.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Apr 2016 07:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3CE0u0C005228; Tue, 12 Apr 2016 10:00:56 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3CE0qd1006764 for ; Tue, 12 Apr 2016 10:00:52 -0400 Received: from colepc.redhat.com (ovpn-113-40.phx2.redhat.com [10.3.113.40]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3CE0p82007994; Tue, 12 Apr 2016 10:00:51 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 12 Apr 2016 10:00:48 -0400 Message-Id: <60d1ded742e0caa619edf656986d6f3d87043e0a.1460469648.git.crobinso@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] Be consistent with setlocale error handling X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com Take setlocale/gettext error handling pattern from tools/virsh-* and use it in all the other standalone binaries. The changes are * Ignore setlocale errors. virsh has done this forever, presumably for good reason. This has been partially responsible for some bug reports: https://bugzilla.redhat.com/show_bug.cgi?id=1312688 https://bugzilla.redhat.com/show_bug.cgi?id=1026514 https://bugzilla.redhat.com/show_bug.cgi?id=1016158 * Report the failed function name * Report strerror --- daemon/libvirtd.c | 20 ++++++++++++++++---- src/locking/lock_daemon.c | 20 ++++++++++++++++---- src/locking/sanlock_helper.c | 16 ++++++++++++---- src/logging/log_daemon.c | 20 ++++++++++++++++---- src/lxc/lxc_controller.c | 20 ++++++++++++++++---- src/network/leaseshelper.c | 16 ++++++++++++---- src/security/virt-aa-helper.c | 16 ++++++++++++---- src/storage/parthelper.c | 16 ++++++++++++---- src/util/iohelper.c | 16 ++++++++++++---- 9 files changed, 124 insertions(+), 36 deletions(-) -- 2.7.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 3d38a46..9488950 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1172,10 +1172,22 @@ int main(int argc, char **argv) { {0, 0, 0, 0} }; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL || - virInitialize() < 0) { + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); + exit(EXIT_FAILURE); + } + + if (virInitialize() < 0) { fprintf(stderr, _("%s: initialization failed\n"), argv[0]); exit(EXIT_FAILURE); } diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 973e691..fffbe1d 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -1179,10 +1179,22 @@ int main(int argc, char **argv) { privileged = geteuid() == 0; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL || - virThreadInitialize() < 0 || + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); + exit(EXIT_FAILURE); + } + + if (virThreadInitialize() < 0 || virErrorInitialize() < 0) { fprintf(stderr, _("%s: initialization failed\n"), argv[0]); exit(EXIT_FAILURE); diff --git a/src/locking/sanlock_helper.c b/src/locking/sanlock_helper.c index d8d294f..6b17fce 100644 --- a/src/locking/sanlock_helper.c +++ b/src/locking/sanlock_helper.c @@ -70,10 +70,18 @@ main(int argc, char **argv) .cb = authCallback, }; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL) { - fprintf(stderr, _("%s: initialization failed\n"), argv[0]); + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); exit(EXIT_FAILURE); } diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index f674cbd..8a0de22 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -936,10 +936,22 @@ int main(int argc, char **argv) { privileged = geteuid() == 0; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL || - virThreadInitialize() < 0 || + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); + exit(EXIT_FAILURE); + } + + if (virThreadInitialize() < 0 || virErrorInitialize() < 0) { fprintf(stderr, _("%s: initialization failed\n"), argv[0]); exit(EXIT_FAILURE); diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 8b5ec4c..612c0d7 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -2505,10 +2505,22 @@ int main(int argc, char *argv[]) for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) ns_fd[i] = -1; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL || - virThreadInitialize() < 0 || + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); + exit(EXIT_FAILURE); + } + + if (virThreadInitialize() < 0 || virErrorInitialize() < 0) { fprintf(stderr, _("%s: initialization failed\n"), argv[0]); exit(EXIT_FAILURE); diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c index 097cd11..e753e75 100644 --- a/src/network/leaseshelper.c +++ b/src/network/leaseshelper.c @@ -115,10 +115,18 @@ main(int argc, char **argv) program_name = argv[0]; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL) { - fprintf(stderr, _("%s: initialization failed\n"), program_name); + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); exit(EXIT_FAILURE); } diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 50d2a08..f47dc63 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1298,10 +1298,18 @@ main(int argc, char **argv) char *profile = NULL; char *include_file = NULL; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL) { - fprintf(stderr, _("%s: initialization failed\n"), argv[0]); + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); exit(EXIT_FAILURE); } diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c index d1df068..c0f1f5a 100644 --- a/src/storage/parthelper.c +++ b/src/storage/parthelper.c @@ -72,10 +72,18 @@ int main(int argc, char **argv) const char *partsep; bool devmap_nopartsep = false; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL) { - fprintf(stderr, _("%s: initialization failed\n"), argv[0]); + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); exit(EXIT_FAILURE); } diff --git a/src/util/iohelper.c b/src/util/iohelper.c index 8a3c377..0200bb1 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -230,10 +230,18 @@ main(int argc, char **argv) program_name = argv[0]; - if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL) { - fprintf(stderr, _("%s: initialization failed\n"), program_name); + if (!setlocale(LC_ALL, "")) { + perror("setlocale"); + /* failure to setup locale is not fatal */ + } + + if (!bindtextdomain(PACKAGE, LOCALEDIR)) { + perror("bindtextdomain"); + exit(EXIT_FAILURE); + } + + if (!textdomain(PACKAGE)) { + perror("textdomain"); exit(EXIT_FAILURE); }