[Sheepdog] [PATCH] sheep: use eprintf instead of fprintf(stderr)
Liu Yuan
namei.unix at gmail.com
Thu Dec 29 12:21:22 CET 2011
From: Liu Yuan <tailai.ly at taobao.com>
These fprintfs will be called in the context sheep, so we have to use
eprintf for err messages.
- coroutine: use panic() instead of fprintf() & abort()
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
lib/coroutine.c | 20 +++++++-------------
lib/net.c | 14 +++++++-------
2 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/lib/coroutine.c b/lib/coroutine.c
index 5b2ed79..3d79b40 100644
--- a/lib/coroutine.c
+++ b/lib/coroutine.c
@@ -39,6 +39,7 @@
#include "util.h"
#include "coroutine.h"
+#include "logger.h"
enum co_action {
COROUTINE_YIELD = 1,
@@ -151,11 +152,8 @@ static int get_stack_size(struct co_ucontext *co)
if (stack[i] != MAGIC_NUMBER)
break;
- if (i == 0) {
- fprintf(stderr, "stack overflow\n");
- fflush(stderr);
- abort();
- }
+ if (i == 0)
+ panic("stack overflow\n");
return STACK_MAX_SIZE - i * sizeof(stack[0]);
}
@@ -305,10 +303,8 @@ void coroutine_enter(struct coroutine *co, void *opaque)
{
struct coroutine *self = coroutine_self();
- if (co->caller) {
- fprintf(stderr, "Co-routine re-entered recursively\n");
- abort();
- }
+ if (co->caller)
+ panic("Co-routine re-entered recursively\n");
co->caller = self;
co->entry_arg = opaque;
@@ -320,10 +316,8 @@ void coroutine_yield(void)
struct coroutine *self = coroutine_self();
struct coroutine *to = self->caller;
- if (!to) {
- fprintf(stderr, "Co-routine is yielding to no one\n");
- abort();
- }
+ if (!to)
+ panic("Co-routine is yielding to no one\n");
self->caller = NULL;
coroutine_swap(self, to);
diff --git a/lib/net.c b/lib/net.c
index 3caba0f..260ae38 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -148,7 +148,7 @@ int create_listen_ports(int port, int (*callback)(int fd, void *), void *data)
ret = bind(fd, res->ai_addr, res->ai_addrlen);
if (ret) {
- fprintf(stderr, "failed to bind server socket: %m\n");
+ eprintf("failed to bind server socket: %m\n");
close(fd);
continue;
}
@@ -198,7 +198,7 @@ int connect_to(const char *name, int port)
ret = getaddrinfo(name, buf, &hints, &res0);
if (ret) {
- fprintf(stderr, "failed to get address info: %m\n");
+ eprintf("failed to get address info: %m\n");
return -1;
}
@@ -223,7 +223,7 @@ int connect_to(const char *name, int port)
ret = connect(fd, res->ai_addr, res->ai_addrlen);
if (ret)
- fprintf(stderr, "failed to connect to %s:%d: %m\n",
+ eprintf("failed to connect to %s:%d: %m\n",
name, port);
else
goto success;
@@ -244,7 +244,7 @@ reread:
if (ret < 0 || !ret) {
if (errno == EINTR)
goto reread;
- fprintf(stderr, "failed to read from socket: %m\n");
+ eprintf("failed to read from socket: %m\n");
return 1;
}
@@ -277,7 +277,7 @@ rewrite:
if (ret < 0) {
if (errno == EINTR)
goto rewrite;
- fprintf(stderr, "failed to write to socket: %m\n");
+ eprintf("failed to write to socket: %m\n");
return 1;
}
@@ -331,7 +331,7 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
ret = do_read(sockfd, rsp, sizeof(*rsp));
if (ret) {
- fprintf(stderr, "failed to read a response: %m\n");
+ eprintf("failed to read a response: %m\n");
return 1;
}
@@ -341,7 +341,7 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
if (*rlen) {
ret = do_read(sockfd, data, *rlen);
if (ret) {
- fprintf(stderr, "failed to read the response data: %m\n");
+ eprintf("failed to read the response data: %m\n");
return 1;
}
}
--
1.7.8.rc3
More information about the sheepdog
mailing list