Ben Greear <[EMAIL PROTECTED]> wrote:

> Pavlin Radoslavov wrote:
> > Ben Greear <[EMAIL PROTECTED]> wrote:
> > 
> >> We're still trying to figure out if this is reproducible, but
> >> here's the stack trace.  This is with all of my patches applied,
> >> so it's possible something we are doing wrong.
> > 
> > Please send instructions how to reproduce the problem: rtrmgr
> > command line options, configuration file and any actions you did.
> > I need the command line options so I know where the log output is
> > redirected to.
> > 
> > Also, please reverse-back the rev. 1.68 change to the
> > rtrmgr/module_manager.cc file:
> > 1.68      +5 -3;  commitid: 11fdf48f7e12041a7; xorp/rtrmgr/module_manager.cc
> > 
> > In particular, change back the two XLOG_*() messages to fprintf(),
> > and see whether you still get the error.
> > This will guide us choosing the next step in debugging the problem.
> 
> Ok, here is how you reproduce the problem:
> 
> I have a program called 'logchopper' that reads from stdin
> and writes to log files, rotating them when they are large.
> This way I can 'log' stdout and stderr by piping it into
> logchopper.
> 
> When I shutdown my xorp instances, I do a 'killall -r xorp', which
> sometimes kills the logchoppers before the parent xorp.  This causes
> a sigpipe, I guess, and then xorp_rtrmgr dumps core.
> 
> I think you could use 'tee' in place of my logchopper and
> have the same result.  If you want, I can send you the logchopper
> source.
> 
> I'm going to try just commenting out the assert in the sig-pipe
> handler.  In my case, xorp will be killed shortly anyway, and even if
> not, I'd rather xorp run w/out stdout/stderr (or maybe exit cleanly)
> than crash.

Ben,

Could you try the following patch.
It basically gets rid of the SIGPIPE handling and uses
"signal(SIGPIPE, SIG_IGN)" to completely ignore SIGPIPE inside the
EventLoop constructor.
Instead of dealing with SIGPIPE, we handle error conditions by
using the return error code.

Please let me know if this patch works for you so I can commit it to
CVS.

Thanks,
Pavlin

Index: libxipc/finder_main.cc
===================================================================
RCS file: /usr/local/www/data/cvs/xorp/libxipc/finder_main.cc,v
retrieving revision 1.27
diff -u -p -r1.27 finder_main.cc
--- libxipc/finder_main.cc	2 Oct 2008 21:57:20 -0000	1.27
+++ libxipc/finder_main.cc	19 Oct 2008 02:58:04 -0000
@@ -103,9 +103,6 @@ finder_main(int argc, char* const argv[]
 #endif
     signal(SIGINT, finder_sig_handler);
     signal(SIGTERM, finder_sig_handler);
-#ifdef SIGPIPE
-    signal(SIGPIPE, finder_sig_handler);
-#endif
 
     int ch;
     while ((ch = getopt(argc, argv, "a:i:n:p:hv")) != -1) {
Index: libxorp/asyncio.cc
===================================================================
RCS file: /usr/local/www/data/cvs/xorp/libxorp/asyncio.cc,v
retrieving revision 1.45
diff -u -p -r1.45 asyncio.cc
--- libxorp/asyncio.cc	2 Oct 2008 21:57:28 -0000	1.45
+++ libxorp/asyncio.cc	19 Oct 2008 02:58:04 -0000
@@ -83,8 +83,6 @@ is_pseudo_error(const char* name, XorpFd
     return false;
 }
 
-bool AsyncFileWriter::_writing = false;
-
 // ----------------------------------------------------------------------------
 AsyncFileOperator::~AsyncFileOperator()
 {
@@ -377,11 +375,6 @@ AsyncFileWriter::AsyncFileWriter(EventLo
 				 int priority)
     : AsyncFileOperator(e, fd, priority)
 {
-#ifndef HOST_OS_WINDOWS
-    if (::signal(SIGPIPE, &AsyncFileWriter::sigpipe_handler) == SIG_ERR)
-	xorp_throw(InvalidString, "can't install signal handler"); // XXX
-#endif
-
     static const uint32_t max_coalesce = 16;
     _coalesce = (coalesce > MAX_IOVEC) ? MAX_IOVEC : coalesce;
     if (_coalesce > max_coalesce) {
@@ -400,16 +393,6 @@ AsyncFileWriter::~AsyncFileWriter()
 }
 
 void
-AsyncFileWriter::sigpipe_handler(int /* num */)
-{
-    if (_writing)
-	return;
-
-    // XXX call original signal handler
-    XLOG_ASSERT(false);
-}
-
-void
 AsyncFileWriter::add_buffer(const uint8_t*	b,
 			    size_t		b_bytes,
 			    const Callback&	cb)
@@ -533,9 +516,6 @@ AsyncFileWriter::write(XorpFd fd, IoEven
     ssize_t done = 0;
     int flags = 0;
     bool mod_signals = true;
-#ifndef HOST_OS_WINDOWS
-    sig_t saved_sigpipe = SIG_ERR;
-#endif
 
 #ifdef MSG_NOSIGNAL
     flags |= MSG_NOSIGNAL;
@@ -600,12 +580,6 @@ AsyncFileWriter::write(XorpFd fd, IoEven
 	//
 	XLOG_ASSERT(! dst_addr.is_zero());
 
-	if (mod_signals) {
-#ifndef HOST_OS_WINDOWS
-	    saved_sigpipe = signal(SIGPIPE, SIG_IGN);
-#endif
-	}
-
 	switch (dst_addr.af()) {
 	case AF_INET:
 	{
@@ -651,12 +625,6 @@ AsyncFileWriter::write(XorpFd fd, IoEven
 #endif
 	}
 
-	if (mod_signals) {
-#ifndef HOST_OS_WINDOWS
-	    signal(SIGPIPE, saved_sigpipe);
-#endif
-	}
-
     } else {
 	//
 	// Write the data to the socket/file descriptor
@@ -702,11 +670,9 @@ AsyncFileWriter::write(XorpFd fd, IoEven
 	    if (done < 0)
 		_last_error = errno;
 	} else {
-	    _writing = true;
 	    done = ::writev(_fd, _iov, (int)iov_cnt);
 	    if (done < 0)
 		_last_error = errno;
-	    _writing = false;
 	}
 	errno = 0;
 #endif // ! HOST_OS_WINDOWS
@@ -737,7 +703,14 @@ void
 AsyncFileWriter::complete_transfer(ssize_t sdone)
 {
     if (sdone < 0) {
-	XLOG_ERROR("Write error %d\n", _last_error);
+	do {
+	    // XXX: don't print an error if the error code is EPIPE
+#ifdef EPIPE
+	    if (_last_error == EPIPE)
+		break;
+#endif
+	    XLOG_ERROR("Write error %d\n", _last_error);
+	} while (false);
 	stop();
 	BufferInfo* head = _buffers.front();
 	head->dispatch_callback(OS_ERROR);
Index: libxorp/asyncio.hh
===================================================================
RCS file: /usr/local/www/data/cvs/xorp/libxorp/asyncio.hh,v
retrieving revision 1.34
diff -u -p -r1.34 asyncio.hh
--- libxorp/asyncio.hh	2 Oct 2008 21:57:28 -0000	1.34
+++ libxorp/asyncio.hh	19 Oct 2008 02:58:04 -0000
@@ -423,15 +423,12 @@ protected:
 
     void write(XorpFd, IoEventType);
     void complete_transfer(ssize_t done);
-    static void sigpipe_handler(int sig);
 
     uint32_t		_coalesce;
     struct iovec* 	_iov;
     ref_ptr<int>	_dtoken;
     list<BufferInfo *> 	_buffers;
 
-    static bool		_writing;
-
 #ifdef HOST_OS_WINDOWS
     void disconnect(XorpFd fd, IoEventType type);
 
Index: libxorp/eventloop.cc
===================================================================
RCS file: /usr/local/www/data/cvs/xorp/libxorp/eventloop.cc,v
retrieving revision 1.46
diff -u -p -r1.46 eventloop.cc
--- libxorp/eventloop.cc	13 Oct 2008 21:31:41 -0000	1.46
+++ libxorp/eventloop.cc	19 Oct 2008 02:58:04 -0000
@@ -47,6 +47,15 @@ EventLoop::EventLoop()
     XLOG_ASSERT(eventloop_instance_count == 0);
     XLOG_ASSERT(_last_ev_run == 0);
     eventloop_instance_count++;
+
+    //
+    // XXX: Ignore SIGPIPE, because we always check the return code.
+    // If the program needs to install a SIGPIPE signal handler, the
+    // handler must be installed after the EventLoop instance is created.
+    //
+#ifdef SIGPIPE
+    signal(SIGPIPE, SIG_IGN);
+#endif
 }
 
 EventLoop::~EventLoop()
Index: rtrmgr/xorpsh_main.cc
===================================================================
RCS file: /usr/local/www/data/cvs/xorp/rtrmgr/xorpsh_main.cc,v
retrieving revision 1.74
diff -u -p -r1.74 xorpsh_main.cc
--- rtrmgr/xorpsh_main.cc	2 Oct 2008 21:58:27 -0000	1.74
+++ rtrmgr/xorpsh_main.cc	19 Oct 2008 02:58:06 -0000
@@ -237,11 +237,6 @@ XorpShell::run(const string& commands, b
     }
 #endif // ! HOST_OS_WINDOWS
 
-#ifdef SIGPIPE
-    // Trap SIGPIPE while we bring up the connection to the Finder.
-    signal(SIGPIPE, signal_handler);
-#endif
-
     // Set the callback when the CLI exits (e.g., after Ctrl-D)
     _cli_node.set_cli_client_delete_callback(callback(exit_handler));
 
@@ -785,12 +780,6 @@ signal_handler(int signal_value)
     case SIGINT:
 	// Ignore Ctrl-C: it is used by the CLI to interrupt a command.
 	break;
-#ifdef SIGPIPE
-    case SIGPIPE:
-	// Ignore SIGPIPE: it may be generated when executing commands
-	// specified on the command line.
-	break;
-#endif
     default:
 	// XXX: anything else we have intercepted will terminate us.
 	is_interrupted = true;
_______________________________________________
Xorp-hackers mailing list
[email protected]
http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/xorp-hackers

Reply via email to