Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: jason.wessel@windriver.com (Jason Wessel)
Subject: [ltt-dev] [UST PATCH 1/3] ust-consumerd: fix exit race crashes
Date: Wed, 27 Apr 2011 15:22:14 -0500	[thread overview]
Message-ID: <1303935736-29208-1-git-send-email-jason.wessel@windriver.com> (raw)

The ust-consumerd gets shutdown by the SIGTERM signal and a number of
places in the ust-consumerd did not properly deal with the case where
a system call returns EINTR in errno as a result of a signal to the
process.  The failure to handle EINTR properly was leading to some
data corruption in the buffer code and causing some random "victim"
crashes in lowlevel.c

The way all the offending functions were tracked down was to
temporarily add an abort() in the SIGTERM signal handler.  Then it was
a matter of looking at what threads were blocked on system calls at
the time outside of the thread that received the signal.

Signed-off-by: Jason Wessel <jason.wessel at windriver.com>
---
 libustconsumer/libustconsumer.c |   25 +++++++++++++++++++------
 ust-consumerd/ust-consumerd.c   |   11 ++++++++++-
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/libustconsumer/libustconsumer.c b/libustconsumer/libustconsumer.c
index c5acffa..6f6d4bb 100644
--- a/libustconsumer/libustconsumer.c
+++ b/libustconsumer/libustconsumer.c
@@ -477,6 +477,8 @@ int consumer_loop(struct ustconsumer_instance *instance, struct buffer_info *buf
 			DBG("App died while being traced");
 			finish_consuming_dead_subbuffer(instance->callbacks, buf);
 			break;
+		} else if (read_result == -1 && errno == EINTR) {
+			continue;
 		}
 
 		if(instance->callbacks->on_read_subbuffer)
@@ -783,8 +785,11 @@ int ustconsumer_stop_instance(struct ustconsumer_instance *instance, int send_ms
 
 	struct sockaddr_un addr;
 
+socket_again:
 	result = fd = socket(PF_UNIX, SOCK_STREAM, 0);
 	if(result == -1) {
+		if (errno == EINTR)
+			goto socket_again;
 		PERROR("socket");
 		return 1;
 	}
@@ -794,13 +799,21 @@ int ustconsumer_stop_instance(struct ustconsumer_instance *instance, int send_ms
 	strncpy(addr.sun_path, instance->sock_path, UNIX_PATH_MAX);
 	addr.sun_path[UNIX_PATH_MAX-1] = '\0';
 
-	result = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
-	if(result == -1) {
-		PERROR("connect");
-	}
+connect_again:
+		result = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
+		if(result == -1) {
+			if (errno == EINTR)
+				goto connect_again;
+			PERROR("connect");
+		}
 
-	while(bytes != sizeof(msg))
-		bytes += send(fd, msg, sizeof(msg), 0);
+	while(bytes != sizeof(msg)) {
+		int inc = send(fd, msg, sizeof(msg), 0);
+		if (inc < 0 && errno != EINTR)
+			break;
+		else
+			bytes += inc;
+	}
 
 	close(fd);
 
diff --git a/ust-consumerd/ust-consumerd.c b/ust-consumerd/ust-consumerd.c
index ce2ee40..c961394 100644
--- a/ust-consumerd/ust-consumerd.c
+++ b/ust-consumerd/ust-consumerd.c
@@ -210,7 +210,11 @@ int on_open_buffer(struct ustconsumer_callbacks *data, struct buffer_info *buf)
 		    trace_path, buf->pid, buf->pidunique, buf->name);
 		return 1;
 	}
+again:
 	result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 00600);
+	if (result == -1 && errno == EINTR)
+		goto again;
+
 	if(result == -1) {
 		PERROR("open");
 		ERR("failed opening trace file %s", tmp);
@@ -225,7 +229,12 @@ int on_open_buffer(struct ustconsumer_callbacks *data, struct buffer_info *buf)
 int on_close_buffer(struct ustconsumer_callbacks *data, struct buffer_info *buf)
 {
 	struct buffer_info_local *buf_local = buf->user_data;
-	int result = close(buf_local->file_fd);
+	int result;
+
+again:
+	result = close(buf_local->file_fd);
+	if (result == -1 && errno == EINTR)
+		goto again;
 	free(buf_local);
 	if(result == -1) {
 		PERROR("close");
-- 
1.7.1




             reply	other threads:[~2011-04-27 20:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-27 20:22 Jason Wessel [this message]
2011-04-27 20:22 ` [ltt-dev] [UST PATCH 2/3] ust-consumerd: fix exit race log corruption Jason Wessel
2011-04-28 13:20   ` Nils Carlson
2011-04-28 14:57     ` Mathieu Desnoyers
2011-04-27 20:22 ` [ltt-dev] [UST PATCH 3/3] support busybox for manual trace tests Jason Wessel
2011-04-28 13:20   ` Nils Carlson
2011-04-28 13:20 ` [ltt-dev] [UST PATCH 1/3] ust-consumerd: fix exit race crashes Nils Carlson

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=1303935736-29208-1-git-send-email-jason.wessel@windriver.com \
    --to=jason.wessel@windriver.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox