From: Eric Blake <eblake@redhat.com>
To: arei.gonglei@huawei.com, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, weidong.huang@huawei.com,
qemu-trivial@nongnu.org, luonengjun@huawei.com, mjt@tls.msk.ru,
armbru@redhat.com, peter.huangpeng@huawei.com,
pbonzini@redhat.com
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 1/4] os-posix/win32: convert fprintf/perror to error_report
Date: Thu, 25 Sep 2014 06:33:53 -0600 [thread overview]
Message-ID: <54240BB1.8020908@redhat.com> (raw)
In-Reply-To: <1411638384-5844-2-git-send-email-arei.gonglei@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 3685 bytes --]
On 09/25/2014 03:46 AM, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
> os-posix.c | 34 ++++++++++++++++++----------------
> os-win32.c | 3 ++-
> 2 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/os-posix.c b/os-posix.c
> index cb2a7f7..9d5ae70 100644
> --- a/os-posix.c
> +++ b/os-posix.c
> @@ -39,6 +39,7 @@
> #include "sysemu/sysemu.h"
> #include "net/slirp.h"
> #include "qemu-options.h"
> +#include "qemu/error-report.h"
>
> #ifdef CONFIG_LINUX
> #include <sys/prctl.h>
> @@ -120,11 +121,11 @@ void os_set_proc_name(const char *s)
> /* Could rewrite argv[0] too, but that's a bit more complicated.
> This simple way is enough for `top'. */
> if (prctl(PR_SET_NAME, name)) {
> - perror("unable to change process name");
> + error_report("unable to change process name");
This loses the value of errno that perror would have displayed. Is that
reduction in error message quality intentional? If not, then this is
not a trivial conversion; if it is, then your commit message should call
it out.
> @@ -167,20 +168,20 @@ static void change_process_uid(void)
> {
> if (user_pwd) {
> if (setgid(user_pwd->pw_gid) < 0) {
> - fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid);
> + error_report("Failed to setgid(%d)\n", user_pwd->pw_gid);
No trailing \n for error_report, please. (You got it right in most of
your conversions)
> @@ -190,11 +191,11 @@ static void change_root(void)
> {
> if (chroot_dir) {
> if (chroot(chroot_dir) < 0) {
> - fprintf(stderr, "chroot failed\n");
> + error_report("chroot failed");
> exit(1);
> }
> if (chdir("/")) {
> - perror("not able to chdir to /");
> + error_report("not able to chdir to /");
Another loss of errno value from perror.
> exit(1);
> }
> }
> @@ -224,7 +225,7 @@ void os_daemonize(void)
> if (len != 1)
> exit(1);
> else if (status == 1) {
> - fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
> + error_report("Could not acquire pidfile: %s", strerror(errno));
This code is broken. The earlier 'if (len != 1)' fails to print a
message before exiting (not to mention it violates coding style by
omitting {}). Then, if we get inside the 'else if (status == 1)'
conditional, then we KNOW that read() succeeded, and therefore errno is
unspecified. Printing strerror(errno) on a random value is NOT helpful.
> @@ -267,7 +268,7 @@ void os_setup_post(void)
> exit(1);
>
> if (chdir("/")) {
> - perror("not able to chdir to /");
> + error_report("not able to chdir to /");
Another loss of errno reporting.
> exit(1);
> }
> TFR(fd = qemu_open("/dev/null", O_RDWR));
> @@ -292,10 +293,11 @@ void os_pidfile_error(void)
> if (daemonize) {
> uint8_t status = 1;
> if (write(fds[1], &status, 1) != 1) {
> - perror("daemonize. Writing to pipe\n");
> + error_report("daemonize. Writing to pipe");
and another.
> @@ -338,7 +340,7 @@ int os_mlock(void)
>
> ret = mlockall(MCL_CURRENT | MCL_FUTURE);
> if (ret < 0) {
> - perror("mlockall");
> + error_report("mlockall");
and another.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 539 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: Eric Blake <eblake@redhat.com>
To: arei.gonglei@huawei.com, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, weidong.huang@huawei.com,
qemu-trivial@nongnu.org, luonengjun@huawei.com, mjt@tls.msk.ru,
armbru@redhat.com, peter.huangpeng@huawei.com,
pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/4] os-posix/win32: convert fprintf/perror to error_report
Date: Thu, 25 Sep 2014 06:33:53 -0600 [thread overview]
Message-ID: <54240BB1.8020908@redhat.com> (raw)
In-Reply-To: <1411638384-5844-2-git-send-email-arei.gonglei@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 3685 bytes --]
On 09/25/2014 03:46 AM, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
> os-posix.c | 34 ++++++++++++++++++----------------
> os-win32.c | 3 ++-
> 2 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/os-posix.c b/os-posix.c
> index cb2a7f7..9d5ae70 100644
> --- a/os-posix.c
> +++ b/os-posix.c
> @@ -39,6 +39,7 @@
> #include "sysemu/sysemu.h"
> #include "net/slirp.h"
> #include "qemu-options.h"
> +#include "qemu/error-report.h"
>
> #ifdef CONFIG_LINUX
> #include <sys/prctl.h>
> @@ -120,11 +121,11 @@ void os_set_proc_name(const char *s)
> /* Could rewrite argv[0] too, but that's a bit more complicated.
> This simple way is enough for `top'. */
> if (prctl(PR_SET_NAME, name)) {
> - perror("unable to change process name");
> + error_report("unable to change process name");
This loses the value of errno that perror would have displayed. Is that
reduction in error message quality intentional? If not, then this is
not a trivial conversion; if it is, then your commit message should call
it out.
> @@ -167,20 +168,20 @@ static void change_process_uid(void)
> {
> if (user_pwd) {
> if (setgid(user_pwd->pw_gid) < 0) {
> - fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid);
> + error_report("Failed to setgid(%d)\n", user_pwd->pw_gid);
No trailing \n for error_report, please. (You got it right in most of
your conversions)
> @@ -190,11 +191,11 @@ static void change_root(void)
> {
> if (chroot_dir) {
> if (chroot(chroot_dir) < 0) {
> - fprintf(stderr, "chroot failed\n");
> + error_report("chroot failed");
> exit(1);
> }
> if (chdir("/")) {
> - perror("not able to chdir to /");
> + error_report("not able to chdir to /");
Another loss of errno value from perror.
> exit(1);
> }
> }
> @@ -224,7 +225,7 @@ void os_daemonize(void)
> if (len != 1)
> exit(1);
> else if (status == 1) {
> - fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
> + error_report("Could not acquire pidfile: %s", strerror(errno));
This code is broken. The earlier 'if (len != 1)' fails to print a
message before exiting (not to mention it violates coding style by
omitting {}). Then, if we get inside the 'else if (status == 1)'
conditional, then we KNOW that read() succeeded, and therefore errno is
unspecified. Printing strerror(errno) on a random value is NOT helpful.
> @@ -267,7 +268,7 @@ void os_setup_post(void)
> exit(1);
>
> if (chdir("/")) {
> - perror("not able to chdir to /");
> + error_report("not able to chdir to /");
Another loss of errno reporting.
> exit(1);
> }
> TFR(fd = qemu_open("/dev/null", O_RDWR));
> @@ -292,10 +293,11 @@ void os_pidfile_error(void)
> if (daemonize) {
> uint8_t status = 1;
> if (write(fds[1], &status, 1) != 1) {
> - perror("daemonize. Writing to pipe\n");
> + error_report("daemonize. Writing to pipe");
and another.
> @@ -338,7 +340,7 @@ int os_mlock(void)
>
> ret = mlockall(MCL_CURRENT | MCL_FUTURE);
> if (ret < 0) {
> - perror("mlockall");
> + error_report("mlockall");
and another.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 539 bytes --]
next prev parent reply other threads:[~2014-09-25 12:34 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-25 9:46 [Qemu-trivial] [PATCH 0/4] os: convert fprintf/perror to error_report arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-09-25 9:46 ` [Qemu-trivial] [PATCH 1/4] os-posix/win32: " arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-09-25 12:33 ` Eric Blake [this message]
2014-09-25 12:33 ` Eric Blake
2014-09-25 12:53 ` [Qemu-trivial] " Gonglei (Arei)
2014-09-25 12:53 ` Gonglei (Arei)
2014-09-25 9:46 ` [Qemu-trivial] [PATCH 2/4] os-posix: report error message when lock file failed arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-10-01 8:45 ` [Qemu-trivial] " Markus Armbruster
2014-10-01 8:45 ` Markus Armbruster
2014-10-01 9:12 ` [Qemu-trivial] " Gonglei
2014-10-01 9:12 ` Gonglei
2014-10-01 10:24 ` [Qemu-trivial] " Markus Armbruster
2014-10-01 10:24 ` Markus Armbruster
2014-10-01 11:58 ` [Qemu-trivial] " Gonglei
2014-10-01 11:58 ` Gonglei
2014-10-01 12:38 ` [Qemu-trivial] " Markus Armbruster
2014-10-01 12:38 ` Markus Armbruster
2014-10-24 7:32 ` [Qemu-trivial] " Michael Tokarev
2014-10-24 7:32 ` [Qemu-devel] " Michael Tokarev
2014-10-24 8:56 ` Gonglei
2014-10-24 8:56 ` [Qemu-devel] " Gonglei
2014-09-25 9:46 ` [Qemu-trivial] [PATCH 3/4] osdep: convert fprintf to error_report arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-09-25 12:35 ` [Qemu-trivial] " Eric Blake
2014-09-25 12:35 ` Eric Blake
2014-09-25 12:54 ` [Qemu-trivial] " Gonglei (Arei)
2014-09-25 12:54 ` Gonglei (Arei)
2014-09-25 9:46 ` [Qemu-trivial] [PATCH 4/4] oslib-posix/win32: convert fprintf/perror " arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-09-25 12:36 ` [Qemu-trivial] " Eric Blake
2014-09-25 12:36 ` Eric Blake
2014-09-25 12:55 ` [Qemu-trivial] " Gonglei (Arei)
2014-09-25 12:55 ` Gonglei (Arei)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54240BB1.8020908@redhat.com \
--to=eblake@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=armbru@redhat.com \
--cc=luonengjun@huawei.com \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--cc=peter.huangpeng@huawei.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=weidong.huang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.