summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2008-01-16 22:40:01 +1100
committerAndrew Tridgell <tridge@samba.org>2008-01-16 22:40:01 +1100
commitbe9594c156a175335629aacdd1a0bc514046dd41 (patch)
treeb5ae571a1e814ed2378efc4fbdf5b1b180936f4a
parente979ca9e6043ba858a4fcd0175de15ca921399f5 (diff)
downloadsamba-be9594c156a175335629aacdd1a0bc514046dd41.tar.gz
samba-be9594c156a175335629aacdd1a0bc514046dd41.tar.xz
samba-be9594c156a175335629aacdd1a0bc514046dd41.zip
fixed handling of \r from stdout of subprocesses
(This used to be ctdb commit f1acec5db4948d8e48412a8546bb181b08a2c5fd)
-rw-r--r--ctdb/server/ctdb_logging.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c
index 22e04eb2a2..c733409c68 100644
--- a/ctdb/server/ctdb_logging.c
+++ b/ctdb/server/ctdb_logging.c
@@ -106,17 +106,17 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
uint16_t flags, void *private)
{
struct ctdb_context *ctdb = talloc_get_type(private, struct ctdb_context);
- ssize_t n;
+ int n1, n2;
char *p;
if (!(flags & EVENT_FD_READ)) {
return;
}
- n = read(ctdb->log->pfd, &ctdb->log->buf[ctdb->log->buf_used],
+ n1 = read(ctdb->log->pfd, &ctdb->log->buf[ctdb->log->buf_used],
sizeof(ctdb->log->buf) - ctdb->log->buf_used);
- if (n > 0) {
- ctdb->log->buf_used += n;
+ if (n1 > 0) {
+ ctdb->log->buf_used += n1;
}
if (ctdb->log->buf_used == sizeof(ctdb->log->buf)) {
@@ -131,10 +131,15 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
return;
}
- n = (p - ctdb->log->buf)+1;
- do_debug("%*.*s", (int)n, (int)n, ctdb->log->buf);
- memmove(ctdb->log->buf, ctdb->log->buf+n, sizeof(ctdb->log->buf) - n);
- ctdb->log->buf_used -= n;
+ n1 = (p - ctdb->log->buf)+1;
+ n2 = n1 - 1;
+ /* swallow \r from child processes */
+ if (n2 > 0 && ctdb->log->buf[n2-1] == '\r') {
+ n2--;
+ }
+ do_debug("%*.*s\n", n2, n2, ctdb->log->buf);
+ memmove(ctdb->log->buf, p+1, sizeof(ctdb->log->buf) - n1);
+ ctdb->log->buf_used -= n1;
}