Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iMaXk-0006LC-PC for mharc-qemu-trivial@gnu.org; Mon, 21 Oct 2019 12:28:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37559) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMaXe-0006Iq-Ub for qemu-trivial@nongnu.org; Mon, 21 Oct 2019 12:28:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMaXd-0001Kj-PN for qemu-trivial@nongnu.org; Mon, 21 Oct 2019 12:28:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51278) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iMaXd-0001KF-H6 for qemu-trivial@nongnu.org; Mon, 21 Oct 2019 12:28:21 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 661698665A for ; Mon, 21 Oct 2019 16:28:20 +0000 (UTC) Received: by mail-wm1-f72.google.com with SMTP id q22so4815458wmc.1 for ; Mon, 21 Oct 2019 09:28:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=mCvOKuU5JGoVf42zSNc4upgCWBKw7Qb85x2J2MWlprY=; b=AvKltVG3DhBpK5UxfhcwbwSOwfyqXNh6rsX5rGbE4eTlTvzBn+u/wKNZFOdDNyZHPt cfGzmCoMRGl8iGX+odle+hYraxEd0K6AiSf/vNDImDvGJK7s88cyzBJEVdNPq8B3aaL3 kwbnmgE+Uibk5fYEKRKediZIZOi2NhdEocAyf7Iyu0go4Lo4r8YWuLO0EeHeQ8P67uUf qzHl7euZ3a8joAaE26tEYuNbL5H8N17mouvTEWEiBn3azPUuag27iE9NU2ZsK8gDz2sv Nw/58pNaaZDMYBnhv2rsOQbTivmLkIAhAh7bNZLyWzOvduSR4wXkcT0ErlZzK6XaLB9E 3bTg== X-Gm-Message-State: APjAAAXDJOzAgfi01efl+BQCmwPB2BAjHawVWO7b9TpVJXZypgp9kNOE IMj6+m6A5gc/A0WgQWAPfODIi2VkDvHTmAeaLqvS3A42zoFYm3ginLMzZSYgDXcD8wmTHJEfN4e D2VgyYDo1LjoS8hV4+w== X-Received: by 2002:a05:6000:1c9:: with SMTP id t9mr3146464wrx.171.1571675298947; Mon, 21 Oct 2019 09:28:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyp8Us36q1Oy2M2NTPvnSrZx/Dg6jXYWgAA4eS3LLxhpzy6GbN5mgR7AWIrIej3CDqz+3QFaw== X-Received: by 2002:a05:6000:1c9:: with SMTP id t9mr3146440wrx.171.1571675298596; Mon, 21 Oct 2019 09:28:18 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:847b:6afc:17c:89dd? ([2001:b07:6468:f312:847b:6afc:17c:89dd]) by smtp.gmail.com with ESMTPSA id 17sm4391455wmg.29.2019.10.21.09.28.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2019 09:28:18 -0700 (PDT) Subject: Re: [PATCH v2] Do not use %m in common code to print error messages To: Thomas Huth , qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, Kamil Rytarowski , berrange@redhat.com, eblake@redhat.com References: <20191018130716.25438-1-thuth@redhat.com> From: Paolo Bonzini Openpgp: preference=signencrypt Message-ID: <001ca3e6-0cfe-eafb-8860-145ff2b7ea09@redhat.com> Date: Mon, 21 Oct 2019 18:28:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191018130716.25438-1-thuth@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-trivial@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Oct 2019 16:28:24 -0000 On 18/10/19 15:07, Thomas Huth wrote: > The %m format specifier is an extension from glibc - and when compiling > QEMU for NetBSD, the compiler correctly complains, e.g.: > > /home/qemu/qemu-test.ELjfrQ/src/util/main-loop.c: In function 'sigfd_handler': > /home/qemu/qemu-test.ELjfrQ/src/util/main-loop.c:64:13: warning: %m is only > allowed in syslog(3) like functions [-Wformat=] > printf("read from sigfd returned %zd: %m\n", len); > ^ > Let's use g_strerror() here instead, which is an easy-to-use wrapper > around the thread-safe strerror_r() function. > > While we're at it, also convert the "printf()" in main-loop.c into > the preferred "error_report()". > > Signed-off-by: Thomas Huth > --- > v2: Do not try to g_free() the strings > > hw/misc/tmp421.c | 4 ++-- > util/main-loop.c | 3 ++- > util/systemd.c | 4 ++-- > 3 files changed, 6 insertions(+), 5 deletions(-) > > diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c > index 9f044705fa..c0bc150bca 100644 > --- a/hw/misc/tmp421.c > +++ b/hw/misc/tmp421.c > @@ -120,7 +120,7 @@ static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name, > int tempid; > > if (sscanf(name, "temperature%d", &tempid) != 1) { > - error_setg(errp, "error reading %s: %m", name); > + error_setg(errp, "error reading %s: %s", name, g_strerror(errno)); > return; > } > > @@ -160,7 +160,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name, > } > > if (sscanf(name, "temperature%d", &tempid) != 1) { > - error_setg(errp, "error reading %s: %m", name); > + error_setg(errp, "error reading %s: %s", name, g_strerror(errno)); > return; > } > > diff --git a/util/main-loop.c b/util/main-loop.c > index e3eaa55866..eda63fe4e0 100644 > --- a/util/main-loop.c > +++ b/util/main-loop.c > @@ -61,7 +61,8 @@ static void sigfd_handler(void *opaque) > } > > if (len != sizeof(info)) { > - printf("read from sigfd returned %zd: %m\n", len); > + error_report("read from sigfd returned %zd: %s", len, > + g_strerror(errno)); > return; > } > > diff --git a/util/systemd.c b/util/systemd.c > index d22e86c707..1dd0367d9a 100644 > --- a/util/systemd.c > +++ b/util/systemd.c > @@ -60,8 +60,8 @@ unsigned int check_socket_activation(void) > * and we should exit. > */ > error_report("Socket activation failed: " > - "invalid file descriptor fd = %d: %m", > - fd); > + "invalid file descriptor fd = %d: %s", > + fd, g_strerror(errno)); > exit(EXIT_FAILURE); > } > } > Queued, thanks. Paolo