[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PATCH 1/4] os-posix/win32: convert fprintf/perror to err
From: |
arei.gonglei |
Subject: |
[Qemu-trivial] [PATCH 1/4] os-posix/win32: convert fprintf/perror to error_report |
Date: |
Thu, 25 Sep 2014 17:46:21 +0800 |
From: Gonglei <address@hidden>
Signed-off-by: Gonglei <address@hidden>
---
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");
exit(1);
}
#else
- fprintf(stderr, "Change of process name not supported by your OS\n");
+ error_report("Change of process name not supported by your OS");
exit(1);
#endif
}
@@ -145,7 +146,7 @@ void os_parse_cmd_args(int index, const char *optarg)
case QEMU_OPTION_runas:
user_pwd = getpwnam(optarg);
if (!user_pwd) {
- fprintf(stderr, "User \"%s\" doesn't exist\n", optarg);
+ error_report("User \"%s\" doesn't exist", optarg);
exit(1);
}
break;
@@ -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);
exit(1);
}
if (initgroups(user_pwd->pw_name, user_pwd->pw_gid) < 0) {
- fprintf(stderr, "Failed to initgroups(\"%s\", %d)\n",
- user_pwd->pw_name, user_pwd->pw_gid);
+ error_report("Failed to initgroups(\"%s\", %d)",
+ user_pwd->pw_name, user_pwd->pw_gid);
exit(1);
}
if (setuid(user_pwd->pw_uid) < 0) {
- fprintf(stderr, "Failed to setuid(%d)\n", user_pwd->pw_uid);
+ error_report("Failed to setuid(%d)", user_pwd->pw_uid);
exit(1);
}
if (setuid(0) != -1) {
- fprintf(stderr, "Dropping privileges failed\n");
+ error_report("Dropping privileges failed");
exit(1);
}
}
@@ -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 /");
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));
exit(1);
} else
exit(0);
@@ -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 /");
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");
}
- } else
- fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+ } else {
+ error_report("Could not acquire pid file: %s", strerror(errno));
+ }
}
void os_set_line_buffering(void)
@@ -338,7 +340,7 @@ int os_mlock(void)
ret = mlockall(MCL_CURRENT | MCL_FUTURE);
if (ret < 0) {
- perror("mlockall");
+ error_report("mlockall");
}
return ret;
diff --git a/os-win32.c b/os-win32.c
index 5f95caa..28877b3 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -33,6 +33,7 @@
#include "config-host.h"
#include "sysemu/sysemu.h"
#include "qemu-options.h"
+#include "qemu/error-report.h"
/***********************************************************/
/* Functions missing in mingw */
@@ -106,7 +107,7 @@ void os_parse_cmd_args(int index, const char *optarg)
void os_pidfile_error(void)
{
- fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+ error_report("Could not acquire pid file: %s", strerror(errno));
}
int qemu_create_pidfile(const char *filename)
--
1.7.12.4